/* This file is automatically generated */ /* Copyright (c) 2008 Rizqi Ahmad Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ /* core.js */ (function($){ $.Chain = { version: '0.1', tag: ['{', '}'], services: {}, service: function(name, proto) { this.services[name] = proto; $.fn[name] = function(options) { if(!this.length) return this; var instance = this.data('chain-'+name); var args = Array.prototype.slice.call(arguments, 1); if(!instance) { instance = $.extend({element: this}, $.Chain.services[name]); this.data('chain-'+name, instance); if(instance.init) instance.init(); } var result; if(typeof options == 'string' && instance['$'+options]) result = instance['$'+options].apply(instance, args); else if(instance['handler']) result = instance['handler'].apply(instance, [options].concat(args)); else result = this; if(options == 'destroy') this.removeData('chain-'+name); return result; }; }, extend: function(name, proto) { if(this.services[name]) this.services[name] = $.extend(this.services[name], proto); }, jobject: function(obj) { return obj && obj.init == $.fn.init; }, jidentic: function(j1, j2) { if(!j1 || !j2 || j1.length != j2.length) return false; a1 = j1.get(); a2 = j2.get(); for(var i=0; i 1) { if(typeof fn == 'function') this.collections[col] = fn; return this.element; } else { if(this.collections[col]) return this.collections[col].apply(this); else return $().eq(-1); } }, $update: function() { if(!this.element.chain('active') || !this.isActive) return this.element; var self = this; var builder = this.element.chain('builder'); var template = $(this.element.chain('template')).eq(0); $.each(this.buffer, function(){ var clone = template .clone() .appendTo(self.element.chain('anchor')) .addClass('chain-item') .item('root', self.element); if(self.linkElement && $.Chain.jobject(this) && this.item()) clone.item('link', this, 'self'); else clone.item(this); clone.chain(builder); }); this.buffer = []; return this.element; }, $add: function() { this.isActive = true; this.buffer = this.buffer.concat(Array.prototype.slice.call(arguments)); this.update(); return this.element; }, $merge: function(items) { this.isActive = true; if($.Chain.jobject(items)) this.buffer = this.buffer.concat(items.map(function(){return $(this)}).get()); else if(items instanceof Array) this.buffer = this.buffer.concat(items); this.update(); return this.element; }, $replace: function(items) { this.isActive = true; this.empty(); if($.Chain.jobject(items)) this.buffer = items.map(function(){return $(this)}).get(); else if(items instanceof Array) this.buffer = items; this.update(); return this.element; }, $remove: function() { for(var i=0; i parseFloat(($(b).item()[name]+'').match(/\d+/gi)[0]); }, 'default': function(a, b){ return $(a).item()[name] > $(b).item()[name]; } }; if(name) { var sortfn = opt.fn || sorter[opt.type] || sorter['default']; var array = this.element.items(true).get().sort(sortfn); array = opt.desc ? array.reverse() : array; for(var i=0; i