function $W(path){ // var path_parts = path.split('/'); // var wdgt; // for (var i=0; i < path_parts.length; i++){ // wdgt = $('.widget.id-'+path_parts[i]); // } if (Spider.widgets[path]) return Spider.widgets[path]; var wdgt_id = path.replace(/\//g, '-'); var wdgt = $('#'+wdgt_id); if (wdgt.length == 0) return null; return Spider.Widget.initFromEl(wdgt); } Spider = function(){}; if (window.SPIDER_BASE_URL) Spider.baseUrl = window.SPIDER_BASE_URL; else Spider.baseUrl = ""; Spider.widgets = {}; Widgets = function(){}; Spider.Widget = Class.extend({ init: function(container, path, config){ this.el = container; this.path = path; var pathParts = path.split('/'); this.widgetId = pathParts[pathParts.length - 1]; this.fullId = pathParts.join('_'); this.backend = new Spider.WidgetBackend(this); this.readyFunctions = []; config = $.extend({}, config); this.config = config; this.model = config.model; Spider.widgets[path] = this; this.events = []; this.onWidgetCallbacks = {}; this.widgets = {}; this.findWidgets(); this.startup(); this.ready(); this.applyReady(); this.plugins = []; if (this.includePlugins){ for (var i=0; i 0 && !par.is('.widget')){ par = par.parent(); } if (!par) return null; return par.spiderWidget(); }; $.fn.getDataObjectKey = function(){ var doParent = null; var par = this; while (par && par.length > 0 && !par.is('.dataobject')){ par = par.parent(); } if (!par) return null; return $('>.dataobject-key', par).text(); }; $.fn.getDataModel = function(){ var par = this; while (par && par.length > 0 && !par.is('.model')){ par = par.parent(); } if (!par) return null; var cl = par.attr('class'); if (!cl) return null; var cl_parts = cl.split(' '); for (var i=0; i < cl_parts.length; i++){ if (cl_parts[i].substr(0, 6) == 'model-'){ return cl_parts[i].substr(6).replace(/-/g, '::'); } } return null; }; Spider.htmlFunctions = []; Spider.onHTML = function(callback){ Spider.htmlFunctions.push(callback); $(document).ready(function(){ callback.call($(this.body)); }); }; Spider.newHTML = function(el){ for (var i=0; i -1 ) { var namespaces = eventName.split("."); eventName = namespaces.shift(); handleObj.namespace = namespaces.slice(0).sort().join("."); } if (!this.events[eventName]) this.events[eventName] = []; this.events[eventName].push(handleObj); }, on: function(eventName, callback){ return this.bind(eventName, callback); }, trigger: function(eventName){ if (!this.events) this.events = {}; if ( eventName.indexOf(".") > -1 ) { var namespaces = eventName.split("."); eventName = namespaces.shift(); namespace = namespaces.slice(0).sort().join("."); } if (!this.events[eventName]) return; var args = Array.prototype.slice.call(arguments, 1); for (var i=0; i < this.events[eventName].length; i++){ this.events[eventName][i].callback.apply(this, args); } }, unbind: function(eventName){ if (!this.events) this.events = {}; var namespace = null; if ( eventName.indexOf(".") > -1 ) { var namespaces = eventName.split("."); eventName = namespaces.shift(); namespace = namespaces.slice(0).sort().join("."); } if (namespace){ for (var i=0; i