[jQuery] unsibscribe without google account
Hi, I'm trying to unsubscribe from this mailinglist and from the developer mailinglist. It seems, that I need a google account for that. Actually I wasn't planing to create a new account just to unsubscribe from two mailinglists. Is there another way? Christof
[jQuery] Re: is accessing element by a class faster than accessing X element by ID
Hi, $('#toto_contaner').children(); That only works, if all .toto elements are direct children of #toto_contaner and there are no other elements in #toto_contaner. In case only the second assumption does not hold, I guess $('#toto_contaner div.toto').hide() is the fastest solution. If the first assumption does not hold, there are two possible cases. Maybe all .toto elements are inside the #toto_contaner, but some of them are not direct children. Then I guess $('#toto_contaner div.toto').hide() is be the best solution. If there is not reasonable #toto_contaner, then I'd expect $('div.toto').hide() to usually be faster than calling 50 times $('#toto'+n).hide(). Of course that depends on how many other Elements the page contains. The more Elements the page has, the better it is to use IDs instead of classes. Also, the reason I was using the ref=n method to set up the list was for a guaranteed ref 1 will be toto[1] every time bit, I see. Since I understood Jean Babtiste that he wants to hide all elements at the same time, I did not think about that problem. Christof
[jQuery] Re: is accessing element by a class faster than accessing X element by ID
Hi, although i couldn't see one or the other or even the other being much faster considering that the selector would have to go through all the elements to see if *any* element on the page either (1) has the specified class or (2) has the specified id There is document.getElementById() which usually is really fast. If you use $('#toto1') uses that. That is why I am not really shure. If you use 50 or more times $('#toto'+n).hide() I'd expect the parser and the many function calls to take up quite some time, so that the whole construct should not be faster than using the class $('.toto').hide(). If all relevant Elements are in the same container, then I'd expect $('#container .toto').hide() to be a good solution. If all the relevant Elements are divs and there are more elements in the container, then $('#container div.toto').hide() might give you a bit more speed. Christof
[jQuery] Re: is accessing element by a class faster than accessing X element by ID
Hi, And try something like: var toto = []; $('.toto').each(function(){ var elem = $(this); toto[elem.attr('ref')] = elem; } Then, to hide the toto div with ref=1 or ref=2, just call: toto[1].hide(); toto[2].hide(); Why not use this: var toto = $('.toto'); toto[1].hide(); toto[2].hide(); That should be the same. Appart from that I think, that Jean Babtiste wanted to hide all elements at the same time. I'd expect his first ( $('.toto').hide() ) version to be usually faster, but I'm not shure about that. Christof
[jQuery] Re: Norton thinks jQuery is a virus?
Hi, Anyone got any ideas? This is now happening to one of our guys on any site he visits that is using jQuery. Even interface.js got blocked at one point.. Risk name: HTTP Acrobat PDF file suspicious download File: jquery.js Are you shure, your Server does not deliver .js Files as application/pdf? Appart from that: Norton is considered harmfull. Christof
[jQuery] Re: Exists
Hi, if(!$('label[for=Subject,class=Error]').length) Have you tried $('label[for=Subject].Error'? Christof
[jQuery] Re: How to clone jQuery object?
Hi, I meant to ask... What is the actual goal here? Can you give a little background? Maybe there is another way to accomplish what you want to do that doesn't rely on cloning the jQuery constructor. I want to have both $ and $D; but in $D, I want to override some functions like 'click', 'hover'. Till now, $ and $D gets overwritten and so I couldn't use $ or couldn't override $D.click Is it absolutelly necessary, that $D has all the other jQuery functionality? If not just hav the code you need in $D. Is it absolutelly necessary, that the functions have the name click() and hover()? Maybe you can simply add dclick() and dhover to jQuery. If both are necessary I'd still stick to Michaels question: Why? Sometimes there are other solutions to a problem that one doesn't see untill someone else hits ones nose to it. Tell us why you need it that way and we can think about alternative solutions. Christof
[jQuery] Re: How to clone jQuery object?
Hi, Is it absolutelly necessary, that $D has all the other jQuery functionality? If not just hav the code you need in $D. Not necessary, but I want to have them chained with jQuery object [...] Is it absolutelly necessary, that the functions have the name click() and hover()? Maybe you can simply add dclick() and dhover to jQuery. Yes, I want to override click [...] The idea was to replace $ ('foo').click() with $D('foo').click() whenever necessary to speed up the pages. Instead of changing your code from $('.foo').click() to $D('.foo').click() to $('.foo').dclick() doesn't seem to be much difference to me. Then jQuery chaining, etc. even feels like the original. I think, that dclick() and dhover() are the best solution for the problem you try to solve. Where is the problem with simply using your jQuery Version everywhere? When it is functionally equivalent but faster you might want to share your improvements with all of us. It was working fine, but I lost the code. svn and backups are your friends. SCNR. Christof
[jQuery] Re: jQuery for loop - am I crazy?
Hi, function initDashboard(){ $(document).ready(function(){ if($(.adminMsgSummary).length 0){ var theCount = $(.adminMsgSummary dl).length-1; for(z=1;z=theCount;z++){ var theDl = $(.adminMsgSummary dl); theDl[z].hide(fast); } } }); } Any ideas?? 1. You should not need $(document).ready in a function. 2. Use What jQuery can do for you ;-) selectors are really powerful function initDashboard() { $('.adminMsgSummary dl:not(:first)').hide(fast); } Christof
[jQuery] Re: deferring script loading
Hi, Thanks, it seems to have worked:-) I suppose it doesn't harm to set the time interval to a value greater than 10, right? Of course not. That just increases the time between the moment, jQuery is available and the moment your code is evaluated. It should still work of course. Christof
[jQuery] Re: dynamically loading javascript files (getScript() behavior)
Hi, Still, I've been using another approach that seems to work fine (at least) in FF and IE. Insted of getting the file and evaluating it, I just add a new SCRIPT element to the HEAD of the document with the specified URL. There are Safari Versions that don't load scripts that way. For nowI would not expectthat to be a big problem, because I guess Safari users tend to upgrade regularily. The main difference with this is that I can check if that script was already loaded (maybe by another component) and thus avoid loading it twice. Yes. There are more powerfull package management systems for JavaScript that can even handle dependencies between multiple packages without loading one package twice. See as an example jsPax.org. I am pretty sure that there is a good reason why to use eval instead of my approach, but I just wanted to know why. The reason is Safari. Christof
[jQuery] Re: jQuery.Plugin, first release.
Hi, 1- First of all, do you frequently use jspax for your jQuery plugins ? no one said this plugin is the first of its kind. Yes I do. I have recieved reports from developers that have poblems with jsPax and IE, but none of their testcases did show their problems for me. For my part I never have experienced any poblems with it - except for the time I was developing it, of course. 2- jspax requires you to organize it all in packages, and require them when the moment comes. It also requires to structure your code with callbacks. When you summon a package, you need to pass in a callback. I tried that some time ago, it's not that easy and makes the code kinda weird. Well, weirdness of code seems to be an emotional measure to some extend. Actually I find, that code that uses jsPax is very well stuctured. If you don't like the callback stuff, you can use JSAN that loads its packages synchronously. This plugin requires you to register for the plugins, the namespaces they take. You need to specify what functions it adds to $ and $.fn. So I as a plugin user need to know which functions a plugin adds? I haven't written that plugin. I only use part of its functionality. I whant to be able to replace it with a newer version which might add additional functions. I don't think that this is really a so great Idea. @Christof (cool name) :-) 2-The code can resolve dependencies, that's the option require which is an array of ids of plugins required, that is all explained in the project page. While I was developing jsPax I found out, that resolving dependencies can be quite tough. I have not read your code in full detail, but are you shure, you have checked all possible cases (like, e.g. two scripts loaded as a dependency for a third one both depend on the same fourth script, timing issues with such situations, etc.)? 3-It should work with all the browsers jQuery claims to fully support. No new technique is used here to load the packages, just jQuery. OK, I even load jQuery as a jsPax package. 4-The only thing you need for each plugin, is the list of functions/ namespaces it registers. Well, I may not really have them. I may only have a packed version of a plugin together with mediocre documentation. For no plugin I have seen so far that is an issue, but it might be in future. What still makes me feel bad is, that in your main script you need to write down all the function names all the plugins you use provide. In some cases it might be not much more code to stuff the packed plugin on top of your main script instead. In contrast to that with jsPax I only have to write down the package names in the main script file - no function names, etc. Of course that means, your really cool usage of simply calling the needed functions is not possible with plain jsPax. I could add a link to a list of pre made registrations, that I add as I get them reported by plugin owners or users. Then you have as many script tags in your head as you have without lazy loading: script src=jquery.js/script script src=pluginplugin.js/script script src=plugin1_registration.js/script script src=plugin2_registration.js/script script src=plugin3_registration.js/script script src=plugin4_registration.js/script ... script src=main.js/script That means, you have to know all dependencies of all plugins. 5-That's a very specific question, this is the first release, a draft you could say. I don't think this point has much importance. I could for instance check that. But the dev is the one registering, so it's not likely to happen. Maybe a plugin registeres another plugin that already is registered in the main script file. I do think that those things will happen. I understand, that you did take that issue out for the first beta release. For further releases you should take it into account. Christof
[jQuery] Re: jQuery.Plugin, first release.
Hi, Now, jQuery is not structured in packages, it's a core. You could consider the plugins as package, but there's no jQuery module to load them orderly (that I know of). That was one of the reasons I wrote jsPax. I chose not to use jQuery in jsPax, because I still have some applications that profit from jsPax but don't use jQuery. This might not be what you specifically need, doesn't mean it's useless. You are not the only possible user. Of course. I didn't mean anything as an offense. That doesn't keep me from thinking if I can imagine a usecase where your solution is better than existing ones. Actually there is something that is a lot cooler: the fact, that you simply call the plugin functions and don't have to care about that after registration. In such a case my approach would be to see first if an existing solution for something similar could be extended. Of course you can still come to the conclusion, that extending would have more drawbacks than doing it yourself - that's why I didn't use JSAN. I'm glad you have a good technique to load your jQuery plugins, I doubt everyone already has one. Of course everyone can use jsPax. Everyone can use JSAN, of course. Of course everyone can use your code as well - no problem with that. As for what you replied on plugin registration. I agree that the user doesn't need to know the namespaces. Maybe doing that DB of registrations is one possible solution. But every developer needs to manage his own database then. The URLs are different for every application. Thus the developer needs to change his database for every application. The dependencies system can handle nested dependencies, also 2 plugins requiring the same dependency while it's loading. It can surely fail in some cases, as I said, this is the first release, it was mostly as a proof of concept, to get some feedback. Some of your concerns I consider too specific. It is more that these are concerns I had to spend quite some thoughts to geht them fully solved in jsPax. Christof
[jQuery] Re: jQuery.Plugin, first release.
Hi, i have no idea whether this is feasible or not, i'm just a UI designer No, it isn't. The browser doesn't know what you mean by class=lazy. As soon as the browser reads a script tag it will begin to load the script, no matter what classname you gave it. There is no way to stop him. Christof
[jQuery] Re: jQuery.Plugin, first release.
Hi, First release of jQuery.Plugin, that's the name, it is used to lazy load plugins. The file is only fetched with the first call to the plugin. 1. Why not use existing and tested code like e.g. jsPax (jspax.org) or jsan? 2. Can your code resolve dependencies? 3. Does it work with Browsers that have strange Problems - e.g. there are some Safari Versions that don't evaluate script tags added via DOM after the page has been loaded? 4. Do the plugins need to support your plugin somehow - if not, you probably are not able to resolve dependencies? 5. What happens if a plugin with the same URL is registered twice with different names? Will it be requested twice - the browser cache should resolve that of course, but some browsers are realy bad at that? Reading through your example I came to the oppinion that the user of your plugin needs to write quite some code to get things done. Maybe I have misinterpreted your example, but as much as I can see a similar effect can be achived with a lot less code using e.g. jsPax. Christof
[jQuery] Re: jQuery.Plugin, first release.
Hi, what if you comment out your script tags ? i'm probably pulling hairs here. Then you don't have the script tags in the DOM. You would need to write your own parser then to parse the content of the coments - not a too simple task. Of course you also can not use the existing jQuery functions then, because your objects are not part of the DOM. You could think of leaving out the src tag and transport the url somhow else. e.g.: script class=lazy url:asdf/jkl/test.js/script But that is much less cool of course. Christof
[jQuery] Re: Loading dynamic JS libraries with jQuery
Hi, I'm trying to load JS files (libraries) dynamically at run-time with jQuery but I'm not being able to... I thought I had this working before but now it's not. Here's my code: Which Browser are you testing with? Generally there are two possibilities to load Scripts dynamically: 1. add a script tag via DOM - loads the script assynchronously. You won't know when it has been loaded and some Safari Versions don't execute the script. 2. load the Script with XMLHttpRequest and then eval() it - you can choose between synchonous an assynchronous loading. You can provide a callback that will get called after the script is loaded. This works with every Browser that has a XMLHttpRequest, but will only load scripts from the same Server. If you whant to have an Example how that could be done, have a look at jspax.org. Christof
[jQuery] Re: Debug Tools - Charles, DebugBar, Firebug Lite
Hi, What debug tools do you all use? [...] How about tools for IE? Is there anything you'd reccomend? alert() Christof
[jQuery] Re: Performance of jquery
Hi, IE7 Prototype: 2199 ms Mootools: 1546 ms jQuery: 1336 ms FF2 Prototype: 326 ms Mootools: 390 ms jQuery: 1092 ms SAFARI3 Prototype: 896 ms Mootools: 279 ms jQuery: 452 ms To complete the values: Konqueror Prototype: only Errors Mootools: only Errors jQuery: 699 ms With Firefox I have (for comparing the numbers): Prototype: 616 ms Mootools: 429 ms jQuery: 917 ms Firefox Performance seems to differ on different Platforms (I use Linux). I guess, the errors speak for themself. Christof
[jQuery] Re: uhhh.......WAT?
Hi, So, if I understand this, clicking on the jQuery link above should...uhh, pop an alert right? No. A click on any a-tag on your page will pop the alert. Christof
[jQuery] Re: uhhh.......WAT?
Hi, This ass/troll/clueless individual thanks you for making this group forum now begin to sound like every other developer's resource on the web: well-intentioned but ultimately crippled by the bratty missives of a few self-important detractors. I don't whant to sound like i'd support Roberts view on how to handle people new to jQuery, but you might whant to think about the language you chose. Maybe that language is one of the reasons why you seem to get that kind of answers from other mailinglists. Actually after I have read your original post I first decided not to answer at all. I have changed my mind after the following discussion has convince me that you are not a troll but are seriously trying to learn something about jQuery. Usually on this mailinglist we have a very constructive, friendly and polite communication. You can see that from the ansers you got. I hope, that in future you and Robert will be members of the jQuery community. You see, noone gets paied for answering your questions, so even if you are frustrated, hold your breath and ask as politely as you can. On the other hand, Robert, even if someone may sound rude here, better don't answer at all if your answer will be rude as well. Christof
[jQuery] Re: Enterprise Javascript?
Hi, after giving a cursory look at XUL here are some of the things AIR does that XUL doesn't: * Built in support for Flex/Flash (Layout/Logic + Fancy Animation/Video) Of course you can use any Firefox Plugin - including the flash Player, Quicktime, Adobe Reader, etc. IIRC there is even going to be an OpenOffice Plugin. * Many chrome options, XUL uses CSS for the chromes with mozilla extensions. What exactly is missing for you? in window animation, You can mix XUL, HTML and SVG and even MathML as you like. You can have a canvas tag and of course you have JavaScript. Which types of Animations are missing for you? Ah yes, of course you can use the Flash Plugin as well. incredibly fast rendering speed for windows, I have not had any XUL applications up to now where that would have been an issue. Can you tell me a use case, wher XUL is too slow, but AIR does the thing? support for native OS features, What native OS features are you missing from the Mozilla Platform? simple packaging scheme http://www.mozilla.org/projects/xpinstall/ is a good start for help with packaging XUL applications. I have not user it up to now, but AFAIK that is what Firefox and Thunderbird use. * Hundreds of desktop application hooks available for your Javascript XPConnect gives you access to all XPCom components of the Mozilla Platform. Of course that is not available for online XUL applications, but for Desktop Applications you can of course access everything using JavaScript. * Application signing for publishers At this point I have to admitt, that I have never needed to think about that up to now. At least I know that Firefox Extensions are signed so I guess that the Mozilla Platform does support it. * Industry backing: Adobe, AOL, eBay, Salesforce.com, Akamai, O'Reilly, Movable Type Are you shure, that the industry backing for the Mozilla platform is bad? From reading the news I don't get that impression. * Documentation: Adobe Integrated Runtime (AIR) for JavaScript Developers Pocket Guide The Mozilla Project is one of the best documented pieces of complex Software available. What exactly are you missing? * IDEs: Flex Builder, Aptana, Eclipse AIR Plugin Have a look at http://wiki.mozilla.org/XUL:IDE Christof
[jQuery] Re: ui slider plugin
Hi, Please ask on the dedicated jQuery UI list: Uh, not another mailinglist. I can not read all that. BTW. I have found a solution. The point was, that I had to use position:abslute for all elements. Seems like slider does expect that to work correctly. Another Problem someone else might run accross that I had was that for draggables the options containment and cursorAt don't work at the same time. I had quite a hard time to find that out since I had to digg into the draggable code. The good thing is that I have learned a lot about ui. Christof
[jQuery] ui slider plugin
Hi I am having problems with the UI slider plugin. I have this HTML structure (bulilt with DOM): div id=hue style=float: right; margin-top: 5px; background-image: url(img/hue.png); width: 18px; height: 186px; img id=hueSlider src=img/handle.gif style=left: 232px;/ /div Then I try to make a slider for the hue: $('#hue').slider({ minValue:0, maxValue:360, axis:'vertical', handle:'#hueSlider', startValue:360-h, start:function(){} }); It works fine, but the slider always begins at the top of the page instead of the top of the containig div (selectColor_hueSlider). How can I convince slider() to work correctly? Christof
[jQuery] Re: Enterprise Javascript?
Hi, Actually, if you'd like to use js to access a database, may I suggest Adobe AIR? Have I already expressed my dislike of AIR? Basically, in allows you to embed JS/HTML into an installable application, Wow, how new. Have you ever looked at XUL? Just create an installer that installs XULRunner and your XUL/XBL/HTML/JS/CSS-Application and you are done. I also remember to have seen simple Windows applications that only created a window, embedded the IE Engine and load a HTML page that has been copied to disk by the installer. Have you ever heared of .hta applications? They are a generic type of the above IE applications by only providing the HTML, images, scripts, etc. in an archive file. OK, the last two are not platform independant, but in many cases that is good enough. Use XULRunner otherwise. So what is so revolutionary new about AIR now that we have to hear all that fuzz? Is there anything that can not be done equally efficient with XULRunner? Christof
[jQuery] Re: Apply xpath-evaluate in an iframe document
Hi, // not working $(frameDocument).(//img).hide(); Try $('img',frameDocument).hide(); Christof
[jQuery] Re: Javascript best practices
Hi, More more plugins are using CSS to style the layout, this is good, but their didn't aware of if user browser don't know javascript, it is useless to load the CSS, e.g. thickbox script type=text/javascript src=path-to-file/thickbox.js/ script link rel=stylesheet href=path-to-file/thickbox.css type=text/ css media=screen / can be better: script type=text/javascript src=path-to-file/thickbox.js/ script script document.write('link rel=stylesheet href=path-to-file/ thickbox.css type=text/css media=screen /'); /script Most userse do have JS active. The overall overhead in bytes downloaded for thickbox.css where it is not needed is smaller than the overhead of bytes you introduce with your additional script tag for all users. In most cases it is better to load the unused stylesheet. Christof
[jQuery] Re: NEWS: jQuery 1.2 Released
Hi, The end result is probably a net enlargement of included JS, IMO. You can always include the convenience functions in your own code. Then you have no net enlargement of code. You even can leave out those you don't intend to use reducint the size of the whole js code. Of course you can say, that this speaks for using no JS library at all, because cou can always define all the functions you need in your own code. Well the reason for libraries is to safe work. Thus it is allways a ballance between including expectedly much used functions and excluding less used. More powerful functions are more likely to be used a lot than functions with only a single, very special use case. Based on that I very much appreciate the decissions of the dev team. That way leads to a library that is as powerfull as possible by staying as small as possible. There are still some whishes I'd have to make some functions more powerfull. specially those are text(), attr() and is(). There was a discussion about those functions: http://groups.google.com/group/jquery-en/browse_thread/thread/30e8d9ae2fc8b57e/d8cf031c88b1da64?rnum=1 I guess, the core developers did not have the time to join that discussion, though I'd appreciate their comments. Christof
[jQuery] Re: jQueryCamp '07 (Boston)
Hi, We're going to be having the first all-day jQuery mini-conference October 27th, here in Boston, MA. Hm. I'd like to come. I'll see if I can find the time and a cheap plane. Does the US still treat travellers from outside like criminals (taking fingerprints, etc.)? Christof
[jQuery] Re: Loading remote JavaScript
Hi, Is there an easy way to get a remote script and run code when it has loaded as well as check the content type? $.getScript only works with those scripts on the same server. You can use $('script src=http://example.com/myscript.js; type=text/javascript'). appendTo('head'); It should work in most cases, but there are Safari Versions which don't interpret scripts loaded that way. Christof
[jQuery] Re: Loading remote JavaScript
Hi, I'm aware of that method, but I want a callback to find out what content type was loaded, display it if text/html or execute it if text/ javascript. $('script src=http://example.com/myscript.js; type=text/javascript'). appendTo('head'); $('script type=text/javascriptcallMyCallback/script'). appendTo('head'); Since the second tag will be inserted after the first, it will be executed after the first script is loaded and executed. Well, you don't get the content Type, but you can check for the existance of variables or functions that should be in the script. That at least tells you if the script has been loaded successfully as javascript. Christof
[jQuery] Re: Exec'ing JS In load()ed content for IE
Hi, Posting things multiple times doesn't raise the probability to get a useful answer. Christof
[jQuery] Re: Jquery Vs. Prototype
Am Dienstag, 7. August 2007 schrieb Klaus Hartl: Joel Birch wrote: On 07/08/2007, at 5:35 PM, Mika Tuupola wrote: say-ferry = American say-kweery = UK gee-kooery = Finnish Rally Driver jah-ee-kweery = Australian jä-kwärrie = german ;-) ha? = bavarian ;-) Christof
[jQuery] Re: Jquery Vs. Prototype
Hi, I'll put it this way: I've been using JavaScript for quite some time - begining with a small game in 1997. I've looked at a lot of libraries over the time and always thought: take out the stuff I don't need and I get the rest much smaller than this stuff. jQuery was the first time this was different. That is mostly due to some simple reasons: 1. Very poverfull philisophy. There simply isn't much I'd take out for any a bit more sophisticated application - the less sophisticated are usually better off with using no library at all. 2. Good code. I don't think I could get it much smaller - at least the compressed version of course. I don't know how prototype has developed since I had looked at it, but jQuery had good code earlier. 3. Small core and efficient plugin API. I can simply stick together whatever Plugin collection I need and use that. The overhead of unused functions is very small in most cases. All in all I'd invest more time to get the same benefits myself than i have invested in learning the jQuery API. Christof
[jQuery] Re: Coder vs Designer?
Hi, In my present job we don't have a designer, so us coders are the designer. I don't mind but I'd still like to keep the two separated as much as possible. Our Designer gives me (the developer) what he has produced with GoLive and a text describing, how things should interact. If something is not clear I simply ask him. What are others doing to make sure that even small snippets of HTML aren't creeping into their js files? Idon't write them. I prefer to use a DOM Builder to create new Elements. $('#courseHist').append('divspan class=headingCourse Title/spanspan class=content' + crs.title + '/span/div'); $('#courseHist').append($.dom('div',{},[ ['span',{'class':'heading'},['Course Title']], ['span',{'class':'content'},[crs.title]] ])); Usually that is OK, because our designer uses a lot of CSS and is happy with code like this most of the time. If that is not acceptable, I use load() for a hidden part of the page at first use and then clone it as often as I need: function insertCourseHistory(hist) { var tmpl = $('#courseHistTemplate'); var tmplc = $('*',tmpl); if( tmplc.lengt == 0 ) { tmpl.load('histTemplate.htmlf',{},function() { insertCourseTitles(hist); }); } else { $('#courseHist').append(tmplc).find('.content').each(function(i) { $(this).html(hist[i].title); }); } } The html fragment file 'histTemplate.htmlf': div span class=headingCourse Title/span span class=content/span /div If the page is not public I even spare the single load and put the template on the page directly. Then the JS code is really simple: $('#courseHist').append('#courseHistTemplate *'). find('.content').each(function(i) { $(this).html(hist[i].title); }); On public pages you might get punished by Google for having hidden content on your page so I prefer to use external html fragments. Christof
[jQuery] Re: Coder vs Designer?
Hi, I'm sorry Christof, didn't mean to offend you. Just saw the code and couldn't hold back... No problem. I took your response as a challange, not an offense ;-) Christof
[jQuery] Re: Coder vs Designer?
Hi, I spot a typical case of classitis here. I just used Matts original here. Why not getting a little more semantic and use a real heading instead of the least semantic element with a class heading: div h2Course Title/h2 p.../p /div Less bloated, less to transfer... How about dtCourse Title/dt dd.../dd And then in the original code have dl id=courseHist/dl Even less bloated, less to transfer, more expressive and my suggested code should still work (as it does with your suggestion). Christof
[jQuery] Re: Good Javascript editor or IDE?
Hi, What recommendations on JavaScript editors or IDEs does anyone have? gvim, or emacs whichever fits your needs more ;-) Just to have brought up two alternatives to those IDEs packed with special features for everything and everyone but don't adapt to your speciffic needs. Is there something sophisticated enough that can have intellisense with jQuery or my own objects in external js files? I the ability to extend your editor yourself with touring-complete languages is sophisticated enough for you, the two above are for you. Christof
[jQuery] Re: OT: A Big Idea
Hi, I wanted to comment your blogpost, but could not register. Anyway. http://commadot.com/?p=581 I would love your thoughts on it. I don't understand, why people think that this idea is so great, but i'm not 100% shure if I have really understood it. Do you whant to use a HTML rendering engine inside flash or do you whant to use a HTML rendering plugin? I case you whant to use a HTML renderer in flash. Why? You can use flash for any rendering stuff if you need exact virusal reproduction. What do you gain when you give HTML to the flash film? In case you'd like a HTML plugin. Why? People won't install it, because basically their browser does HTML rendering for them. And they don't care about standards, otherwise noone would ever have used Netscape 2 or Internet Explorer 6. I understand you whant a single rendering engine to make shure that your HTML/CSS code always looks the same. I don't. 1. The web has never been designed to give you exactly the same results everywhere. It has been designed to give the user the best possible access to the information independent from his eventual disabilities. Use the tool as it is and don't complain that your hammer is not a saw. 2. If you still need exact visual reproduction of something, there is always flash. You can not have accessability and exact visual reproduction at the same time as much as you never can exactly measure position and momentum at the same time. 3. We have had a browser engine to rule them all, IE, but noone ever liked it. You just change the dictator but stay in domination. Having multiple browser engines gives the users back their freedom of choice. For web developers an designers it sometimes is a pita, but in the whole it is better to have a pita for some and freedom or all. Christof
[jQuery] Re: AW: [jQuery] Re: OT: A Big Idea
Hi, 1. The web has never been designed to give you exactly the same results everywhere. It has been designed to give the user the best possible access to the information independent from his eventual disabilities. Use the tool as it is and don't complain that your hammer is not a saw. I'm pretty sure the web in a couple years whould be the same but the tools will drasticly change. Take a look and see what's going on right now. The web is the tool I am talking about. It is a tool for publishing. Another tool for publishing is e.g. a newspaper - each with their benefits and drawbacks. 2. If you still need exact visual reproduction of something, there is always flash. You can not have accessability and exact visual reproduction at the same time as much as you never can exactly measure position and momentum at the same time. That's the idea behind it. They like to change this in the future. Isn't that a good idea? How could that be? How can you have exact visual representation for visualy handicaped persons? They need to use a huge font in order to be able to decipher anything. How can you have exact visual representation with an aural reader? Also think of reproduction on paper, a braile reader, etc. It is simply not possible. The web was (not perfectly, but basically) designed to be able to have the information available on every possible output. It is just eventually able to give you some controll over the visual presentation. That is nice and we should use it, but we should never depend on it. You can try to exactly measure position and momentum at the same time, but you will fail. You can also try to catch free energy travel faster than light, but you will fail. You can try to have exact visual presentation in an accessible way, but you will fail. 3. We have had a browser engine to rule them all, IE, but noone ever liked it. You just change the dictator but stay in domination. Having multiple browser engines gives the users back their freedom of choice. For web developers an designers it sometimes is a pita, but in the whole it is better to have a pita for some and freedom or all. I guess the idea behind the concept is to get a way to use a specific rendering engine in different browsers. This means the software we speak about is a piece of midleware which runs in a browser of the users choice and is able to render the visited page with the engine the developer decides to use. That means, the User needs to have a number of engines installed and run them in a shell which he calls browser and the developer decides which of the engines to use for the current page. Great. I need to install IE on Linux then, because there will be quite a number of pages that demand IE as their rendering engine. I also don't gain freedom of choice then. I can not choose to not install a specific engine and still use all Webpages. Nowadays I can install one or if I like fourtytwo (OK, we count varoius versions as well...) rendering engines and use (almost) all Webpages whith whatever engine I trust. There are also rendering engines that still have severe security problems. Even if I have one of them installed for testing reasons I don't whant the developer of a Website (who eventually is evil) to chose that engine for his Webpage whithout me beeing able to prevent it. This would make the develeopers choose the rendering engine and the user the browser. Isn't that freedom? No, sorry. The developer of a webpage should never be able to chose which software executes on the clients side, except inside the sandbox, the user may allow him, because if he is evil he will chose the choice that is the worst for the user from a security point of view. The user should not give the developer of any website controll over his machine. This yould make us much more independent from the browser companies and give us the prower we need. Only two of the major browser engines are developed by a single company each. That is IEs engine and Operas. Webkit is currently beeing returned to the kHTML team, kHTML is a comunity project and Gecko as well. I guess, I have all the major engines now. We do not depend on any company when it comes to browser engines, we as developers only depend on the users and which browser they install. Christof
[jQuery] Re: AW: [jQuery] Re: OT: A Big Idea
Hi, 1. Allow the publisher to determine which rendering engine to display the page in. Exactly this is what I don't whant to see and I do think that I have good reasons. Think about sIFR. It works because it's unobtrusive and relies on a plugin that everyone has. Well, most people. How does the flash player work for aural platforms? How good ist in on a Braille display? Its surprising to me how immediately everyone is saying, bad idea. Is sIFR a bad idea? Interesting how perception varies. I have had the impression that everybody but me likes this idea ;-) Christof
[jQuery] Re: AW: [jQuery] Re: OT: A Big Idea
Hi, sIFR does not break aural readers at all. It takes normal HTML and it pushes it into a flash movie (if flash is there) and shows it with the flash font. So we can not count on an exact visual representation - only if flash player is installed. What do we gain then? Is the flash player our new dictator then? The King IE is dead, long live the King Flash! OK, this was polemic, but I hope that you can see, what I mean. The problem sifr tries to solve - display specific fonts on the client if that is possible somehow - is different from the problem you try to solve. Your problem is the fact, that different browsers have different interpretations of the standard documents and some even actively ignore the standards. You try to solve that by defining one rendering engine that is the rendering engine for your page. I whant to read your page, but I can't or don't whant to use that specific rendering engine. Ask users to switch to a standard compliant browser and use standards wherever possible, but don't force them. I think you are assuming that anything at all would break. I am assuming, nothing would break. Then what is it all about. If you whant to make shure that your page looks good in all situations you still have to test with all browsers without flash. You even have to test with flash player now, to be shure. Either you break something or you gain nothing. Christof
[jQuery] Re: named function vs anonymous functions
Hi, If you want to call a method of a CLASS then yes it will work because 'this' is then no longer tied to a specific OBJECT. Yes, it is. It is tied to the class object, which is the constructor function object in JavaScript: function myWonderfullClass() { this.countme = ++myWonderfullClass.countme; } myWonderfullClass.countme = myWonderfulClass.prototype.countme = 0 myWonderfulClass.alertCount = myWonderfulClass.prototype.alertCount = function() { window.alert(this.countme); }; function callMyFunction(f) { f(); } // this will alert '0' myWonderfullClass.alertCount(); myObject = new myWonderfullClass(); // this will alert '1' myWonderfullClass.alertCount(); // this will alert '1' myObject.alertCount(); // this will alert '', or 'undefined' 'callMyFunction(myWonderfulClass.alertCount); // this will alert '', or 'undefined' 'callMyFunction(myObject.alertCount); this.countme = 42; // this will alert '42' 'callMyFunction(myWonderfulClass.alertCount); // this will alert '42' 'callMyFunction(myObject.alertCount); Christof
[jQuery] Re: [Off-Topic] CSS Combine Images
Hi, I have been using this technique for some time now and always searched for a tool that would help me combine those images easily, but never succeeded. That is why I decided to build my own :) Have you had a look at ImageMagick? The ImageMagick tool montage should do what you need. I guess you could also profit from writing a GIMP script foo if ImageMagick is not an alternative for you. I don't whant to neglect your efforts, just give you some tips how to overcome your current restrictions almost for free. I guess you would have a hard time to find an image format usable for the web that is not supported by GIMP, extending the script to multiple rows is very simple and you have any scaling and extending functions you might whant to have for images with different sizes. Christof
[jQuery] Re: [Off-Topic] CSS Combine Images
Hi, I have done this in php with gd and ImageMagick in the past, but this a desktop application that will allow more finegrained control of the combined output image and the source handling in the future. montage is a CLI tool with fairly finegrained control of the combined output ;-) However I just whanted to add some thoughts. Have you thought of using Qt for the GUI? Qt also gives you some image manipulation functions and can handle various formats as well. Btw you win a cross platform desktop application for Windows, MacOS X and various X11 based platforms like e.g. Linux, Solaris or the BSDs. Qt itself is a C++ library, but there are bindings to many other languages as well, like e.g. Python, Perl, Java, etc. Sure there are many options to do it, I even created a photoshop action to do it, but none of these are really doing the trick for me. Just sharing :) ScriptFoo goes further than photoshop actions. Actually you get a touring complete language to manipulate even every single pixel of some set of images if you like. You can do the UI with GTK then. AFAIK photoshop actions are not really much more than a recoded pattern of appling existing Photoshop tools. Actually I was wandering why the available image formats should be an issue. That is why I guess you have not been able to find the best tools for that. In my experience most image formats are no issue for desktop applications nowadays. Even if none of the easy ways like integrating into Gimp or using Qt is an option for you, you can always call e.g. the netpbm tools to read any input or generate any output format you like. Christof
[jQuery] Re: named function vs anonymous functions
Hi, I currently have: $(this).change(function(){ //my function code here });//end change fn I decided to move the function outside this block since I might want to use it at another time besides a change event so my function is now myfunction = function(){ //my function code here } so what is the proper syntax for calling this named function for that change event? $(this).change(myfunction); Christof
[jQuery] Re: named function vs anonymous functions
Hi, $(this).change(myfunction); To expand on that a small bit: if you want to call a method of an object then you must create an anonymous function to do it for you: $(this).change( function(){ myobject.myFunc() } ); I was of the impression that $(this).change(myObject.myFunc); would work... No, that would only give the function object myObject.myFunc to change(), which has no relation to myObject. The this variable is set at the time a function is called. That means, that when change() whants to call myObject.myFunc the propper object for this is not available. Christof
[jQuery] Re: OT: js file obfuscation
Hi, Any recommendations for a (preferably free/opensource) js obfuscator that you've used and liked? I'm looking for something to take what packer does to the next step: at minimum, obscure methods names, but preferably scramble the dickens out of the file to reduce the likelihood of reverse-engineering. Dean Edwards Packer (http://dean.edwards.name/packer/) jSquash (http://sourceforge.net/projects/jsquash) is alpha status and we have not updatet it for quite a while. Normaly I get working results. Christof
[jQuery] Re: Possible to retrieve image data via AJAX for display?
Am Mittwoch, 25. Juli 2007 schrieb Rob Desbois: Yes, sorry I didn't phrase my post very well: there is a URL for the image, of course, but I was trying to emphasise that there isn't a URL to an image cached on the server's filesystem to pass back, as I don't want to *permanently* cache the image (or implement a cleverer algorithm - there's no need). I simply want the cached image (or intermediates) to be temporary; the user's session seems the obvious candidate for this type of storage to me. var ctx = $('canvas')[0].getContext(2d); var img = new Image(); img.onload = function() { ctx.drawImage(img,0,0); ctx.beginPath(); ctx.moveTo(30,96); ctx.lineTo(70,66); ctx.lineTo(103,76); ctx.lineTo(170,15); ctx.stroke(); // ... } img.src = /basicImage.png; I am pretty shure that this is what you are looking for. I have the code almost exactly from the first example of http://developer.mozilla.org/en/docs/Canvas_tutorial:Using_images The example should work in Firefox, Safari and Opera. For IE there is IECanvas (http://sourceforge.net/projects/iecanvas). If you really need to care about Konqueror, you can try to mimic the behaviour you need with data URLs. For a refference how this could look like, see PNGlets: http://www.elf.org/pnglets/ There is no really usefull Drawing solution on all Browsers. Changing data URLs lie PNGlet is slow and annoying and IECanvas is slow and can not handle many drawing primitives - it gets slower all the time. There was the possibility in IE 6 to use javascript URLs for images that return monochrome XBM images which could have been colored and combined with filters. Alas MS doesn't support XBM any more, so there is not evan a pita-way left. Christof
[jQuery] Re: Possible to retrieve image data via AJAX for display?
Hi, Thanks for that, but I was really looking to see if there was a browser-independent mechanism, No, there isn't. Canvas and IECanvas is the closest you can get. I have done quite some research on that matter for a project where I really could have profited from canvas, but IECanvas was much too slow. You might also spend a thought on Java Applets - at least they work mostly browser-independent. essentially something like the Web archives that IE has supported for years. I never noticed that they ever were browser-independent. Christof
[jQuery] Re: Possible to retrieve image data via AJAX for display?
Hi, I believe the ctx variable should be: var ctx = $('canvas')[0].getContext(2d); I was expecting that a canvas tag exists on the page. If it doesn't it should better be something like this: var ctx = $('canvas').appendto('body')[0].getContext(2d); Christof
[jQuery] Re: Possible to retrieve image data via AJAX for display?
Hi, I have a server-side script which generates a graph image given a set of dataset identifiers. Additional datasets are implicitly added server-side too. Currently the image contains the legend, but I'd like to generate the legend in HTML as it'll be more consistent with legends used for tables. The legend contents cannot be determined until partway through graph generation - so I'd like to retrieve both raw image data and legend data via AJAX, build the legend's HTML representation and display the image. I guess you are lokking for something like canvas. Firefox and Safari do support it. I am not shure about Opera, but IE and Konqueror don't. For IE there is at least IECanvas (http://sourceforge.net/projects/iecanvas), which might be of use. You can use JavaScript to put an Image on a canvas and you also have drawing primitives to add Information. Christof
[jQuery] Re: Loading Javascript Dynamically (in other words, as needed)
Hi, I was wondering if jQuery can be used to load javascript dynamically, on an as-needed basis. Here is the problem I have: I want to load a page with as little javascript as possible. jspax.org You don't even need to have jQuery loaded before. I do user jQuery as a jsPax Package. In the last fiew months I have recieved two reports that peolpe had problems with jsPax and IE. I do trust both of them because they definatelly are no idiots, but I have not been able to reproduce that problem up to now. When someone clicks on an item that requires some javascript functionality, I want it to load a javascript function from an external file and then execute it. Yes, with jsPax: $using('jQuery',function() { $(function() { $('.clickableElements').bind(click,function() { var self = this; $using('my.wonderful.package', function() { my.wonderful.package.handleClickOn(self); }); }); }); }); What a cascade of functions :-) While there is some simple javascript I've found that can do this kind of thing by appending the script to the DOM, it can't do things in order. Those scripts do not work in some safari versions. If you whant your script to work there as well, you need to load it via XMLHttpRequest and execue it with exec(). Also adding a script tag loads the script assynchonously and does not give you information on when it has finished. jsPax uses XMLHttpRequest whenever it is available and calls your callback on success. Otherwies it adds two script tags. One with the script set as src and the second one with a script text inside that calls a special callback function. This callback function indirectly is a call your callback that you have given to the $using() function - just changing the context. The browser can not execute the second script before it has executed the first one. I don't like the idea of doing a time-out loop, so I was wondering if jQuery has something built in for this kind of thing. if you do have jQuery loaded, then it is fairly easy to mimic the behaviour of jsPax: $(function() { var clickScriptAvilable = false; $('.clickableElements').bind(click,function() { var self = this; if( clickScriptAvilable ) my.wonderful.package.handleClickOn(self); else $.getScript('my.my/wonderful/package.js', funciton() { clickScriptAvilable = true; my.wonderful.package.handleClickOn(self); }); }); }); IIRC getScript() always uses XMLHttpRequest without a fallback to inserting script tags. That is usually OK, because you usually don't take browsers into account that don't even have a XMLHttpRequest when you use jQuery. Actually in my daily work I don't take these into account as well, but I whanted jsPax to be able to even handle those. Christof
[jQuery] Re: Syntactic sugar for checking whether an element exists
Hi, I'd like: $('.whatever').text(); // = [foo, bar, baz] $('.whatever').text(','); // = foo,bar,baz But at the moment $('.whatever').text(','); would set the text in all elements to ','. I don't think we should change that behaviour because it is the more complicated to simulate: $('.whatever').text().join(','); vs $('.whatever').each(function() { this.innerHtml = ','; }); Christof
[jQuery] Re: Syntactic sugar for checking whether an element exists
Hi, I did do so, but I think it doesn't help to have functions which have semantically irritating names. If a function is called exists(), that indicates, that the function is operating on one or no element, not a collection (the same problem as with is()). Oh I'm not saying exists() is the best possible name. I like it, yes, but if you have better ideas please share ; ). As I said what you whant should be called isNotEmpty(). Then it is not less intuitive to type length!=0 I think. I very much agree with you here. All of the property accessing functions behave very unpredictable when used on a collection of items. You explained what attr() currently does. text() is even more confusing as it returns a string with the text of all matched elements combined. Yes, still I have to say, that jQuery is one of the most consistent libraries I have seen. So these critical remarks are more about how to make it even better. I also think that text() is problematic as well. It should better return an Array of strings. If I need what text currently does I can do $('.whatever').text().join(''). I even could do $('.whatever').text().join(' - oh my god - '), which is not possible with the current text() implementation. How about $('.whatever').text().sort(...), or whatever. Having those functions return an array would be great, but I can see it causing problems with existing code. Yes of course. I don't think that these things should be in a 1.1 release, but maybe for the 1.2 release, when compatibility may be broken anyway I'd apprechiate that. But returning the value directly if only one item was matched should fix most of that. I don't like that. $('.myClass').text()[0] would then fail if there is only one Element with that class. Now that of course would also cry for a way to enforce the array returning behavior consistently (even if just one element is matched). I'd suggest the following for that: $.array = function(a){return a.constructor == Array ? a : [a];} $('a').attr('href') // Returns the href if only one element is matched or an array of hrefs if several elements exist $.array($('a').attr('href')) // Always returns an array of hrefs, even if just one element matches the selector But that would make the desirable behaviour the more complicated to achieve. I think that breaking compatibility with a new release is acceptable at least for a major release - that would be release 2.0 then. When that is acceptable, it is the better way. As we have seen all the current behaviours we have come up with can be simulated very easy with [0], .join('') or a function like I have suggeested for has(). So updating existing code to the new behaviour would not be a too complicated task. Would be nice to hear some of the devs comment on this, Yes, that is true. but I guess we are on the wrong list with this discussion as there also is a dev list I think. I have seen them writing here as well. I don't know if they currently can take their time to read our discussion. Christof
[jQuery] Re: Interested in porting another DOM creation plugin?
Hi, This looks really interesting: http://www.zachleat.com/web/2007/07/07/domdom-easy-dom-element-creation/ Of course his proposal for porting doesn't quite work out with jQuery, but a port that is integrated into jQuery's API would be really cool. A nice Idea, but somehow I feel uncomfortable with it. I've been using Oslows DOM builder which uses arrays and objects to express the desired DOM up to now and somehow I prefere it, because it doesn't need to parse any strings before it starts building Objects. Actually a mixture of both would be cool: $.dom([ 'a', {href:'asdf'}, ['asdfasdf'] ]); creates like Oslows code a href=asdfasdfasdf/a while $.dom([ 'a#jkl[href=asdf]', ['asdfasdf'] ]); creates a id=jkl href=asdfasdfasdf/a and $.dom([ 'div.test a#jkl[href=asdf] + a[href=asdf], p', [ 'span.lkj', ['asdfasdf'] ] ]); creates div class=test a id=jkl href=asdfspan class=lkjasdfasdf/span/a a href=asdfspan class=lkjasdfasdf/span/a /div pspan class=lkjasdfasdf/span/p Of course $.dom() always should return jQuery Objects. What do you think? I think it will be a really efficient way to create even a rather complex DOM tree. $.dom([ 'table[width=100%][border=2][cellpadding=0] tr + tr +tr +tr', [ 'td[style=background-color:red],td', ['asdfasdf'] ] ]); table width=100% border=2 cellpadding=0 trtd style=background-color:redasdfasdf/tdtdasdfasdf/td/tr trtd style=background-color:redasdfasdf/tdtdasdfasdf/td/tr trtd style=background-color:redasdfasdf/tdtdasdfasdf/td/tr trtd style=background-color:redasdfasdf/tdtdasdfasdf/td/tr /table Christof
[jQuery] Re: Syntactic sugar for checking whether an element exists
Hi, Why? For me the sweetest thing about using jQuery has been it's intuitiveness right out of the box. When I started I just looked at some initial code samples (fancy API pages weren't around back then or I didn't know about them) and then was virtually able to 'guess' the jQuery functions I needed. I usually have looked into the jQUery code when I needed some functionality before the docs have become really good now. So now I just need to check whether this element exists. Hm - exists() produces a fatal error. Let me search the docs: The question if this element exists does not arise when you remember that a jQuery object is a collection of elements. What should exists() return when there are five elements in the collection. I know, you whant to have it return true then, but that means it should not be called exists(), but isNotEmpty(). With that function name you immediatelly will say, what do I need a function call, if .lentgh!=0 gives me the same result faster with even less typing and equally intuitive. Now that is in my view one of the very strong parts of jQuery. There is not too much fuzz. You usually get what you need in a fast and straight forward way. If only more notable libraries in other languages where that efficient. Same goes for hasClass() I think. dito. div class=myClass.../div div class=myOtherClass.../div $('div').hasClass('myClass'); What should this return now? BTW: I don't really like the function name of is(). I'd more prefer has(), because that makes clear, that you whant to know if one of the elements in the collection fits to the expression. Christof
[jQuery] Re: Syntactic sugar for checking whether an element exists
Hi, However, as you said this library is more then just code, it's art. And this is why I'm emphasizing those new functions: They empower the artist Perfection is achieved, not when there is nothing more to add, but when there is nothing left to take away. (Antoine de Saint-Exupéry) Don't try to add paint to the Mona Lisa ;-) Christof
[jQuery] Re: Syntactic sugar for checking whether an element exists
Hi, var element; if ( (element=$('#someID')[0]) ) { /* element exists */ } else { /* damn... */ } I'd prefer var e if( (e=$('#someID')).length ) { // element Exists } else { // element does not exist } Usually you whant to know if an Element exists to create it otherwise, so I often have code like this: if( ! (e=$('#someID').length) ) e = $('p id=someIDasdf/p').appendto('#myParent'); e.hide(); Christof
[jQuery] Re: Syntactic sugar for checking whether an element exists
Hi, if( ! (e=$('#someID').length) ) e = $('p id=someIDasdf/p').appendto('#myParent'); e.hide(); Oops. if( ! (e=$('#someID')).length ) e = $('p id=someIDasdf/p').appendto('#myParent'); e.hide(); Just close the parentheses where they should be closed :-) Christof
[jQuery] Re: Syntactic sugar for checking whether an element exists
Hi, Christof: I appreciate your comments. Even more however I would have appreciated if you'd have taken into consideration why I made the proposal. I did do so, but I think it doesn't help to have functions which have semantically irritating names. If a function is called exists(), that indicates, that the function is operating on one or no element, not a collection (the same problem as with is()). That will make the way to learn jQuery even harder because people don't understand what they are working with. If you are working with a saw, then break() is a senseless operation even when it is often successfully used on flintstones. If people expect the saw to be used like a flintstone, they will fail, even if the saw has an operation break() that tries to guess what a flintstone user is trying to do. It is better to educate flintstone users how to use a saw and what can be done with it. I just think that jQuery has gained a lot of it's popularity due to it's easy-to-learn factor (besides it's superiority and beauty that is : ) and think this could be a good addition to it. Well, I have not started using jQuery because it is easy to learn, but because it solved some problems for me. I quickly learned that my code can be more elegand and slim when I invested my time to find the best ways of using jQuery. div class=myClass.../div div class=myOtherClass.../div $('div').hasClass('myClass'); What should this return now? It should return true. That's because $('a').attr('href') returns the 'href' attribute of the first anchor matched (afaik). Well, is() returns if there is one element in the collection that fits to the selector. As we see, the semantics is unclear here. I am not really happy with functions like attr() as well. They could also return an array with all values of this attribute in the collection. Then $('a').attr('href')[0] would be the same as the current attr() function. Another thing I dislike about attr() is that attr('name','value') operates on all Elements of the collection while attr('name') doesn't. I think that is irritating. To make that complete I also think, that is() should better return an array of boolean values that indicate for every element in the jQuery object if it fits to the selector. If only one of then is sufficient, then I'd call that function e.g. has(): $.fn.has = function(s) { var r = false; $.each(this.is(s),function(i,n) { r |= n; }); return r; }; Christof
[jQuery] Re: Attn. developers. Speed of getElementById
hI, String comparison has to compare each char at each position. abc=abc would involve 3 iterations. digitalbush.com=digitalbush.com would involve 15 iterations. That is only really relevant if you really need to do all the comparisons. I guess that browsers do a linear search trough the list of IDs. That is a complexity of O(m*n) for m beeing the length of the id and n the number of IDs. Then the length of the ID is important as you did describe it. If they only would sort the ID list before and use a binary search that would go down to O(m*log(n)), which means that both m and n get a lot less important for the overall runtime of the algorithm. They could improve even this by hashing an rehashing. That helps to increase the base of the logarithm compared to the base 2 for the binary search. There is a lot of work available about how big datasets can be handled and these algorithms work really fast on Datasets you will never find as IDs in a HTML Page - e.g. Datbases with millions of entries. Caching results sounds like a workaround for jQuery, but actually the problem is on the side of the browser vendors. I think that caching brings so many problems like knowing when to clear the cache, that I guess that the effort to get it right is better invested in pushing the browser vendors. Maybe implement better algorithms in free engines like Gecko and Konqueror and make some publicity about it. Christof
[jQuery] Re: Javascript: OOP help, accessing parent objects
Hi, Thanks, that's really great, I'll have to really play around with that when I've got the time to really get to grips with it. Can you do multiple inheritence with that trick? That is not a trick, but a usuall JavaScript idiom. You can simulate multiple inheritance as well, but then you need to copy all the Elements from the second parent to your derived class. I think you should not try to only simulate classes with prototypes, but take your time to understand how prototypes work and what they bring to you. They can be used to simulate a class based approach as well, but they are not perfect at it. On the other hand they can bring you other features that you don't have with classed based object orientation. Christof
[jQuery] Re: Javascript: OOP help, accessing parent objects
Hi, function Contained () { var self=this; self.var1=1; self.var2=2; self.method1=function () { }; } function Container () { var self=this; self.varA = 'a'; self.varB = 'b'; self.containedObj = new Contained; } var foo = new Container; Now suppose I want to access variables of Container from within Contained, for example I might want method1 to return the value of varA in Container. How would I go about doing this? As in all OO-Languages you don't. Examples in other languages: Java class Conainted { public int var1; public int var2; public Contained() { var1 = 1; var2 = 2; } public void method1() {...} } class Container { public String varA; public String varB; public Container() { varA = 'a'; varB = 'b'; } public Contained containedObj; } (new Container()).containedObj.method1(); //How could method1 ever access varA? C++ class Contained { public: int var1, var2 Contained(); void method1(); }; class Container { public: std::string varA; std::string varB; Container(); Contained containedObj; }; Contained::Contained(): var1(1), var2(2) {}; void Contained::method1() {...} Container::Container(): varA(a), varB(B) {}; (new Container()).containedObj.method1(); //How could method1 ever access varA? You may give the container as a parameter to method1: Java: class Conainted { ... public void method1(Container c) { System.out.println(c.varA); ... } } C++: class Contained { public: ... void method1(Container* c); }; void Contained::method1(Container* c) { cout c-varA endl; ... } JavaScript: function Contained () { this.var1=1; this.var2=2; this.method1=function (c) { alert(c.varA); }; } Christof
[jQuery] Re: Javascript: OOP help, accessing parent objects
Hi, C++ ... (new Container()).containedObj.method1(); //How could method1 ever access varA? OOps, this shopuld of course read (new Container())-containedObj.method1(); Christof
[jQuery] Re: Javascript: OOP help, accessing parent objects
Hi, Okay, thanks for the help. I was just trying to figure out how to do inheritence in javascript and instead embedded objects inside other objects. :) Ah, what you are looking for is this: function super() { /*...*/ }; super.prototype = { varA: 'a', varB: 'b' } function sub() { /*...*/ }; sub.prototype = new super(); // this is equivalent to inheritance // we can not simply assign an object to prototype now, because that would // overwrite the existing prototype. Use jQuery.extend(sub.prototype,{...}); // wherever you have jQuery available. sub.prototype['var1'] = 1; sub.prototype['var2'] = 2; sub.prototype['method1'] = function() { alert(this.varA); // yes, now we have this.varA }; (new sub()).method1(); // will alert 'a'. Christof
[jQuery] Re: TreeView with Checkbox Tree
Hi, I am looking for this: http://www.blueshoes.org/_bsJavascript/components/tree/examples/example3.ht ml I want insert Checkbox in my treeview. Is it possible with JQuery? I guess Jörns Treeview Plugin will do the trik for you. Just add the checkboxes to the li-Tag. http://bassistance.de/jquery-plugins/jquery-plugin-treeview/ Christof
[jQuery] Re: jquery editor?
Hi, This may be slightly off-topic, yet i would like to know which piece of software you like best to write jquery code? I prefer gvim. I don't have a specific jquery-Syntax file, because I did not have a need for it, but it would be no problem to write one. The downside is that vanilla gvim lacks many features that you might be used to. You can get most of them by writing gvim scripts, but that is not for everybody. If you are interested, have a look at http://www.vim.org/scripts/script_search_results.php to see what peoble already have done with gvim. Christof
[jQuery] Re: security advice
Hi, i think what i really was after, was a small 'framework' that does the thing for me. i can include it everywhere i need/want and check a isLoggedIn or sth like that. There can't be a framework that takes the burdon of secure programming from the programmer. There are features of your programming language that keep you from thinking of some security issues - there are no buffer overflows in PHP programms, e.g. - but they can not keep everything from you, because that would make PHP so restricted that noone would ever use it for serious programming. Christof
[jQuery] Re: security advice
Hi, Wow, what is this. I have not inserted the '' in front of the line that starts with from thinking. It is not in the copy of the message in my sent-folder. It must have beed added somewhere else. Christof
[jQuery] Re: Dynamically loading javascipt .js files?
Hi, Is there a way for jQuery to dynamically load an external js file? You might like to have a look at jspax.org. Christof
[jQuery] Re: WYMeditor hiccups
Hi, However, $j is defined globally throughout jquery.wymeditor.js, as: var $j = jQuery.noConflict(); I have not looked at your code now, so this is just a guess. Are you shure, that you have jQuery propperly loaded? Christof
[jQuery] Re: dealing with spam on the jQuery list.
Hi, We'd have to mark them as spam via the gmail web client though, right? I use Thunderbird to get my gmail. I almost never visit the actual gmail web client. :o' I don't use gmail. I wouldn't use the gmail webclient, because I am very happy with kmail. I don't like to use webmailers, because with them I can not see my mail while I am offline. I don't know, what spamfilters gmail gives you, but I'd like to have spam filtered from the mailinglist before it reaches me. Christof
[jQuery] Re: The best practice to do this
Hi, textarea id=mytext -1 -2 -3 /textarea I guess, it is just my lack of imagination why someone could whant to need such a UI. At first I suggest, that you step back and have some thoughts if there really is not a better uI for what you need. Anyway, To get what I think you need you could try something like this: $('#mytext').keydown(function(ev) { if( ev.keyCode == 13 ) { var self = $(this); self.text(self.text().replace(/^([^-][^ ])/g,'- $1')); } }); Not tested, but this should check for each keystroke if it was a newline. If it was, it should insert a '- ' at the begining of all Lines that don't already have it. My problem is how i break a line in textarea (i try a lot things and dont work) ?? It yould simply work by inserting a '\n' at the appropriate place in the Textarea. Christof
[jQuery] Re: An idea for a jQuery core addition - Plugin Registering...
Hi, A lot of people prefer to package up all the plug-ins they use on a site and then pack/minimize it into one file. This method can be really affective for plug-ins that are used as part of the core site theme. 1. When your pages have very different functionality, it is more efficient to load only what you need. 2. When you don't need all Libraries from the beginning (e.g. some of them just after a specific element has been clicked) you can increase User experience by loading them later. For this reason only, I see benefit is just have a very simple basic plug-in registration method for jQuery. That can be done with jsPax as well, btw: --- my.js $package('my.first.package',{ ... }); $package('my.second.package',{ ... }); $package('my',{}); --- $using('my', function() { // we have both packages availabe here $using('my.first.package', function() { // jsPax doesn't try to load anything here }); }); if( $package.packagefinished('my.first.package') ) { // package 'my.first.package' is available here } else { // package 'my.first.package' is not available here } You can even pack all the packages in your main script and inside the same script use $using(). The packages ar already availabe then and nothing will be loaded. Christof
[jQuery] Re: An idea for a jQuery core addition - Plugin Registering...
Hi, how would jsPax accomplish: $(user).each(function(){ $.jsanUse('com.myapp.userClass'); com.myapp.userClass.doSomething(this); }); Where com.myapp.userClass.doSomething is passed the selected user? Would it have to be this? $using('com.myapp.userClass', function() { $(user).each(function(){ com.myapp.userClass.doSomething(this); }); }); You can also write $(user).each(function(){ $using('com.myapp.userClass', function() { com.myapp.userClass.doSomething(this); }); }); Then 'com.myapp.userClass' is loaded for the first user-Element if there is any. The each() runns through all Elements and after the first element, $using() just notices that 'com.myapp.userClass' is already on its way to come and deferres the callback. As soon as 'com.myapp.userClass' is available all pending callbacks are executed. each() returns immediatelly. Overall I think we both agree that namespace based on-demand package loading is a valuable asset to any JS developer. Yes :-) Christof
[jQuery] Re: An idea for a jQuery core addition - Plugin Registering...
Hi, variable names. You can e.g. do that by encouraging people to use Plugin names like java packages, e.g. org.jquery.ajax. Exactly! And furthermore if you use a corresponding directory structure i.e. /jslib/org/jquery/ajax.js then you should eliminate collisions right off the bat. That is exactly how jsPax searches for its packages. It also seems the OpenAjax approach assumes an HTML page with a large number of script tags. In my apps I use two: script src=/jslib/jquery-latest.pack.js .../script script src=/jslib/jqjsan.js .../script // the jQuery port of JSAN i mentioned in a previous post script type=text/javascript ... $.jsanUse('com.myapp.controller'); /script I simply use script src=/scripts/package.js type=text/javascript/script script $package.packageBase = '/scripts/packages'; $using('com.myapp.controller', function() { // ... do something when library has finished loading. }); /script And for the sake of example the file /jslib/com/myapp/controller.js would look something like: if (typeof self != 'undefined') { if (typeof com == undefined ){ com = {};} if (typeof com.myapp == undefined ){ com.myapp = {};} if (typeof com.myapp.controller == undefined ) { com.myapp.controller = { [...] }); } else if(typeof $.jsanUse != 'undefined'){ $.jsanUse('com.myapp.controller'); } else { throw new Error(com.myapp.controller does not support your platform); } In my case it is $using('jQuery', function() { $package('com.myapp.controller', { // ... the com.myapp.controller package. }); }); Note that functionality like com.myapp.errorClass is loaded on demand only if and when I need it. That is exactly what jsPax is for. Have a look at jspax.org. This keeps the initial footprint small. Last time I looked at JSAN, the initial Footprint for jsPax was a lot smaller. As I can see from your Script-tags, you are loading jQuery as part of the initial Footprint as well. For me jQuery is just another package. Since the namespace is created when the package is loaded any further calls to $.jsanUse('com.myapp.errorClass') will not reload the files as it checks for the namespace first. jsPax can even find out that a file has already been requested but has not finished loading. That way you can do something like this: $using('jQuery', function() { // jQuery is available here }); // jQuery is not available here $using('jQuery.ajax', function() { // jQuery.ajax needs the package jQuery as well. // here bth packages are available, but jQuery will only be loaded once. }); Overall your jslib may contain a larger filesize but you will only be loading small bits spread over the time your app is being used. Yes. I use things like that: $using('jQuery', function() { $(function() { $('#myelem').click(function() { $using('some.other.package', function() { // the other package will be loaded after the // element has been clicked the first time. }); }); }); }); Christof
[jQuery] Re: An idea for a jQuery core addition - Plugin Registering...
Hi, In my May 2 2007 11:21 post I mentioned a jQuery port of JSAN making it a plugin to jQuery. the code in that post is the entire contents of the file jqjsan.js which comes out to 1,116 bytes in an uncompressed state. The compressed jsPax is 1,654 bytes. But as you pointed out they are really getting at the same end result. But you need jQuery loaded before you can use it, correct? That means, you need a fiew bits more than just 1116 bytes that are initially loaded. JsPax doesn't need anything to be loaded before. Because the load of $.jsanUse is done async:false I can use it's methods immediately after the request instead of the function in jsPax's $using. On the other hand jsPax can load multiple Libraries in parallel: $using(['jQuery','my.other.lib','yet.another.lib'], function() {...}); Then jsPax starts three XMLHttpRequests and executes the function as soon as all three packages are completely loaded with all dependencies. The browser can do his best efforts to optimize the requests. He can pipeline the requests in one connection, he can use multiple connections or a combination of that. If you use very many small libraies which depend on even more small libraries, your performance will noticably increase with jsPax. Of course the app 'pauses' during the load, but this has not caused any complaints from the users as the files are small enough to typically load in 100ms. I guess that depends on the connection your user uses. Try the same with a connection with a long round trip time - e.g. dialup GSM connection. My experience is that most people don't complain about a bad user experience as long as they don't know that it could be done better. The plugin I showed there supports altURLs that are not the same as the namespace and a flag to use the -min version of a file. I have thought about features like that when I developed jsPax. I came to the conclution, that the cases you need them are so rare, that they don't justify a bigger package.js. Whenever you really need it, you cann create a package to handle that. Because it is using the XHR+eval approach it does not yet support js files JsPax uses XHR+eval as well. If the Browser doesn't have a XHR-implementation it tries to use DOM to create a script tag. The Reason why I chose XHR+eval is, that there are Safari Versions that don't eval scripts that are added via DOM. JSAN was created about a year before jsPax http://use.perl.org/~schwern/journal/24112 and I first used it in a commercial project in January of 2006. I knew JSAN before I created jsPax, but there were some reasons why I did not use it: 1. It uses synchronous XHR, which means the browser can not really optimize the calls - I was creating a complex set of small libraries for a specific Application. 2. It doesn't have a fallback for Browsers without XHR - the Application I was developing could not accept that. 3. It has a lot of stuff in the API that is not absolutelly necessary for a package system and thus unnecessarily makes the core Library unnecessarily big. 4. I don't like the API that results form the synchronous loading. I much prefer the callback when all needed Libraries are loaded. I have used it in almost every project since, and this is really the main reason I talk about it over anything else. I have used jsPax in various professional applications now. I guess that there is a stalemate here. I was drawn to the idea of a plugin for jQuery since that would allow it to use some of the functionality jQuery has built in like $.ajax I do use jQuery plugins as jsPax packages. I use jQuery itself as a package - there are some pages where I don't need jQuery, but other libraries. Christof
[jQuery] Re: An idea for a jQuery core addition - Plugin Registering...
Hi, Why not use OpenAjax? http://ejohn.org/blog/thoughts-on-openajax/ OK, I accept the legal stuff. I did not join that Alliance because I did not understand any of that. I have problems with legal texts in german - a foreign language doesn't make that better. The technical stuff: OpenAjax is a specification and not an implementation. The refference implementation is in fact really bad. The mistake I see in Johns analysis as well as in deans comment in the jQuery blog is, that they analyse the poor code of the refference imlementation and take that to condemn the specification. I think the spec could be a lot worse. As I said I was planing to write an OpenAjax Hub as a jsPax package. I took the refference implementation as a place to look for the desired behaviour - not as base for the code. If you would like to load your js files that way as well, your API looks much like the jsPax API. I was planing to make an OpenAjax-package for jsPax that uses the jsPax package information, but did not get around to do it. The idea was to give users of plugin a hint which dependencies are not loaded yet, without any fancy packaging on the clientside. Actually I was falling in the naming trap that Brandon already noted. Don't call it require. $.dimensions = {}; OK, here we use $package('dimensions',{}) with jsPax - not really more complicated. Yeah, but I don't see that we actually gain anything that way. 1. If you use Stuff like $.dimensions = {}; You pollute the jQuery internal namespace. Maybe use something like $.plugins.dimensions = {}. 2. You can not easily express subplugins. Maybe you would like to partition the functionality of a more complex plugin in multiple files and have a central js-file that needs all the others, but each one can used stand allone or requires just a subset of the other files. Load one of them and it maybe tries $.myplugin.partone = {}. That fails if $.myplugin does not exist, that is if the main file is not loaded. The main file is not necessary for the code that just needs explicitly that part of your plugin: - myplugin.js $.myplugin = {} // we can not wait for the file to be fully evaluated. // that is bad for multythreaded JS implementations as well as // for exceptions that arise while myplugin.js is evaluated. $.ajax({ url: 'www.example.com/js/myplugin/part1.js', async: false, dataType: 'script' }); $.ajax({ url: 'www.example.com/js/myplugin/part2.js', async: false, dataType: 'script' }); $.ajax({ url: 'www.example.com/js/myplugin/part3.js', async: false, dataType: 'script' }); $.ajax({ url: 'www.example.com/js/myplugin/part4.js', async: false, dataType: 'script' }); - - myplugin/part1.js if(!$.myplugin) $.myplugin = {}; $.myplugin.part1 = {}; ... - - myplugin/part2.js if(!$.myplugin) $.myplugin = {}; $.myplugin.part2 = {}; ... - - myplugin/part3.js if(!$.myplugin) $.myplugin = {}; $.myplugin.part3 = {}; $.require('myplugin.part1,myplugin.part2'); ... - - myplugin/part4.js if(!$.myplugin) $.myplugin = {}; $.myplugin.part4 = {}; $.require('myplugin.part1,myplugin.part3'); ... - Please check if myplugin.js has been loaded (not only one of the parts). Just to add a potential solution for all of the problems: jQuery.checkForPlugins = function(names) { var ns = (typeof names == 'string')?names.split(','):names, i, p, n, j; for( i = 0; i ns.length; i++) { // this is still faster than $.each() // and not too much more code. // I don't have a real problem if // you change that to use $.each(). p = jQuery.plugins; n = (ns[i]+'.available').split('.'); for( j = 0; p j n.length; j++) { if( !p[n[j]] ) throw required plugin + ns[i] + not found; p = p[n[j]]; } } } jQuery.plugin = function(name) { var p = jQuery.plugins; var n = name.split('.'); for( var i = 0; i n.length; i++ ) { if( !p[n[i]] ) p[n[i]] = {}; p = p[n[i]]; } p[n].available = true; } // Usage: $.checkForPlugins('autocomplete,dimensions,myplugin.part1'); // or $.checkForPlugins(['autocomplete','dimensions','myplugin.part1']); // at the end of the plugin: $.plugin('dimensions'); That is very similar to what jsPax does for dependency tracking. JsPax also has to maintain the state that a package has alreday been requested but has not finished loading by now, i.e. is not available. Christof
[jQuery] Re: An idea for a jQuery core addition - Plugin Registering...
Hi, Sorry, I just found a mistake in my solution code: jQuery.plugin = function(name) { var p = jQuery.plugins; var n = name.split('.'); for( var i = 0; i n.length; i++ ) { if( !p[n[i]] ) p[n[i]] = {}; p = p[n[i]]; } p[n].available = true; } That should be p.available = true; of course. That code can easily be changed to support other Information about the plugins, like e.g. version numbers: jQuery.getPluginVersion = function(name) { var n = (name).split('.'), j; for( j = 0; p j n.length; j++) { if( !p[n[j]] ) throw required plugin + ns[i] + not found; p = p[n[j]]; } return p.version; } jQuery.plugin = function(name,version) { var p = jQuery.plugins; var n = name.split('.'); for( var i = 0; i n.length; i++ ) { if( !p[n[i]] ) p[n[i]] = {}; p = p[n[i]]; } p[n].available = true; p[n].version = version?parseFloat(version):0; } // Usage: $.checkForPlugins('autocomplete,dimensions,myplugin.part1'); if( $.getPluginVersion('myplugin.part1') 42.2 ) throw get a current Version of myplugin!; // at the end of the plugin: $.plugin('myplugin.part1',42.5); Christof
[jQuery] Re: An idea for a jQuery core addition - Plugin Registering...
Hi, // Implementation: $.require = function(names) { $.each(names.split(,), function(i, n) { if( !$.fn[n] || $[n] ) throw required plugin + n + not found; }); } // Usage: $.require(autocomplete,dimensions); Why not use OpenAjax? If you would like to load your js files that way as well, your API looks much like the jsPax API. I was planing to make an OpenAjax-package for jsPax that uses the jsPax package information, but did not get around to do it. $.dimensions = {}; OK, here we use $package('dimensions',{}) with jsPax - not really more complicated. Christof
[jQuery] Re: Why this code is so slow?
Hi, How can I change this to my code runs faster? I don't think, that you should change jQuery here. As much as I understand it, that function is called whenever you use a more complex expression than just an ID, a tag name or a classname. 1. Try to give your input-Elements IDs and use $(#myid).filter([EMAIL PROTECTED]) instead of [EMAIL PROTECTED]'patrimoniais__pat_co_veiculos'[EMAIL PROTECTED]. Then jQuery can use document.getElementByID() to get the Element and checks for the condition in the filter. I am not shure if jQuery will do the same for $([EMAIL PROTECTED]). You could profile to see if there is a difference. 2. Use chaining and try to cache jQuery results: $('#dadosAuxiliares').tabs( {fxShow: {height: 'show', opacity: 'show'}, tabStruct:'.fragment'}); $('#dadosAuxiliares').triggerTab(0); can be $('#dadosAuxiliares').tabs( { fxShow: {height: 'show', opacity: 'show'}, tabStruct:'.fragment'} ).triggerTab(0); Then the query for '#dadosAuxiliares' onlyneeds to be executed once. $([EMAIL PROTECTED]'familiares__pes_ds_dependente_possui']).click(function(){ // apresenta um highlight na linha clicada $('.show_familiares__pes_ds_dependente_possui').highlightFade({color:'yellow',speed:1500,iterator:'sinusoidal'}); if ($([EMAIL PROTECTED]'familiares__pes_ds_dependente_possui'[EMAIL PROTECTED]).val() == 1){ $(.show_familiares__pes_ds_dependente_possui).show(); } else{ $(.show_familiares__pes_ds_dependente_possui).hide(); } }); can be var p = $([EMAIL PROTECTED]'familiares__pes_ds_dependente_possui']); var shp = $('.show_familiares__pes_ds_dependente_possui'); p.click(function{ shp.highlightFade({color:'yellow',speed:1500,iterator:'sinusoidal'}); if( p.filter('[EMAIL PROTECTED]').val == 1 ) shp.show(); else shp.hide(); p.end(); // remove the filter result }); Then p and shp are only queried once during the whole life of the script. Christof
[jQuery] Re: Library showdowns
Hi, There are some situations when you can only pass a variable referring to a function; with a curry function you can pass a variable that refers to a function + arguments. That is not a big problem with annonymous functions: takingAFunction(function(a){return mycallback(5,a)}); That is more elaborate but also more flexible than currying: takingAFunction(function(a){return mycallback(a,5)}); With currying you only get the first variant - at least with weakly typed languages like JavaScript. With strongly typed languages you run into the same problem, when two parameters have the same type (pseudocode): float function mycallback(float a, float b) { return a/b; } mycallback(42) must produce something equivalent to float function(float b) { return mycallback(42,b); } Currying doesn't give you float function(float a) { return mycallback(a,42); } Christof
[jQuery] Re: Library showdowns
Hi, Currying doesn't give you float function(float a) { return mycallback(a,42); } Of course it does, you just have to clever. let us say you have this function: divide = function(a){ return function(b){ return a/b; }} If you want to create the function a/3 you can do the following: id = function(id){ return id; } div3 = divide(id)(3); Well, then there is not much left from the ellegance currying gives you at first glance. You don't relly get that, because you need to work around the weaknesses of currying. Christof
[jQuery] Re: [Newbie] Why this. doesn't work?
Hi, I have this Javascript in JSON notation and using the jQuery Ajax. var objectJSON = { myvalue: hello, myFunction: function(param) { this.myvalue = param; $.ajax({ type: POST, url: '/ajax/address.php', data: param= + param, success: this.pageLoadOk }); }, pageLoadOk: function(t){ $('#id-element').html(t); alert(this.myvalue); //*** this.myvalue is not accesible from here ***// alert(objectJSON.myvalue); //***It works **// }, Your function pageLoadOk is called with the annonymous object you provide to $.ajax() as this, not with objectJSON. To understand what happens, try this: var objectJSON = { myvalue: hello, myFunction: function(param) { this.myvalue = param; $.ajax({ type: POST, url: '/ajax/address.php', data: param= + param, success: this.pageLoadOk, myvalue: param // here is the difference! }); }, pageLoadOk: function(t){ $('#id-element').html(t); alert(this.myvalue); alert(objectJSON.myvalue); }, } Christof