-
-
Save lsmith/375536 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').insert('<p>New content</p>', 'replace'); | |
Y.one('#id3').remove(); | |
/** | |
* Effects | |
*/ | |
new Y.Anim({ | |
node: '#id1', | |
to: { | |
height: 0 | |
}, | |
duration: 3 | |
}).run(); | |
new Y.Anim({ | |
node: '#id2', | |
to: { | |
opacity: 0 | |
}, | |
duration: 1 | |
}).run(); | |
new Y.Anim({ | |
node: '#id3', | |
to: { | |
height: 20, | |
opacity: 0.5 | |
}, | |
duration: 1.5 | |
}).run(); | |
/** | |
* Transition | |
*/ | |
new Y.Anim({ | |
node: '#id', | |
to: { | |
height: 20 | |
}, | |
duration : 1.5, | |
easing : Y.Easing.bounceOut | |
}).run(); | |
/** | |
* Events | |
*/ | |
Y.one('#id').on({ | |
click: function (e) { | |
this.setStyle('background','red'); | |
}, | |
mouseout: function (e) { | |
this.setStyle('background','blue'); | |
} | |
}); | |
/** | |
* Custom Function | |
*/ | |
Y.Node.prototype.customFunction = function ( cfg ) { | |
this.setStyles({ | |
background: cfg.background, | |
border: cfg.border | |
}); | |
}; | |
Y.one("#id").customFunction({ | |
color: "red", | |
border: "3px blue solid" | |
}); | |
/** | |
* Ajax | |
*/ | |
Y.io('ajax.html',{ | |
method: 'GET', | |
on: { | |
success: function (id,o,args){ | |
Y.one('#id').setContent(o.responseText); | |
} | |
} | |
}); | |
/** | |
* Classes | |
*/ | |
function Developer() { | |
Developer.superclass.constructor.apply(this, arguments); | |
} | |
function Designer() { | |
Designer.superclass.constructor.apply(this, 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