Re: [jQuery] jQuery toXML
Jason Karns wrote: I saw your toXML plugin and the thread where you were discussing its creation. I've run into a situation where I need to serialize the page to XML. However, the majority of the page is form elements and I need the actual values of these elements serialized, and not the original HTML source. Do you have any suggestions on where I might find a solution for this? Have you tried the Forms plugin: http://www.malsup.com/jquery/form/ Although it doesn't serialize to XML. If you want your form values as XML, you'd have to decided on a meaningful schema for the XML, and probably have to build up a document fragment manually from form values and then use toXML to serialize it. If returning the data as XML is really that important then it's probably worth looking in to XForms instead. FormFaces is a pure javascript XForms implementation: http://www.formfaces.com/ - Mark. ___ jQuery mailing list discuss@jquery.com http://jquery.com/discuss/
Re: [jQuery] Reading json strings
Bruce MacKay wrote: Hi folks, I don't understand what I'm doing wrong in the following code ( http://temporarius.massey.ac.nz/json_test.htm) where I cannot seem to harvest the returned json string. The test json string being returned after the form is submitted is: {fields: [{id: name, isValid: false, message: Username must be at least 3 characters long}]} I don't understand why the length of fields is being given as 1, and when I try to view the components of fields, I get an [object Object] error. json.fields is an Array containing just one Object. fields: [ -- An array { -- An object id: 'name', -- A property isValid: false, ... } ] If you want fields to contain an object, and you wish to iterate through the properties of that object then you need to get rid of the array: fields: { id: 'name', isValid: false, ... } for (var propertyName in json.fields) { alert(propertyName + ' = ' + json.fields[propertyName]); } Regards - Mark ___ jQuery mailing list discuss@jquery.com http://jquery.com/discuss/
Re: [jQuery] $.val() limited in functionality?
Jörn Zaefferer wrote: Currently val() is only a shortcut, but doesn't encapsulate anything useful. It would be nice to have it handling some more stuff. I wouldn't like to have it in an external plugin, that makes it difficult to access or find it when you actually need that functionality. Some thoughts about the implementation: - single select: Nothing to worry about, right? - multiple select: Get it's option:selected children and put their values into an array, empty array when nothing is selected - radio: Find the input:radio siblings with the same name and get the value from the one that is checked, ??? when nothing is selected - checkbox: combination of radio and select: Find input:checkbox siblings that are checked and put their values into an array, empty array when nothing is checked - everything else: stick to the simple value As a start, heres what I use: (It doesn't cover radio buttons as described above - as I never needed it) It returns an array of values if the jquery has several elements, it maybe more useful to return an object (id/name = value) instead. $.fn.getValue = function() { var o = []; this.each(function() { switch (this.type) { case 'checkbox': case 'radio': v = this.checked; break; case 'select-one': v = this.selectedIndex = 0 ? (this.options[this.selectedIndex].value || this.options[this.selectedIndex].text) : null; break; case 'select-multiple': v = []; for (var i = 0; i this.options.length; i++) { if (this.options[i].selected) v.push(this.options[i].value || this.options[i].text); } break; case 'button': case 'reset': case 'submit': break; default: v = this.value; } o.push(v); }); return o.length 1 ? o : o[0]; }; ___ jQuery mailing list discuss@jquery.com http://jquery.com/discuss/
Re: [jQuery] does jQuery has support for parameter handling ?
Truppe Steven wrote: Mark Gibson schrieb: In PHP have a look at: utf8_encode(), iconv, or mbstring I think i haven't clearly told my problem: I just have some article manager where for each article i have some description text (german english). At the moment i have one php file loading the text from the database and pass it to my article manager. Here i just want to send strings like Diesen Artikel würde viel kosten for example (auml;). If i do this without any encoding the strings get damaged and looks strange because of the way urls are interpreted. So i thought i must urlencode/urldecode it, as long as i urldecode/urlencode all in php it's working. I'm still a bit confused, but I guess you are trying to pass data from PHP to Javascript, and this data may contain character outside the ASCII character set. Javascript works with the Unicode, and your data is probably in ISO-8859-1. In this case I would suggest converting the data using PHP utf8_encode() and pass it in a JSON serialized string. URI's are absolutely useless for this kind of thing. ___ jQuery mailing list discuss@jquery.com http://jquery.com/discuss/
Re: [jQuery] Spam problem in bugs
Yehuda Katz wrote: Consider ticket 342 closed. I just committed your patch in the latest svn. -- Yehuda Thanks, but it doesn't seem to be there! The trunk is at rev 549 at present, is this what you're seeing? - Mark. ___ jQuery mailing list discuss@jquery.com http://jquery.com/discuss/
Re: [jQuery] console for IE
Mark Gibson wrote: I've adapted the console.js script originally found here: http://wish.hu/firebug-on-explorer Added pretty dumps of objects, arrays, elements, etc. My new script can be fetched from here: http://jollytoad.googlepages.com/browsercompatibility Andy Matthews wrote: Interesting. How is it used? console.log(some_variable); It's a better alternative to lots of nasty alert()'s when debugging javascript. It's roughly based on Joe Hewitt's fantastic Firebug extension for Firefox: http://www.joehewitt.com/software/firebug/ He introduced an object called console, which allows logging various useful stuff. If you haven't tried it, go get it now you wont know how you lived without it: https://addons.mozilla.org/firefox/1843/ ___ jQuery mailing list discuss@jquery.com http://jquery.com/discuss/
Re: [jQuery] New Plugin: Resizeable
Stephen Woodbridge wrote: Mark Gibson wrote: I've not had chance to test it, but I'm sure all elements have a resize event. If not then the resizeable plugin can trigger() it itself. Hi Mark, I tried to do this like this: $(document).ready(function(){ $('#resize_map').Resizeable( { minHeight: 100, maxHeight: 700, minWidth: 100, maxWidth: 800, handlers: { se: '#resize' } } ); $(#resize_map).bind('resize', function(e) { alert(resized event); }); }); But no event fires :(, I have also tried: $(#resize_map).resize(function(e) { alert(resized event); }); $(#resize_map).trigger('resize'); does force the event to fire. I can add the trigger('resize') to the resizable plugin, but it seems like it should just fire. Any other thoughts? Steve, After a quick flick through JavaScript, The Definitive Guide and a few online docs, it seems that the resize event only applies to window size changes. So you'd have to manually trigger the event. Also, I've noticed that trigger appears to be broken for IE in the latest jquery download r501! - but is fixed in SVN. BTW, you can just chain the bind: $('#resize_map') .Resizeable({ ... }) .bind('resize', function(e) { alert(resized event); }); - Mark. ___ jQuery mailing list discuss@jquery.com http://jquery.com/discuss/
Re: [jQuery] Hiding and showing table rows
Brian Morykon wrote: I was hoping to hide and show table rows with a slide effect. But it seems that Firefox needs a display: table-row instead of a display: block to make a row appear properly. While IE throws an error at table-row and does fine with block. While I didn't get the slide effect working, I did get the row to appear properly by adding these functions: [snip] Hope this helps someone -- or perhaps someone can help me find a better way. Thanks! You could find the default display value for a row by creating a dummy row and checking the css display value, this should be more reliable and future proof than browser sniffing (in case MS ever support table-row!): var rowdisplay = $('tr/tr').css('display'); Tested in FF2.0, IE7/6/5.5, Opera 9.02 Regards - Mark Gibson ___ jQuery mailing list discuss@jquery.com http://jquery.com/discuss/
[jQuery] Spam problem in bugs
Hi, I noticed there is a spam problem in the bug tracking system. Two enhancement requests I've submitted have been spammed: http://jquery.com/dev/bugs/bug/342/ http://jquery.com/dev/bugs/bug/344/ At least one of these (#342) is a feature I really need, and I'm starting to worry that it (and other tickets) are going to get ignored - could the site be changed to force a login before submitting/changing stuff (maybe using the mailing-list email and password)? Cheers - Mark Gibson ___ jQuery mailing list discuss@jquery.com http://jquery.com/discuss/
[jQuery] console for IE
Hi, this isn't directly jQuery related, but I thought you'd be interested. I've adapted the console.js script originally found here: http://wish.hu/firebug-on-explorer Added pretty dumps of objects, arrays, elements, etc. My new script can be fetched from here: http://jollytoad.googlepages.com/browsercompatibility Hope you find it useful, I do! PS. Improvements are very welcome. Regards - Mark Gibson. ___ jQuery mailing list discuss@jquery.com http://jquery.com/discuss/
Re: [jQuery] New Plugin: Resizeable
Stephen Woodbridge wrote: Hi Stefan, I have been trying your resize plugin, it is really slick and works great! I have a request, does it already have or can you add the ability to added a call back at the end of the resize, so other code can be notified of the change in size? Like notify below: $(document).ready(function(){ $('#resize_map').Resizeable( { minHeight: 100, maxHeight: 700, minWidth: 100, maxWidth: 800, handlers: { se: '#resize' }, notify: function(){ alert(I have been resized); $('#map_tag').Resized(this.sizes); } } ); }); Maybe there is another way to do this? Would this not be better suited to an event? $('#resize_map').bind('resize', function() { alert(I have been resized); }); I've not had chance to test it, but I'm sure all elements have a resize event. If not then the resizeable plugin can trigger() it itself. ___ jQuery mailing list discuss@jquery.com http://jquery.com/discuss/
Re: [jQuery] Function to enumerate the querystring?
Chris W. Parker wrote: On Tuesday, October 31, 2006 10:46 AM Luke Lutman said: Have a look at this recent thread :-) http://www.nabble.com/method-plugin-for-getting-query-string-vars--tf248 1232.html#a6919130 I read through this and tried to implement your first suggestion but I notice that everything takes location.search and parses that. I want to use it in the following way: theHref = $(this).attr(href).query(); Your function is: jQuery.query = function() { var r = {}; var q = location.search; q = q.replace(/^\?/,''); // remove the leading ? q = q.replace(/\$/,''); // remove the trailing jQuery.each(q.split(''), function(){ var key = this.split('=')[0]; var val = this.split('=')[1]; // convert floats if(/^[0-9.]+$/.test(val)) val = parseFloat(val); // ingnore empty values if(val) r[key] = val; }); return r; }; I'm not sure how to modify that function to do what I want (considering my current lack of JS/jQuery syntax). Would you mind showing me what to do? Thank you, Chris. ___ jQuery mailing list discuss@jquery.com http://jquery.com/discuss/ RFC3986 (URI Generic Syntax) presents a regular expression for parsing generic URI's: http://tools.ietf.org/html/rfc3986#page-50 Something like this (not tested): jQuery.parseURI = function(uri) { var m = /^(([^:/?#]+):)?(//([^/?#]*))?([^?#]*)(\?([^#]*))?(#(.*))?/.exec(uri); return { scheme: m[2], authority: m[4], path: m[5], query: m[7], fragment: m[9] }; } So: $.parseURI($(this).attr(href)).query would return the query string, which can then be parsed by the function above, or combine the two functions. - Mark Gibson ___ jQuery mailing list discuss@jquery.com http://jquery.com/discuss/
Re: [jQuery] Plugin method question
Ⓙⓐⓚⓔ wrote: let's just use the informal type text/x-jquery-json that contains 1 js object or text/x-jquery-text for an unquoted string of chars and others... There is an official 'application/json' media type registered at IANA. http://www.iana.org/assignments/media-types/application/ and an RFC: http://www.ietf.org/rfc/rfc4627.txt ___ jQuery mailing list discuss@jquery.com http://jquery.com/discuss/
[jQuery] Extending $.extend to extend from multiple objects!
Hi, I'd like to suggest an enhancement to $.extend, to allow extending an object from multiple objects. This will allow a simple way for plugins to have a global set of default options: $.fn.plugin(options) { var options = $.extend({}, arguments.callee.defaults, options || {}); ... } $.fn.plugin.defaults = { ... } This extends an empty object with the global defaults and then again with the local options. With the existing implementing this would have to be done as such: $.extend($.extend({}, arguments.callee.defaults), options || {}); Heres the new $.extend function: jQuery.extend = jQuery.fn.extend = function(obj) { // If no property objects were provided, then we're extending jQuery if ( arguments.length == 1 ) { var obj = this; var a = 0; } else { var a = 1; } while (a arguments.length) { var prop = arguments[a]; if (prop !== null prop != undefined) { // Extend the base object for ( var i in prop ) obj[i] = prop[i]; } a++; } // Return the modified object return obj; }; - Mark Gibson ___ jQuery mailing list discuss@jquery.com http://jquery.com/discuss/
Re: [jQuery] Function to enumerate the querystring?
Chris W. Parker wrote: On Tuesday, October 31, 2006 10:46 AM Luke Lutman said: Have a look at this recent thread :-) http://www.nabble.com/method-plugin-for-getting-query-string-vars--tf248 1232.html#a6919130 I read through this and tried to implement your first suggestion but I notice that everything takes location.search and parses that. I want to use it in the following way: theHref = $(this).attr(href).query(); Your function is: jQuery.query = function() { var r = {}; var q = location.search; q = q.replace(/^\?/,''); // remove the leading ? q = q.replace(/\$/,''); // remove the trailing jQuery.each(q.split(''), function(){ var key = this.split('=')[0]; var val = this.split('=')[1]; // convert floats if(/^[0-9.]+$/.test(val)) val = parseFloat(val); // ingnore empty values if(val) r[key] = val; }); return r; }; I'm not sure how to modify that function to do what I want (considering my current lack of JS/jQuery syntax). Would you mind showing me what to do? Hello, following my previous reply to this, I've had to implement this myself. So here it is, attached. This returns an object containing the properties: - as specified in RFC3986 (URI Generic syntax) - compatible with the window.location object - the query string split into key=value pairs You can cut out what you don't need. (I can't believe a JS mailing list bounces js attachments, I try again with it pasted inline!) jQuery.parseURI = function(uri) { var m = /^(([^:\/?#]+):)?(\/\/([^\/?#]*))?([^?#]*)(\?([^#]*))?(#(.*))?/.exec(uri); var q = m[7].split(''); var p = {}; while (q.length 0) { var x = q.shift().split('='); p[x[0]] = x[1]; } return { // Generic components (as specified in RFC3986) scheme: m[2], authority: m[4], path: m[5], query: m[7], fragment: m[9], // window.location compatible properties hash: m[8], host: m[4], hostname: m[4].split(':')[0], href: uri, pathname: m[5], port: m[4].split(':')[1] || '', protocol: m[1], search: m[6], // The parsed query string: params: p }; }; I've also uploaded it here: http://jollytoad.googlepages.com/uri.js ___ jQuery mailing list discuss@jquery.com http://jquery.com/discuss/
Re: [jQuery] Plugin method question
Paul McLanahan wrote: @jake I'm really liking the code tag idea. If I'm understanding you correctly, it would work something like associating a label to an input using the for attribute. I'd just be associating a code tag's contents with a specific DL either by location in the markup or maybe by some specific classes. That might prove to be the easiest and most semantically correct solution. I find that a good way of passing data/options/etc to javascript is using hidden inputs: input type=hidden id=stuff value={put:'your',options:'here'}/ I often use JSON notation in the value, then you can just eval() it. var options = eval($('#stuff').val()); ___ jQuery mailing list discuss@jquery.com http://jquery.com/discuss/
Re: [jQuery] how to stop each iteration under each's function?
asterocean wrote: for exzample: $([EMAIL PROTECTED]'text']).each(function(){if (this.value==){alert(error);this.focus();break;}}); but 'break;' won't stop the iteration of each, what should i do? There was some discussion on this list of returning false to break the loop - but I'm not sure if that has been implemented yet - does anyone know? $([EMAIL PROTECTED]'text']).each(function() { if (this.value==) { alert(error); this.focus(); return false; } }); Otherwise, you can throw an exception: try { $([EMAIL PROTECTED]'text']).each(function() { if (this.value==) { alert(error); this.focus(); throw true; // The actual value here is arbitary } }); } catch(e) {} ___ jQuery mailing list discuss@jquery.com http://jquery.com/discuss/
[jQuery] Patch: Set Content-Type of an AJAX request
Hi, I'd like to suggest an additional option for $.ajax() to allow an alternative Content-Type, eg: application/json I'd like to send raw JSON data to a PHP script, but PHP requires that a Content-Type other than the usual 'application/x-www-form-urlencoded' is set before it allows you to access the raw request data (via $HTTP_RAW_POST_DATA). This will also allow the correct submission of XML, and other formats. I've attached a patch against ajax.js Cheers - Mark Gibson Index: ajax.js === --- ajax.js (revision 512) +++ ajax.js (working copy) @@ -686,6 +686,7 @@ var success = type.success; var error = type.error; var dataType = type.dataType; + var contentType = type.contentType || application/x-www-form-urlencoded; var global = typeof type.global == boolean ? type.global : true; var timeout = typeof type.timeout == number ? type.timeout : jQuery.timeout; ifModified = type.ifModified || false; @@ -708,7 +709,7 @@ // Set the correct header, if data is being sent if ( data ) - xml.setRequestHeader(Content-Type, application/x-www-form-urlencoded); + xml.setRequestHeader(Content-Type, contentType); // Set the If-Modified-Since header, if ifModified mode. if ( ifModified ) ___ jQuery mailing list discuss@jquery.com http://jquery.com/discuss/
Re: [jQuery] json.js
Jörn Zaefferer wrote: When I introcuded json.js [http://json.org/json.js] from http://json.org/ . Problem now is my browser keeps freezing and eating up CPU. I checked and it is clearly conflicting with JQuery. It extends Object, which seemes to cause lots of trouble with jQuery. You could check if it works when removing Object.prototype.toJSONString. Yeah, I had this problem, so I hacked the original json.js into a jQuery plugin. It adds the two functions: var json_str = $.toJSON(value) var value= $.parseJSON(json_str, [safe]) If the optional safe argument is supplied as true, then the string will be checked for valid JSON syntax. Safety checks can be set globally by setting: $.parseJSON.safe = true; You can find the code here: http://jollytoad.googlepages.com/json.js Regards - Mark Gibson ___ jQuery mailing list discuss@jquery.com http://jquery.com/discuss/
[jQuery] New Plugin: StickHeadings (experimental)
Hi, I've start work on an experimental plugin that freezes section headings at the top of a scrollable container while the section content is in view. See here for a demo: http://jollytoad.googlepages.com/stickyheadings I'm having a couple of issues, mentioned on the page above. The main ones are the jerky motion in Firefox and the out-of-whack offsets in IE. Can anyone help? Cheers - Mark Gibson ___ jQuery mailing list discuss@jquery.com http://jquery.com/discuss/
Re: [jQuery] nice plugin idea - Splitter
Armand Datema wrote: I just found this link http://www.jackslocum.com/yui/2006/08/19/a-splitbar-component-for-yahoo-ui/ Does a jquery version excist yet? I don't about that, but have you tried the 'Click here and I will point it out' link!!! Wow! That's it, documentation is going in the bin, it's live demonstrations from now on. ___ jQuery mailing list discuss@jquery.com http://jquery.com/discuss/
Re: [jQuery] jQuery API discussion
John Resig wrote: e.g.: $( '.b0rp' ).filter( '#blap' ).on.click( function() { $( '#foo' ).ajax.load( ... ) } ); Why no just do .onclick() and .ajaxLoad() - like what was proposed? Not only is it fundamentally easier to write and understand, but it's easier to implement too. The feasibility of 'namespacing' hasn't been brought up yet - but leave it to be said that it would be really really difficult and add a ton of overhead to the jQuery base as a whole (in order to continue chainability support). AJAX functionality is the one exception where I think a prefix is going to help. Instead of doing .get(), .post(), or .load() - having .ajaxGet(), .ajaxPost(), and .ajaxLoad() simply makes more sense. Why not just .request(method, options) or .http() After all AJAX is just a bottle of toilet cleaner ;), and a bit of a misnomer as a lot of calls don't even involve the X(ML). - Mark. ___ jQuery mailing list discuss@jquery.com http://jquery.com/discuss/
Re: [jQuery] Compiling selectors into native Javascript
John Resig wrote: The thread about benchmarks got me thinking about compilation and caching of selectors too. It could be a big win for benchmarks where they use the same selector in a loop 1000 times! :-) The problem with caching is that it's unable to handle situations where the DOM changes in-between, unless there's an explicit .refreshCache() or some such. And doing this by default is hardly desirable, as it would cause a lot of common code to break. It is something that is definitely explorable some day - I'm just afraid that the payoff may not be worth it. The cache isn't for the DOM at all, it caches compiled selectors as native javascript functions, so that the selector string doesn't need to be parsed everytime. ___ jQuery mailing list discuss@jquery.com http://jquery.com/discuss/
Re: [jQuery] Compiling selectors into native Javascript
Dave Methvin wrote: So my take was that the performance payback for simple selectors called frequently could be good, but those cases are already pretty fast--we're reducing a number that's already small. Complex selectors would still require helper functions or compiled-in loops on every function invocation, so they won't be improved nearly as much. Still, it would be a fun project to try! My main inspiration was the similarity of concepts between jQuery and XPath2, both essentially result in a sequence of elements (also values in XPath2). It occurred to me that several XPath2 features could map easily to javascript helper functions: axes, functions, and operators. I'm wondering how complex an XPath2 implementation would be? ___ jQuery mailing list discuss@jquery.com http://jquery.com/discuss/
Re: [jQuery] Variable from PHP to Jquery
Steven Wittens wrote: [snip] Also to avoid having to use templated JS, we have a transparent mechanism for passing data from PHP to JS. All you do is call an API drupal_add_js(), which aggregates all variables that it is passed, and automatically inserts them as a single inline script tag in the HTML head, as Drupal.settings = { ... }. This works really well: you don't need to dynamically generate .js files, and you avoid large chunks of inline code. [snip] Alternatively you could use one of the JSON serializers for PHP: http://json.org ___ jQuery mailing list discuss@jquery.com http://jquery.com/discuss/
Re: [jQuery] jQuery API discussion
Jörn Zaefferer wrote: If we go back to the roots and stick to bind(), unbind(), trigger(), attr() and css(), we could remove all those events and html and css attribute shortcut methods, greatly reducing the number of methods. By adding those methods, or rather only parts of it, like click(), back via plugins, the jQuery meat could be reduced to some extend, maybe even reducing the barrier for newcomers by simplifying the API docs. bind(), unbind(), trigger() and attr() could be improved to a hash as css() alread does, allowing you to set several attributes at once or adding/removing several events with one method call. Passing a hash without values to attr could be quite sexy, too, when it simply fills the hash with all available values. Your ideas and opinions, please! Aye, aye. How much harder is it really to use: $(...).bind('click', function() {...}); than: $(...).click(function() {...}); and $(...).bind({ click: function() {...}, change: function() {...}, }); sounds quite nice too. And for those lazy sods out there how about: $.quickMethods({ bind: ['click'], attr: ['val','href','title'], css: ['display','height','width'] }); and .click(), .val(), etc. are instantly restored. You get the idea ;P While we're on the API: I really don't like the method name .css(), as its actual operation is to change a style property, and doesn't really have much directly to do with Cascading Style Sheets. Could it not be .style() instead? - Mark. ___ jQuery mailing list discuss@jquery.com http://jquery.com/discuss/
Re: [jQuery] $(document).load() and friends
Mika Tuupola wrote: Am I missing something obvious or why does .load() not seem to trigger anything. I am sure $('img').load(function() { something }); used to work before. This is not the case with 1.0.2. Check the page below. I get only ready at firebug console. So none of the load()'s get executed. http://www.appelsiini.net/~tuupola/jquery/panview/load.html -cut- $(document).ready(function() { console.log('ready'); }); $('img').load(function() { console.log('img load'); }); $('p').load(function() { console.log('p load'); }); $(document).load(function() { console.log('document load'); }); -cut- $('img') and $('p') won't find anything until the document is ready, try: $(document).ready(function() { console.log('ready'); $('img').load(function() { console.log('img load'); }); $('p').load(function() { console.log('p load'); }); }); I'm not sure about $(document).load though, never used it! - Mark Gibson ___ jQuery mailing list discuss@jquery.com http://jquery.com/discuss/
Re: [jQuery] Best way for storing user preferences?
Raffael Luthiger wrote: 2) The js-script gets generated each time the page is called. And the corresponding vars are set in there. 3) Every time the page is loaded the js-script asks the server for a XML (or JSON) file with the preferences in there. 5) More (and better) ideas? I'd use a combination of these. This same problem plagued me for a while too, I didn't like the idea of generating JS on the fly, and an ajax request seemed overkill, then it suddenly struck me today: From the backend, serialize your data as JSON, and place it in the value attribute of a hidden input element. eg: in HTML: input type=hidden id=state value={hide:['section1','section2']}/ then in JS: eval('var state = ' + $('#state').val()); I'm currently writing a plugin to pull JSON data from a document like this (roughly based on XForms model/instance concepts), although as I say I've only just started this today :) - Mark Gibson ___ jQuery mailing list discuss@jquery.com http://jquery.com/discuss/
Re: [jQuery] jQuery 1.0.2 RC2
Jörn Zaefferer wrote: it's time for another release candiate, this time including even more bug fixes and nothing else. IE 6.0.2900.2180 (XP SP2) - 1 tests of 211 failed: 38. $.find() (1, 42, 43) Firefox 1.5.0.7 - ok (test #55 failed once - but I think this may have been down to a network error) Opera 9.02 - ok ___ jQuery mailing list discuss@jquery.com http://jquery.com/discuss/
[jQuery] New plugin: toXML (XML serializer)
Hi, I've submitted the XML serializer plugin to the wiki: http://jquery.com/docs/Plugins/toXML/ - Mark Gibson ___ jQuery mailing list discuss@jquery.com http://jquery.com/discuss/
Re: [jQuery] New plugin: toXML (XML serializer)
Christof Donat wrote: Simulate XMLSerializer globally and use it always - change the serialization function on first call to distinguish between IE and others. [snip] I admit, that the two suggestions might not be to easy to understand. I like to play with functions as values :-) At least the first one provides a more general solution by simulating XMLSerializer and both of them are faster after the first call. That might be a criterium if you work with large Datasets. If performance is imortant to you, you might also consider to replace the calls to each() with for-loops. Christof, thanks for your ideas. The thing is, the main use case for a toXML() call is to send XML data via an ajax request. The duration of the request greatly overshadows any optimisation that could be applied to toXML. Also, I don't think it is a good idea to attempt to implement an XMLSerializer object for the sake of it, especially when the full interface isn't being implemented - it could have further reaching effects than you expect. As a rule I live by the KISS principle, and never optimise code unless it becomes a bottleneck, and then only do so under profiling conditions. Regards - Mark Gibson ___ jQuery mailing list discuss@jquery.com http://jquery.com/discuss/
[jQuery] jQuery stylesheets
Recently I've been playing with loading of HTML into pages dynamically, which lead to my script evaluation plugin, that I posted yesterday. Now I've hit another problem: I'd like to apply a common set of operations (ie. applying plugins) to all elements on a page, whether they were there from the start, or loaded dynamically. The first part is easily handled by $(document).ready(), but loaded content can only be processed by supplying a callback every time. The solution I've considered is to register callback functions that act like stylesheets, and are applied to dynamic content. eg: $.stylesheet(function() { $('input').each(function() { $(this).addClass(this.type); }); }); This stylesheet adds the input type to the class name, so we can style different input types individually (in browser that don't fully implement CSS selectors, you know who you are! ;) $.stylesheet is the registration function. Within the 'load' function, or other places where content is added, we call: self.applyStylesheets(); Here is the implementation of these functions: $.stylesheet = function(callback) { if ($.stylesheet.list === undefined) $.stylesheet.list = new Array(); if (typeof callback == 'function') $.stylesheet.list.push(callback); }; $.fn.applyStylesheets = function() { if (typeof $.stylesheet.list == 'object') { var self = this; $.each($.stylesheet.list, function() { if (typeof this == 'function') { this.call(self); } }); } return this; }; What do you think? Cheers - Mark Gibson (I've resent this email, as it didn't seem to get through first time, sorry if you get it twice!) ___ jQuery mailing list discuss@jquery.com http://jquery.com/discuss/
[jQuery] Evaluating script elements
Hi, I believe there is a flaw in the way scripts are evaluated in the 'load' function. This piece of code is my concern: // Execute all the scripts inside of the newly-injected HTML $(script, self).each(function(){ if ( this.src ) $.getScript( this.src ); else eval.call( window, this.text || this.textContent || this.innerHTML || ); }); It doesn't load scripts (with src attribute) in expected way that a browser would. Take the following snippet of html: script src=fancy-plugin.js/script script $('#foo').FancyPlugin(); /script Loaded in a normal html page in the normal way in a browser, fancy-plugin.js would be loaded and ready, before the second script is executed. If loaded via 'load', then 'fancy-plugin.js' is loaded asyncronously, and may not be evaluated before the second literal script is. You see the problem? The solution is to wait for each script to load before executing the next. Here's my solution as a plugin: (I was thinking it should probably be added to the core as a reusable function, and called from within 'load', replacing the snippet above) $.fn.eval = function(callback) { var self = this; var exec = function(scripts) { console.log(scripts); for (var i=0; i scripts.length; i++) { if (scripts[i].src) { $.getScript(scripts[i].src, function() { if (i+1 scripts.length) { // Continue executing remaining of scripts exec(scripts.gt(i)); } else if (typeof callback == 'function') { // This was last script, so call the callback fn callback.call(self); } }); // Remaining scripts will be eval'd after this script is loaded return; } else { // Evaluate the content as the script eval.call(window, scripts[i].text || scripts[i].textContent || scripts[i].innerHTML || ); } } if (typeof callback == 'function') callback.call(self); } exec($(this).filter('script')); return this; }; BTW: this was tested with jQuery rev 384. Cheers - Mark Gibson ___ jQuery mailing list discuss@jquery.com http://jquery.com/discuss/
Re: [jQuery] Evaluating script elements
Brian wrote: Looks good, but please don't use eval as the function name. It's a Bad Idea to overload reserved/predefined words, even if namespaced. Oops, sorry. I was going to rename it before submitting the suggestion. How about: evalScript() exec() execScript() any ideas? ___ jQuery mailing list discuss@jquery.com http://jquery.com/discuss/
Re: [jQuery] Serializing XML
Ok, after some searching around the web, I believe that Firefox, Opera, and Safari all implement XMLSerializer, whilst IE has an 'xml' property on every node. So here's my XML serializer plugin: $.fn.serializeXML = function () { var out = ''; if (typeof XMLSerializer == 'function') { var xs = new XMLSerializer(); this.each(function() { out += xs.serializeToString(this); }); } else if (this[0] this[0].xml != 'undefined') { this.each(function() { out += this.xml; }); } return out; }; It seems to work in FF 1.5.0.7 and IE 6, but needs testing in Opera and Safari. - Mark Gibson ___ jQuery mailing list discuss@jquery.com http://jquery.com/discuss/
[jQuery] SVN Error
Hi, I've just tried an update from SVN, (add a checkout to double check) and just keep getting the following error: Can't find temporary directory! It seems to be just on jquery.com, as my other svn sandboxes update ok. - Mark. ___ jQuery mailing list discuss@jquery.com http://jquery.com/discuss/
Re: [jQuery] Widget Challenge
Dan Atkinson wrote: Why the bottom? Is that where the Apple menu is? I don't know, I don't have an Apple computer. I like the idea of cloning the icon to maintain the menu position. I'll be honest and say that I simply don't have the JS/jQuery knowledge to clone it. Is it just: $(img).clone().appendTo(img); ?? That would just add it next to the image... Hmmm... No. I don't know enough about it to do that with ease! :) Couldn't that be done, just by changing the CSS 'position' property so something like 'fixed', 'absolute', or whatever (haven't had time to look it up!) so it no longer affects the surrounding element. ___ jQuery mailing list discuss@jquery.com http://jquery.com/discuss/
[jQuery] Suggestion: add iframe hack to core jQuery
Hi, I was thinking that due to it being such a common problem, I'd like to suggest adding the iframe hack for IE to the jQuery core. (To hide select elements beneath a positioned element) The plugin below appends an iframe with the necessary css so that you don't need any messy hacks in your normal CSS stylesheets. I've made use of IE's CSS expression() to resize the iframe to match the parent element - the previous suggestions of 3000px caused select's to the left or below to disappear. I've only tested in IE6, will it work in IE 5/5.5? Is it needed for IE7? $.fn.iframehack = function() { if ($.browser.msie) return this.append('iframe style=display:block;position:absolute;top:0;left:0;z-index:-1;filter:mask();width:expression(this.parentNode.offsetWidth);height:expression(this.parentNode.offsetHeight)/'); else return this; }; ___ jQuery mailing list discuss@jquery.com http://jquery.com/discuss/
Re: [jQuery] mousewheel plugin
Brandon Aaron wrote: I've actually just recently implemented the mousewheel and thought about writting it as a plugin. There are a few special situations that need to be considered. For example IE allows a mousewheel event to be attached to an element in the dom and Firefox allows it only to be attached to the document. So I have normalized this so that you can attach a mousewheel event to elements in the dom. The unfortunate part is that it doesn't work in Safari, yet. I'm not sure about Opera. Strange, I've managed to attach it to any element: el.addEventListener('DOMMouseScroll', function(e) { console.log(e.detail); e.preventDefault(); }, false); Hover the mouse over the element and scroll, it worked fine! The element doesn't even require focus. (Firefox 1.5.0.7) e.detail usually contains 3 or -3. - Mark. ___ jQuery mailing list discuss@jquery.com http://jquery.com/discuss/
Re: [jQuery] Suggestion: add iframe hack to core jQuery
Brandon Aaron wrote: BTW ... Great idea on using the expression css and the mask filter! That reduces the code lots. Cheers, I haven't even got a clue what the mask filter does! It was suggested in the date picker plugin. Normally I steer clear of this wierd IE specific stuff, but this seemed to be the perfect (ab)use of expressions. :) - Mark ___ jQuery mailing list discuss@jquery.com http://jquery.com/discuss/
[jQuery] Bugs in idrag/idrop
Hi Stefan, I've just downloaded the latest Interface today, it seems to be throwing up a few errors in idrag.js: During a drag operation: newCoords has no properties, line 340: if (newCoords.constructor == Object) { After a drag operation: elm is not defined, line 287: dragged.dragCfg.onStop.apply(elm); Also, there seems to be a problem with idrop.js too. Wherever I drop an item on the page, it calls the ondrop of the palette. The attached example demonstrates this and the errors above. BTW, I'm using: Firefox 1.5.0.6 (with Firebug) jQuery r249 idrag.js r1.25 idrop.js r1.6 Cheers - Mark. Title: Drag'n'drop Testing Drag'n'drop Test Palette Item 1 Item 2 Item 3 Drop items here ___ jQuery mailing list discuss@jquery.com http://jquery.com/discuss/
Re: [jQuery] Performance of idrag/idrop
Mark Gibson wrote: Ideally I'd like to have a single Droppable on the whole table, and use the 'ondrop' callback, but having the position of the pointer (relative to the table element) passed to the callback function, is this possible? Right, I've solved it. To recap the problem: I have a palette of items, which need associating with columns in a table. I wanted to drag the item into the table (using ghosting drag). On dropping the item it would be removed from the palette and placed in the TH cell of whichever column it was dropped in. First I tried adding a Droppable to every TH and TD - this caused a major delay at the beginning of the drag operation. Now, I've got a Droppable on just the TABLE: $(table).Droppable({ accept: 'item', tolerance: 'pointer', ondrop: function(item) { var dropx = item.dragCfg.cursx; // The cursor position at time of drop var ths = $(this).find('th'); // Get all heading cells // Find the column in which the drop occurred for (var i=1; i ths.length; i++) { if (dropx jQuery.iUtil.getPosition(ths[i]).x) break; } // Place the item in the column heading $(item).remove().appendTo(ths[i-1]); } }); I have to ask though, if using of item.dragCfg.cursx is future proof? Is there a better/safer way I should be doing this? Otherwise, I hope this may help someone else. Cheers - Mark ___ jQuery mailing list discuss@jquery.com http://jquery.com/discuss/
Re: [jQuery] XPath '[EMAIL PROTECTED]' doesn't work on XML documents
Mark Gibson wrote: John Resig wrote: Just a hunch, but IE's DOM support isn't native Javascript. If they got their typelib wrong it may be trying to call getAttribute rather than check elem for a getAttribute property. Can you replace that last line with this and see if it works? } else if ( typeof(elem.getAttribute) != undefined ) { Ok, this fixes one problem, but a further error occurs on line 641: return elem.getAttribute( name, 2 ); It appears that the getAttribute method on XML elements only accepts a single argument: return elem.getAttribute( name ); From the MS docs the second argument of 2 forces the method to be case-sensitive, which if I'm correct, isn't required by any browser other than IE. So is it possible to detect whether the browser is IE and the document is an HTML doc - in which case use the two args method, otherwise call with just one arg. Sorry, I got this wrong - it doesn't force case sensitive. According to the docs: 2 - Returns the value exactly as it was set in script or in the source document. Now I'm even more confused, what else would it return? - Mark. ___ jQuery mailing list discuss@jquery.com http://jquery.com/discuss/
[jQuery] Performance of idrag/idrop
Hi, I've created a UI where items can be dragged from a palette and dropped into a table - using jQuery and iDrag/iDrop from Interface. So, I've made every table cell and heading ('th.td') a Droppable, so there could be hundreds of droppables, but only a small amount of draggables (ie. less than 20). Now this is causing a major delay on starting a drag operation. I've had a look at idrop.js, and highlight() seems to where the delay occurs. I tried to profile the code using venkman, but can't my head round it at the minute - anyone know an easy way to profile a javascript function? Anyway, could anyone suggest an alternative, some performance improvements, or where the bottleneck is in highlight()? I thought about making the whole table a droppable - but I'm unsure of how to retreive the target element from a draggable. (BTW, i'm using ghosting if it makes a difference) Cheers - Mark Gibson ___ jQuery mailing list discuss@jquery.com http://jquery.com/discuss/
Re: [jQuery] Performance of idrag/idrop
Stefan Petre wrote: When you drag an element each droppable is interrogated until overlaps or to the end if no droppable is overlapped. If you have a large amount of drop zones in a grid with the same dimensiunos then you can use 'onDrag' and 'onDrop' callback from draggable to use mathematic rules for overlapping and decide witch drop zone is overlapped and to do further action. Yeah, I though of this, but can't see where I can position info from in the callback. Ideally I'd like to have a single Droppable on the whole table, and use the 'ondrop' callback, but having the position of the pointer (relative to the table element) passed to the callback function, is this possible? Cheers - Mark. ___ jQuery mailing list discuss@jquery.com http://jquery.com/discuss/
[jQuery] XPath '[EMAIL PROTECTED]' doesn't work on XML documents
Hello, I've come across a strange bug in IE: I've loaded an XML doc using $.get(), and selecting nodes using an XPath with a predicate containing an attribute: $([EMAIL PROTECTED], xml) IE just throws a wobbly: Line: 639 Error: Wrong number of arguments or invalid property assignment which appears to reside in the 'attr' function, the line is: } else if ( elem.getAttribute ) { as you see the message is a bit vague, i don't see a function call here or an attempt at assigning a property! I've attached demonstration files html/js/xml. (.js renamed to .jsx - as the mail server rejected it!!!) BTW, this works fine in Firefox, what a surprise! ;) Cheers - Mark Gibson (jQuery: r249) (IE: 6) Title: jQuery Testing Test Your Mum test data stuff=0/ data stuff=1/ /test $(function() { alert($([EMAIL PROTECTED]).length); // This works (shows: 2) $.get(selector.xml, function(xml) { alert($([EMAIL PROTECTED], xml).length); // This fails in IE }); }); ___ jQuery mailing list discuss@jquery.com http://jquery.com/discuss/
[jQuery] Wiki Vandalism
Hello, It appears that some anonymous fool has arsed about with the wiki, and Plugins/ExtendedTabs is no more. Is there a way of viewing historic versions of pages if this happens? or restoring it ourselves? In the mean time does anyone have the code for ExtendedTabs that they could email to me? Cheers - Mark Gibson ___ jQuery mailing list discuss@jquery.com http://jquery.com/discuss/
[jQuery] Patch for idrag.js
Hello, I've just started using jQuery and Interface, fantastic bit of kit I must say, it's a lot nicer than Yahoo UI's bloat. I've come across a small bug in Interfaces idrag.js regarding the onStop and onChange functionality - they didn't work! I've attached a patch to fix the problem. Cheers - Mark Gibson PS. Sorry if this isn't the right place, but I couldn't find a bug list, SF style management, etc. BTW. Is Interface accessible via anon CVS/SVN from anywhere? --- interface/idrag.js 2006-09-04 21:20:00.0 +0100 +++ DL-trunk/js/jquery/interface/idrag.js 2006-09-06 13:06:39.103470200 +0100 @@ -297,9 +297,10 @@ jQuery.iDrag.helper.css('cursor', 'move'); } + nx = dragged.dragCfg.oR.x + ((!dragged.dragCfg.axis || dragged.dragCfg.axis == 'horizontally') ? (dragged.dragCfg.nx - dragged.dragCfg.oC.x + dragged.dragCfg.diffX) : 0); + ny = dragged.dragCfg.oR.y + ((!dragged.dragCfg.axis || dragged.dragCfg.axis == 'vertically') ? (dragged.dragCfg.ny - dragged.dragCfg.oC.y + dragged.dragCfg.diffY) : 0); + if (dragged.dragCfg.revert == false) { - nx = dragged.dragCfg.oR.x + ((!dragged.dragCfg.axis || dragged.dragCfg.axis == 'horizontally') ? (dragged.dragCfg.nx - dragged.dragCfg.oC.x + dragged.dragCfg.diffX) : 0); - ny = dragged.dragCfg.oR.y + ((!dragged.dragCfg.axis || dragged.dragCfg.axis == 'vertically') ? (dragged.dragCfg.ny - dragged.dragCfg.oC.y + dragged.dragCfg.diffY) : 0); if (dragged.dragCfg.fx 0 nx != dragged.dragCfg.oC.x ny != dragged.dragCfg.oC.y) { x = new jQuery.fx(dragged,dragged.dragCfg.fx, 'left'); y = new jQuery.fx(dragged,dragged.dragCfg.fx, 'top'); @@ -351,8 +352,8 @@ if (dragged.dragCfg.onChange (nx != dragged.dragCfg.oR.x || ny != dragged.dragCfg.oR.y)){ dragged.dragCfg.onChange.apply(dragged, dragged.dragCfg.lastSi); } - if (dragged.dragCfg.onStart) - dragged.dragCfg.onStart.apply(elm); + if (dragged.dragCfg.onStop) + dragged.dragCfg.onStop.apply(elm); /*if (dragged dragged.dragCfg.prot == false) { if (dragged.dragCfg.ghosting == false) { @@ -657,7 +658,7 @@ hpc : o.hpc ? o.hpc : false, onDrag : {}, onStart : o.onStart o.onStart.constructor == Function ? o.onStart : false, - onStop : o.onStart o.onStart.constructor == Function ? o.onStop : false, + onStop : o.onStop o.onStop.constructor == Function ? o.onStop : false, onChange : o.onChange o.onChange.constructor == Function ? o.onChange : false, axis : /vertically|horizontally/.test(o.axis) ? o.axis : false ___ jQuery mailing list discuss@jquery.com http://jquery.com/discuss/