This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
cujo.Stateful | |
(c) copyright 2010, unscriptable.com | |
author: john | |
LICENSE: see the LICENSE.txt file. If file is missing, this file is subject to the AFL 3.0 | |
license at the following url: http://www.opensource.org/licenses/afl-3.0.php. | |
Adds dojo.Stateful behavior to objects without the dojo.declare turds and overhead |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var myApplet = funcToGetApplet(); | |
myApplet.setCallback({ | |
myMethod: function (args) { | |
// do something with args here | |
}, | |
anotherMethod: function (args) { | |
// do something with args here |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function createObject (ctor, args) { | |
function F () { | |
ctor.apply(this, args); | |
} | |
F.prototype = ctor.prototype; | |
F.prototype.constructor = ctor; // IE might need this | |
return new F(); | |
} | |
// quick test: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// result sets (two identical queries) | |
var rs1, rs2; | |
//items to watch (two instances of same model data) | |
var item1, item2; | |
dojo.when(store.query({}), function (results) { | |
rs1 = results; | |
item1 = results[0]; | |
// item1.get('prop') == 'foo' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function init () { | |
// find widgets by id: | |
var myStandby = dijit.byId('basicStandby1'), | |
myForm = dijit.byId('myForm'); | |
// i don't think you need this line, but i haven't studied the BasicStandby widget | |
//document.body.appendChild(myStandby.domNode); | |
dojo.connect(myForm, 'onSubmit', function() { | |
myStandby.show(); | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
attributeMap: { | |
seconds: { | |
data: "seconds", | |
type: "no-dom" | |
}, | |
displaySeconds: { | |
source: "seconds", | |
deriver: "_displaySeconds", | |
type: "no-dom" | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
cujo.js equivalent (in-browser): | |
file: myApp.view.LoginPanel.html | |
<div class="myapp-view-loginpanel"> | |
<span data-attach="greeting">${display.greeting}</span> | |
<a data-attach="action" href="{$config.loginUrl}">{$display.loginAction}</a> | |
</div> | |
logout version extends login version (inheritance defined in myApp.view.LogoutPanel.js: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
My comment on nettuts+ that didn't get approved (I wonder why) http://bit.ly/bwb18i | |
It seems that this post started out with good intentions: How to show junior javascript programmers how to use the Firebug profiling commands. However, due to crappy jQuery advice, turned into an illustration of web programming anti-patterns (aka “Programming No-nos”). | |
I have to agree with James (of course), and would add the following: | |
———- | |
Premature optimization. | |
Do not try to second-guess the framework (jQuery, prototype, dojo, etc.) unless you’ve already got a performance problem. The people who build those frameworks have done an excellent job and have designed them to work well in most situations. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$.each(itemList, function (which) { | |
// if dev passed an array | |
if ($.isArray(itemList)) | |
// use the 2nd arg as item name (1st arg is array index) | |
which = arguments[1]; | |
// check if we've already initialized this item | |
var already = doneMap[which]; | |
if (!already) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// original (http://html5shiv.googlecode.com/svn/trunk/html5.js) | |
(function(){if(!/*@cc_on!@*/0)return;var e = "abbr,article,aside,audio,canvas,datalist,details,figure,figcaption,footer,header,hgroup,mark,menu,meter,nav,output,progress,section,summary,time,video".split(','),i=e.length;while(i--){document.createElement(e[i])}})() | |
// kangax version (29 characters less, yay!) | |
/*@cc_on(function(e,i){i=e.length;while(i--)document.createElement(e[i])})("abbr,article,aside,audio,canvas,datalist,details,eventsource,figure,footer,header,hgroup,mark,menu,meter,nav,output,progress,section,time,video".split(','))@*/ |