1
0
mirror of https://github.com/janeczku/calibre-web synced 2024-12-30 12:00:31 +00:00
calibre-web/cps/static/js/libs/intention.min.js

10 lines
5.7 KiB
JavaScript
Raw Normal View History

2017-01-14 12:32:25 +00:00
/*! intention.js v0.9.7.3
* http://intentionjs.com/
*
* intention.js
*
* Copyright 2011, 2013 Dowjones and other contributors
* Released under the MIT license
*
*/
!function(a,b){"use strict";"function"==typeof define&&define.amd?define("intention",["jquery","underscore"],b):a.Intention=b(a.jQuery,a._)}(this,function(a,b){"use strict";var c=function(c){var d=b.extend(this,c,{_listeners:{},contexts:[],elms:a(),axes:{},priority:[]});return d};return c.prototype={responsive:function d(a,c){var e,f="abcdefghijklmnopqrstuvwxyz0123456789",g="";for(e=0;5>e;e++)g+=f[Math.floor(Math.random()*f.length)];var h={matcher:function(a,b){return a===b.name},measure:b.identity,ID:g};if(b.isObject(c)===!1&&(c={}),b.isArray(a)&&b.isArray(a[0].contexts))return b.each(a,function(a){d.apply(this,a)},this),void 0;b.isArray(a)===!1&&b.isObject(a)?c=a:c.contexts=a,c=b.extend({},h,c),this.on("_"+c.ID+":",b.bind(function(a){this.axes=this._contextualize(c.ID,a.context,this.axes),this._respond(this.axes,this.elms)},this));var i={ID:c.ID,current:null,contexts:c.contexts,respond:b.bind(this._responder(c.ID,c.contexts,c.matcher,c.measure),this)};return this.axes[c.ID]=i,this.axes.__keys__=this.priority,this.priority.unshift(c.ID),i},elements:function(c){return c||(c=document),a("[data-intent],[intent],[data-in],[in]",c).each(b.bind(function(b,c){this.add(a(c))},this)),this},add:function(c,d){var e;return d||(d={}),c.each(b.bind(function(c,f){var g=!1;this.elms.each(function(a,b){return f===b?(g=!0,!1):!0}),g===!1&&(e=this._fillSpec(b.extend(d,this._attrsToSpec(f.attributes,this.axes))),this._makeChanges(a(f),e,this.axes),this.elms.push({elm:f,spec:e}))},this)),this},remove:function(a){var b=this.elms;return a.each(function(a,c){b.each(function(a,d){return c===d.elm?(b.splice(a,1),!1):!0})}),this},is:function(a){var c=this.axes;return b.some(c.__keys__,function(b){return a===c[b].current})},current:function(a){return this.axes.hasOwnProperty(a)?this.axes[a].current:!1},on:function(a,b){var c=a.split(" "),d=0;for(d;d<c.length;d++)void 0===this._listeners[c[d]]&&(this._listeners[c[d]]=[]),this._listeners[c[d]].push(b);return this},off:function(a,c){if(b.isArray(this._listeners[a])){var d,e=this._listeners[a];for(d=0;e.length;d++)if(e[d]===c){e.splice(d,1);break}}return this},_responder:function(a,c,d,e){var f;return function(){var g=e.apply(this,arguments);return b.every(c,function(c){return d(g,c)?void 0===f||c.name!==f.name?(f=c,this._emitter({_type:"_"+a+":",context:f.name},f,this)._emitter({_type:a+":",context:f.name},f,this)._emitter(b.extend({},{_type:a+":"+f.name},f),f,this)._emitter(b.extend({},{_type:f.name},f),f,this),!1):!1:!0},this),this}},_emitter:function(a){if("string"==typeof a&&(a={_type:a}),a.target||(a.target=this),!a._type)throw new Error(a._type+" is not a supported event.");if(b.isArray(this._listeners[a._type])){var c,d=this._listeners[a._type];for(c=0;c<d.length;c++)d[c].apply(this,arguments)}return this},_fillSpec:function(a){var c=function(c){b.each(a,function(a,d){b.each(a,function(a,b){c(a,b,d)})})},d={};return c(function(a){b.isObject(a)&&b.each(a,function(a,b){d[b]=""})}),c(function(c,e,f){b.isObject(c)&&(a[f][e]=b.extend({},d,c))}),a},_assocAxis:function(a,c){var d=!1;return b.every(c.__keys__,function(e){return d===!1?(b.every(c[e].contexts,function(b){return b.name===a?(d=e,!1):!0}),!0):!1}),d},_makeSpec:function(a,b,c,d,e){var f;return void 0!==e[a]?(f=e[a],void 0===f[b]&&(f[b]={})):(f={},f[b]={},e[a]=f),f[b][c]=d,e},_attrsToSpec:function(a,c){var d={},e=new RegExp("^(data-)?(in|intent)-(([a-zA-Z0-9][a-zA-Z0-9]*:)?([a-zA-Z0-9]*))-([A-Za-z:-]+)"),f=new RegExp("^(data-)?(in|intent)-([a-zA-Z0-9][_a-zA-Z0-9]*):$");return b.each(a,function(a){var g,h=a.name.match(e);if(null!==h){if(h=h.slice(-3),g=h[0],void 0===h[0]){if(h[0]=this._assocAxis(h[1],c),h[0]===!1)return}else h[0]=h[0].replace(/:$/,"");h.push(a.value),h.push(d),d=this._makeSpec.apply(this,h)}else f.test(a.name)&&(g=a.name.match(f)[3],b.each(c[g].contexts,function(b){this._makeSpec(g,b.name,"class",b.name+" "+a.value,d)},this))},this),d},_contextSpec:function(a,b){return b.hasOwnProperty(a.axis)&&b[a.axis].hasOwnProperty(a.ctx)?b[a.axis][a.ctx]:{}},_resolveSpecs:function(c,d){var e={},f=["append","prepend","before","after"];re