toserve.flight.lib.base.js Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of net.enilink.platform.lift Show documentation
Show all versions of net.enilink.platform.lift Show documentation
eniLINK is a web platform for linked data applications based on the KOMMA framework and Lift.
The newest version!
define(["./utils","./registry","./debug"],function(t,e,n){"use strict";function i(t){t.events.slice().forEach(function(t){var e=[t.type];t.element&&e.unshift(t.element),"function"==typeof t.callback&&e.push(t.callback),this.off.apply(this,e)},t.instance)}function r(t,e){try{window.postMessage(e,"*")}catch(n){throw console.log("unserializable data for event",t,":",e),new Error(["The event",t,"on component",this.toString(),"was triggered with non-serializable data"].join(" "))}}function o(t){var e,i=[];if(this.attr=new this.attrDef,n.enabled&&window.console){for(var r in this.attrDef.prototype)i.push(r);e=Object.keys(t);for(var o=e.length-1;o>=0;o--)if(-1==i.indexOf(e[o])){console.warn('Passed unused attributes including "'+e[o]+'" to component "'+this.toString()+'".');break}}for(var r in this.attrDef.prototype)if("undefined"==typeof t[r]){if(null==this.attr[r])throw new Error('Required attribute "'+r+'" not specified in attachTo for component "'+this.toString()+'".')}else this.attr[r]=t[r]}function s(t){var e=Object.create(t);for(var n in this.defaults)t.hasOwnProperty(n)||(e[n]=this.defaults[n]);this.attr=e,Object.keys(this.defaults||{}).forEach(function(t){if(null===this.defaults[t]&&null===this.attr[t])throw new Error('Required attribute "'+t+'" not specified in attachTo for component "'+this.toString()+'".')},this)}function a(t){return function(e,n){$(e.target).trigger(t,n)}}function u(){this.trigger=function(){var t,e,i,o,s,a=arguments.length-1,u=arguments[a];return"string"==typeof u||u&&u.defaultBehavior||(a--,i=u),1==a?(t=$(arguments[0]),o=arguments[1]):(t=this.$node,o=arguments[0]),o.defaultBehavior&&(s=o.defaultBehavior,o=$.Event(o.type)),e=o.type||o,n.enabled&&window.postMessage&&r.call(this,e,i),"object"==typeof this.attr.eventData&&(i=$.extend(!0,{},this.attr.eventData,i)),t.trigger(o||e,i),s&&!o.isDefaultPrevented()&&(this[s]||s).call(this),t},this.on=function(){var e,n,i,r,o=arguments.length-1,s=arguments[o];if(r="object"==typeof s?t.delegate(this.resolveDelegateRules(s)):"string"==typeof s?a(s):s,2==o?(e=$(arguments[0]),n=arguments[1]):(e=this.$node,n=arguments[0]),"function"!=typeof r&&"object"!=typeof r)throw new Error('Unable to bind to "'+n+'" because the given callback is not a function or an object');return i=r.bind(this),i.target=r,i.context=this,e.on(n,i),r.bound||(r.bound=[]),r.bound.push(i),i},this.off=function(){var t,e,n,i=arguments.length-1;if("function"==typeof arguments[i]&&(n=arguments[i],i-=1),1==i?(t=$(arguments[0]),e=arguments[1]):(t=this.$node,e=arguments[0]),n){var r=n.target?n.target.bound:n.bound||[];r&&r.some(function(t,e,i){return t.context&&this.identity==t.context.identity?(i.splice(e,1),n=t,!0):void 0},this)}return t.off(e,n)},this.resolveDelegateRules=function(t){var e={};return Object.keys(t).forEach(function(n){if(!(n in this.attr))throw new Error('Component "'+this.toString()+'" wants to listen on "'+n+'" but no such attribute was defined.');e[this.attr[n]]="string"==typeof t[n]?a(t[n]):t[n]},this),e},this.select=function(t){return this.$node.find(this.attr[t])},this.attributes=function(t){var e=function(){};this.attrDef&&(e.prototype=new this.attrDef);for(var n in t)e.prototype[n]=t[n];this.attrDef=e},this.defaultAttrs=function(e){t.push(this.defaults,e,!0)||(this.defaults=e)},this.initialize=function(t,e){if(e=e||{},this.identity||(this.identity=h++),!t)throw new Error("Component needs a node");return t.jquery?(this.node=t[0],this.$node=t):(this.node=t,this.$node=$(t)),this.attrDef?o.call(this,e):s.call(this,e),this},this.teardown=function(){i(e.findInstanceInfo(this))}}var h=0;return u});