-
Notifications
You must be signed in to change notification settings - Fork 177
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add scroll_top() #174
Add scroll_top() #174
Conversation
src/webapi/element.rs
Outdated
} | ||
|
||
/// scrollTop | ||
fn set_scroll_top( &self, value: u32 ) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm... is there any particular reason why the getter returns i32
and the setter accepts u32
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@koute ah, good catch... I guess I should pick one 🤦♂️
what do you think makes the most sense here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In general we should stick with the types from the specs, so it'd be the best if you'd find the relevant IDL in the specs and use the type specified there. (:
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unrestricted double should be f64
no?
If you scroll down to TypedArray objects
table, you can see what the Web IDL types represent.
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypedArray
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just want to do some double checking... Here's some example code of mine:
let top: f64 = Some(window().page_y_offset() as f64)
.unwrap_or(document().document_element().unwrap().scroll_top());
I can see now why I left it as i32
to start...
page_y_offset is listed as:
does this make sense? or does page_y_offset
need a different type as well?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@rickycodes The double
type should also be f64
, therefore page_y_offset
should return f64
.
The only difference between double
and unrestricted double
is that in the WebIDL they guarantee that double
will not be NaN
, -Infinity
, or Infinity
(but the type is the same).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok, cool. I just updated that as well. If things look good I can update with documentation/links and this should be good to go :)
Oh, I guess it would also make sense to add page_x_offset
and scroll_left
as well ;)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yep. Still needs the docs and the links to the specs. (:
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok, this should be all good now!
src/webapi/document.rs
Outdated
@@ -116,4 +116,17 @@ impl Document { | |||
js!( @(no_return) @{self}.title = @{title}; ); | |||
} | |||
} | |||
|
|||
/// Returns the Element that is the root element of the document (for example, the <html> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The <html>
has to be escaped in backticks or it will mess up the docs.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this should be good now, I've also gone back and added backticks that were missed in some of my previous other work.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
also updated doc links and the change to document_element()
(:
lmk if you spot anything else!
src/webapi/document.rs
Outdated
/// element for HTML documents). | ||
/// | ||
/// [(JavaScript docs)](https://developer.mozilla.org/en-US/docs/Web/API/Document/documentElement) | ||
// https://www.w3.org/TR/DOM-Level-2-Core/core.html#ID-87CD092 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please link to this spec instead: https://dom.spec.whatwg.org/#ref-for-dom-document-documentelement
Ditto for other links.
src/webapi/document.rs
Outdated
/// | ||
/// [(JavaScript docs)](https://developer.mozilla.org/en-US/docs/Web/API/Document/documentElement) | ||
// https://www.w3.org/TR/DOM-Level-2-Core/core.html#ID-87CD092 | ||
pub fn document_element( &self ) -> Option< HtmlElement > { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
According to specs shouldn't this return Option< Element >
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, although the links to the specs still need to be fixed. (:
src/webapi/element.rs
Outdated
/// Gets the the number of pixels that an element's content is scrolled vertically. | ||
/// | ||
/// [(Javascript docs)](https://developer.mozilla.org/en-US/docs/Web/API/Element/scrollTop) | ||
// https://drafts.csswg.org/cssom-view/#dom-element-scrolltop |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For consistency please link to the IDL in the specs; for this particular method in should be:
https://drafts.csswg.org/cssom-view/#ref-for-dom-element-scrolltop%E2%91%A0
(:
src/webapi/window.rs
Outdated
/// aligned with the top edge of the window's content area. | ||
/// | ||
/// [(JavaScript docs)](https://developer.mozilla.org/en-US/docs/Web/API/Window/pageYOffset) | ||
// https://drafts.csswg.org/cssom-view/#dom-window-pageyoffset |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These should also link to the IDL, e.g. in this case https://drafts.csswg.org/cssom-view/#ref-for-dom-window-pageyoffset
3e496df
to
02b9fac
Compare
@koute ack! 🤦♂️ ok, I hope this covers em' thanks for catching these! |
@@ -190,4 +190,27 @@ impl Window { | |||
return @{self}.outerHeight; | |||
).try_into().unwrap() | |||
} | |||
|
|||
/// he read-only Window property pageYOffset is an alias for scrollY; as such, it returns |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
he
-> The
(:
Besides the typo LGTM. (: |
Just floating this for some early feedback, still need to add docs, but thought I'd open a PR...
example usage (which I am doing for my own website: ricky.codes):
and then setting: