Created
April 22, 2010 17:21
-
-
Save apipkin/375510 to your computer and use it in GitHub Desktop.
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
/** | |
* DOM Ready | |
*/ | |
Y.on('domready',function(e){ | |
// code | |
}); | |
/** | |
* DOM Basics | |
*/ | |
Y.all('#id, .class, div').setStyle('background', 'blue'); | |
/** | |
* DOM Filtering | |
*/ | |
Y.all('div p').setStyle('background', 'blue'); | |
Y.all("div[rel='test']").setStyle('background','blue'); | |
Y.all('div p:nth-child(odd)').setStyle('background','blue'); | |
/** | |
* DOM Manipulation | |
*/ | |
Y.one('#id1').append('<p>Additional content</p>'); | |
Y.one('#id2').replace('<p>New content</p>'); | |
Y.one('#id3').remove(); | |
/** | |
* Effects | |
*/ | |
new Y.Anim({ | |
node : Y.one('#id1'), | |
to : { | |
height : 0 | |
}, | |
duration : 3 | |
}).run(); | |
new Y.Anim({ | |
node : Y.one('#id2'), | |
to : { | |
opacity : 0 | |
}, | |
duration : 1 | |
}).run(); | |
new Y.Anim({ | |
node : Y.one('#id3'), | |
to : { | |
height : 20, | |
opacity : 0.5 | |
}, | |
duration : 1.5 | |
}).run(); | |
/** | |
* Transition | |
*/ | |
new Y.Anim({ | |
node : Y.one('#id'), | |
to : { | |
height : 20 | |
}, | |
duration : 1.5, | |
easing : Y.Easing.bounceOut | |
}).run(); | |
/** | |
* Events | |
*/ | |
Y.one('#id').on('click',function(e){ | |
e.currentTarget.setStyle('background','red'); | |
}).on('mouseout',function(e){ | |
e.currentTarget.setStyle('background','blue'); | |
}); | |
/** | |
* Custom Function | |
*/ | |
//?? | |
/** | |
* Ajax | |
*/ | |
Y.io('ajax.html',{ | |
method:'GET', | |
on:{ | |
success:function(id,o,args){ | |
Y.one('#id').setContent(o.responseText); | |
} | |
} | |
}); | |
/** | |
* Classes | |
*/ | |
var Developer = function (config){ | |
Developer.superclass.constructor.apply(arguments); | |
}, Designer = function(config) { | |
Designer.superclass.constructor.apply(arguments); | |
}; | |
Y.extend(Developer,Y.Base,{ | |
task : function() { | |
return 'Development'; | |
}, | |
info : function() { | |
alert( this.get('name') + ', ' | |
+ this.task() + ', ' | |
+ this.get('company') | |
); | |
} | |
},{ | |
NAME : 'developer', | |
ATTRS : { | |
name : {}, | |
company : { | |
value : 'New Company' | |
} | |
} | |
}); | |
Y.extend(Designer, Developer, { | |
task : function() { | |
return 'Design'; | |
} | |
},{ | |
NAME : 'designer' | |
}); | |
var newDeveloper = new Developer({name:'Tim'}); | |
var newDesigner = new Designer({name:'Tom'}); | |
newDeveloper.info(); // Output: "Tim, Development, New Company" | |
newDesigner.info(); // Output: "Tom, Design, New Company" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment