- Screen name: caruga
caruga's Profile
15 Posts
37 Responses
0
Followers
Show:
- Expanded view
- List view
Private Message
- EDIT: Pretty sure it is, or behaviour changes from 1.7.0 onward. Reporting.
I've been trying to isolate a second possible bug (or intentional behaviour change) where there is an inconsistency between 1.7.2 and 1.8.0, but I can't seem to reproduce it in a minimalised code.
But during the process of trying to recreate it I noticed that the following html:- <html>
- <head>
- <script type="text/javascript" src="http://code.jquery.com/jquery-1.7.2.min.js"></script>
- </head>
- <body>
- <script type="text/javascript">
- $('<div class="ch"><div class="chh">chapter 1</div></div>').appendTo("body");
- var a;
- $('<div class="ch"><div class="chh">chapter 2</div></div>').appendTo("body");
- a = $("body > .ch:last");
- console.log(
- a.prevAll().length);
- console.log(
- a.prevAll(".ch").length);
- console.log(
- a.prevAll(".ch:first").length);
- console.log(
- a.prevAll(".ch:first div:first").length);
- console.log(
- a.prevAll(".ch:first .chh").length);
- </script>
- </body>
- </html>
produces the following output (in any jquery version):2
1
1
1
0
Shouldn't those last two outputs be the same?- 02-Aug-2012 09:39 AM
- Forum: Using jQuery
The following line fails in iexplorer, but not other browsers:- $(xmldoc).find("idea:not(idea idea)").each( function(index) {
call stack is:dirNodeCheck
Sizzle
PSEUDO
filter
Sizzle
find
> processXML
The error is:SCRIPT438: Object doesn't support this property or method
jquery-1.7.2.js, line 5276 character 6- 02-Aug-2012 04:01 AM
- Forum: Using jQuery
- $(anchor).text(txt);
$(links).append($("<span>"+ pretxt + "</span>")).append(anchor);
works. this is the workaround code I ended up using.
The following only shows pretxt, seemingly losing the original anchor node:- t = anchor;
- anchor = $("<span>"+ pretxt + "</span>").insertBefore(t);
- $(links).append(anchor);
What have I not understood?
Also kinda irks me that the official jquery docs never tell me anything about the return values of functions, it just lists a cryptic 'jquery' as the return value for pretty much everything.
Another thing: is there a way to prepend text to an element without creating an element? The "span" is only there so that jquery lets me do it with a constructor.- I don't know if this is the right way to do it but it's the way I have been doing it: create an element and use the css method. I don't know if there's a way to obtain the values from the stylesheet directly?
Anyway, I'm trying to obtain the font-size variable in here:- #contents {
- font-size:130%;
- }
with the following:- cBaseSz = ($("body").append(t = $("<span id=\"Contents\">"))).css("fontSize");
- t.remove();
However this returns the value in pixels ("px" at the end), and I want the literal value specified in the stylesheet. What to do...?- 30-Jul-2012 11:03 AM
- Forum: Using jQuery
- $(this).find("link")
seems to return just one node, and not a 1 element array, so 'each' method won't work on it?
Additionally using 'children' instead of 'find' returns nothing at all, even though the link tag is an immediate descendent???
I have the following xml:- <idea>
- <desc>blah</desc>
- <link>http://blah</link>
- </idea>
where 'this' was obtained with- $(xmldoc).find("idea:first")
and
- $(this).find("link").text()
will return "http://blah", whereas I thought it needed to be $(this).children("link")[0] ? Basically I want to in future iterate across all possible 'link' tags, and this ain't going to work with what i'm currently getting. How do I achieve what i want?
- In my browser console it shows success, but in the 'textStatus' callback variable it shows 'error'.
- idea.load(link, 0, function(text, status, req) {
- _("responseText: " + text + "\n" +
- "textStatus: " + status + "\n" +
- "XMLHttpRequest: " + req);
- });
Where 'link' can be pretty much any link I can think of.
- According to this page, I am able to create a dom object with jquery function thusly ('_' method prints to console):
- var idea = $("<div>");
- _("idea: " + idea.text());
- _("idea: " + idea.html());
Yet the last two methods return blank strings. What am I assuming wrong?- 26-Jul-2012 11:04 PM
- Forum: Using jQuery
$("html, body, #Contents div:first").each( function() {
alert(topAdjust);
leftAdjust += parseInt($(this).css("marginLeft")) + parseInt($(this).css("paddingLeft"));
topAdjust += parseInt($(this).css("marginTop")) + parseInt($(this).css("paddingTop"));
})
If I remove the ":first" I get about 9 iterations, otherwise I get 2 (i.e. it isn't ran for the first 'div' enclosed in a tag with id 'Contents', which is what I want).
- 26-Jul-2012 09:39 PM
- Forum: Getting Started
EDIT: solved. This forum should really have a delete post option.
I get a null value. And I actually only want the first element (does subscript operator work?). The ul element in question definitely exists.- alert($(node).parent("ul").offset());
- $("html, body").animate(
- { scrollTop: ((savedepth > 1) ? ($(node).offset().top) : 0),
- scrollLeft: 200 }, {duration: 45+45*depth, queue: false }, 0);
The above works for animating vertically, but not horizontally. Even if animation is not possible how do I left-adjust the page? I am trying to create an effect where the clicked node in a tree display is positioned at the top left of the viewport (where the depth effects how right-adjusted it is); right now I can only get it to the top.
- 26-Jul-2012 09:08 AM
- Forum: Using jQuery
I've managed to create a zoom and scroll effect but it breaks if I have them run concurrently. When clicking on an element it is meant to zoom in scale with that element's depth (this works), and then scroll the page so that the top of the element is at the top of the viewport. This only works if I click on elements of equal depth to the current one, as the value of the offset is no longer valid after all the elements have been zoomed.
Interrupting the process with an alert allows correct behaviour to occur, as it allows the value to 'catch up'.
Here's the code I'm using:- (t = $("#contents .chapter")).click(zoomadjust = function(evt) {
- if(this != zoomednode) {
- var zoom, depth, t;
- if(!zoomednode)
- zoomednode = $(this).parents("ul")[0];
- t = depth = $(this).parents("ul").length;
- zoom = 130;
- while(--t > 0)
- zoomnum = (zoom *= 1.15);
- zoom += '%';
- depth -= $(zoomednode).parents("ul").length;
- if(depth < 0)
- depth *= -1;
- zoomednode = this;
- $("#contents").animate(
- { fontSize: zoom,
- },
- {duration: 45+45*depth, queue: false }, 0, 0
- );
- $("html, body").animate(
- { scrollTop: $(zoomednode).offset().top, {duration: 45+45*depth, queue: false });
- }
- })
I've tried predicting the value by scaling it up, but it doesn't seem to help.
EDIT: Wonder if lambda expressions can do what I'm seeking, let's have a look...
UPDATE: Nope, didn't work. I tried- $("html, body").animate(
- { scrollTop: function() { return $(zoomednode).offset().top } }, {duration: 45+45*depth, queue: false });
in the hope that it would always use the most up-to-date value each time it is referenced, but it seems that isn't supported...
- (t = $("#contents .chapter")).click(zoomfunc = function(evt) {
alert(evt);
if(this != zoomednode) {
var zoom, depth, t;
if(!zoomednode)
zoomednode = $(this).parents("ul")[0];
t = depth = $(this).parents("ul").length;
zoom = 130;
while(--t > 0)
zoom *= 1.15;
zoom += '%';
depth -= $(zoomednode).parents("ul").length;
if(depth < 0)
depth *= -1;
zoomednode = this;
$(contents).animate(
{ fontSize: zoom },
45+45*depth, 0,
function() {
}
);
}
})
t.select = zoomfunc;
'select' and 'focus' do not do what I want. The above code zooms hierarchically-arranged chapters in scale to the 'top-most' chapter that was most recently clicked on. I'm seeking an effect where if I CTRL-F in my browser for a chapter and it hilights it, it does the equivilent as if it had clicked on the chapter when hilighting it.- This might be more of a html/css question but I'm not certain, so I'll make this my 1st point of call.
I've added a click event handler to the elements of an unordered list. The problem is it responds to clicking anywhere in the horizontal space, including where the visible text ends. I'd like it to only answer to being clicked on the text itself.
Update: Got the desired effect by making a new class just to insert a span in the contents of the list element and make it 'display: inline'.- 25-Jul-2012 09:07 PM
- Forum: Getting Started
Ok, the following bit of code worked for the effect I was going for:- $("contents").click(function(evt) {
$(contents).animate(
{ fontSize: '+=50%' },
60);
});
- $("contents li").click(function(evt) {
$(contents).animate(
{ fontSize: '+=50%' },
60);
});
Which does not work at all. What is my incorrect assumption on how this all works?
EDIT: Looks like just $("li") works (except it still responds to clicking anywhere in the horizontal space--how can I fix that?). How do I go about obtaining only the li tags that are children of the element with the id 'contents' ?- If I insert
[code]<script src="http://code.jquery.com/jquery-1.7.2.min.js"/>[/code]
Above of
[code]
<script type="text/javascript" >
function processxml(xmldoc) {
var i, root, el, els, str, esc;
i = 0;
root = xmldoc.getElementsByTagName("featurelist")[0];
el = root.getElementsByTagName("chapter")[0];
/* Initiate contents */
str = '<ul id="contents">';
while(el && el != root) {
if(c=el.getAttributeNode("htmlclass"))
str += '<div id="' + c.value + '">';
str += "<li>" + el.getAttribute("title") +"</li>";
if((els = el.getElementsByTagName("chapter")).length) {
str += "<ul>";
el = els[0];
continue;
}
esc = 0;
while(!esc) {
save = el;
while((el = el.nextSibling) && el.nodeName != "chapter")
;
if(!el) {
/* No next sibling */
str += "</ul>";
el = save;
while((el = el.parentNode) && el.nodeName != "chapter")
;
if(!el)
/* No parent */
break;
else
/* Found parent, look again for sibling */
continue;
}
else {
/* We have next sibling */
if(c)
str += "</div>";
esc = 1;
}
}
}
/* Terminate contents */
str += "</ul>";
alert(str);
// document.write(str);
document.body.innerHTML = str;
}
function init() {
var xml;
xml = new XMLHttpRequest();
xml.open("GET", "digest.xml", false); // Will make asynchronous later on.
xml.send();
xmldoc=xml.responseXML;
processxml(xmldoc);
}
</script>
[/code]
The page fails to load with a "init is not defined" error. It loads just fine if I don't link the jquery source.- «Prev
- Next »
- (t = $("#contents .chapter")).click(zoomfunc = function(evt) {
Moderate user : caruga
© 2013 jQuery Foundation
Sponsored by
and others.