Permalink
Browse files

First commit

  • Loading branch information...
0 parents commit 3a564fa8c586090b628a1ebc5b55563f6a91bb75 Winton Welsh committed Apr 27, 2008
Showing with 7,918 additions and 0 deletions.
  1. +68 −0 AjaxChain.js
  2. +46 −0 Array.js
  3. +97 −0 Base.js
  4. +326 −0 Dialog.js
  5. +221 −0 Element.js
  6. +25 −0 Indicator.js
  7. +56 −0 Lightbox.js
  8. 0 README
  9. BIN assets/.DS_Store
  10. +7,064 −0 assets/moo.js
  11. +15 −0 assets/setup.rb
  12. BIN assets/yui_compressor.jar
@@ -0,0 +1,68 @@
+/*
+Script: AjaxChain.js
+ Contains the <AjaxChain> class.
+
+License:
+ MIT-style license.
+*/
+
+/*
+Class: AjaxChain
+ A chain implementation for Ajax requests.
+
+Events:
+ onEnd - Called when chain length goes from one to empty.
+ onStart - Called when chain length goes from empty to one.
+
+Example:
+ >// ajax request will execute only after the last one finished
+ >while (true) {
+ > this.chain(function() {
+ > new Ajax('/', {
+ > onComplete: function() {
+ > this.callChain();
+ > }.bind(this),
+ > onFailure: function() {
+ > this.callChain(true); // call chain again
+ > }.bind(this)
+ > }).request();
+ > }.bind(this));
+ >}
+*/
+
+var AjaxChain = new Class({
+
+ chain: function(fn){
+ this.chains = this.chains || [];
+ this.chains.push(fn);
+
+ if (this.chains.length == 1) {
+ this.fireEvent('onStart');
+ fn.delay(10, this);
+ }
+
+ return this;
+ },
+
+ callChain: function(failed){
+ if (this.chains && this.chains.length) {
+ if (failed)
+ this.chains[0].delay(10, this);
+ else {
+ this.chains.shift();
+
+ if (this.chains.length)
+ this.chains[0].delay(10, this);
+ else
+ this.fireEvent('onEnd');
+ }
+ }
+ },
+
+ clearChain: function(){
+ this.chains = [];
+ }
+
+});
+
+AjaxChain.implement(new Events);
@@ -0,0 +1,46 @@
+/*
+Script: Array.js
+ Contains Array prototypes.
+
+License:
+ MIT-style license.
+*/
+
+/*
+Structure: Array
+ Extensions to the native Array object.
+*/
+
+Array.extend({
+
+ /*
+ Property: toObject
+ Returns an object with the Array's values as keys.
+
+ Arguments:
+ fill - (default: null) All values are set to this value.
+ */
+
+ toObject: function(fill) {
+ var obj = {};
+ this.each(function(item) {
+ obj[item] = (fill) ? fill : true;
+ });
+ return obj;
+ },
+
+ /*
+ Property: zebra
+ Adds the class name "zebra" to even or odd indices of the element array
+
+ Arguments:
+ odd - True if zebra'ing odd indexed elements instead of even.
+ */
+
+ zebra: function(odd) {
+ var add = (odd) ? 1 : 0;
+ this.each(function(item, index) {
+ ((index + add) % 2 == 0) ? item.addClass('zebra') : item.removeClass('zebra');
+ });
+ }
+});
97 Base.js
@@ -0,0 +1,97 @@
+/*
+Script: Base.js
+ Contains the <Base> class.
+
+License:
+ MIT-style license.
+*/
+
+/*
+Class: Base
+ Extend this class to add DOM load groups (by selector) and automatic event attachment.
+
+Example:
+ >var Test = Base.extend({
+ >
+ > initialize: function() {
+ > this.parent(); // call Base constructor
+ > },
+ >
+ > elements: {
+ > load: { // elements in 'load' are loaded on instanciation
+ > rows: '.row'
+ > },
+ > links: {
+ > my_link: 'a.my_link'
+ > }
+ > },
+ >
+ > onMyLinkClick: function(e, el) {
+ > console.log('my link clicked!');
+ > }
+ >});
+ >
+ >console.log(Test.elements.rows); // [ element, element ]
+ >console.log(Test.elements.my_link); // null
+ >
+ >Test.loadElements('links');
+ >console.log(Test.elements.my_link); // element
+*/
+
+var Base = new Class({
+
+ initialize: function() {
+ if (this.elements.load)
+ this.loadElements('load');
+ },
+
+ loadElement: function(name, group) {
+ if (name == 'filter') return false;
+
+ var filter = this.elements[group].filter;
+ var selector = this.elements[group][name];
+
+ var elements = $ES(selector, (filter) ? $$(filter)[0] : null);
+
+ var eventName = 'on' + name.split('_').map(function(item) { return item.capitalize(); }).join('');
+ var regex = new RegExp(eventName + '[a-zA-Z]+');
+
+ // addEvent for fn matches
+ for (fn in this) {
+ if ($type(this[fn]) != 'function') continue;
+ if (regex.test(fn)) {
+ var event = fn.substring(eventName.length).toLowerCase();
+
+ elements.each(function(item) {
+ item.removeEvents(event);
+ item.addEvent(event, this[fn].bindWithEvent(this, [ item, this.el ]));
+ }, this);
+ }
+ }
+
+ this.el[name] = elements;
+
+ // force array
+ if (!this.elements.force_array.contains(name) && this.el[name].length == 1)
+ this.el[name] = this.el[name][0];
+
+ return this.el[name];
+ },
+
+ loadElements: function(group) {
+ for (name in this.elements[group])
+ this.loadElement(name, group);
+ },
+
+ unloadElement: function(name, group, type) {
+ if (this.el[name]) {
+ this.el[name].removeEvents(type);
+ delete this.el[name];
+ }
+ },
+
+ unloadElements: function(group) {
+ for (name in this.elements[group])
+ this.unloadElement(name, group);
+ }
+});
Oops, something went wrong.

0 comments on commit 3a564fa

Please sign in to comment.