Initial dev repository
[kcls-web.git] / opac / extras / mobile / js / plugin.js
diff --git a/opac/extras/mobile/js/plugin.js b/opac/extras/mobile/js/plugin.js
new file mode 100644 (file)
index 0000000..6bac918
--- /dev/null
@@ -0,0 +1,6 @@
+var __hasProp=Object.prototype.hasOwnProperty,__bind=function(i,f){return function(){return i.apply(f,arguments)}};
+module("plugin",imports("eg.eg_api"),function(i){var f;$.fn.plugin=function(a){return a?this.addClass("plugin "+a):this.hasClass("plugin")};f={};$.fn.subscribe=function(a,b){f[a]=typeof f[a]!=="undefined"&&f[a]!==null?f[a]:[];f[a].push({plugin:this,cb:b});return this};$.fn.publish=function(a,b){var c,d,g,h,e;if(f[a]===undefined)return this;d=f[a];c=0;for(g=d.length;c<g;c++){e=d[c];if(e.plugin){if(!$.contains(document,e.plugin.get(0)))return e.plugin=null;h=typeof b!=="undefined"&&b!==null?e.cb.apply(e.plugin,
+b):e.cb.apply(e.plugin);h!==false&&e.plugin.trigger("_",[h])}}return this};$.fn.refresh=function(a){typeof a==="function"?this.bind("_",function(b,c){var d;if(c!=="show_tab")d=a.apply($(this),Array.prototype.slice.call(arguments,1));if(d===false)return false;if(b.isPropagationStopped())return $(this).parent().trigger("_",["show_tab"])}):this.triggerHandler("_");return this};$.fn.loading=function(a){this.find(".failed").remove();return this.append($("<span>").addClass("loading").text("Loading "+a+
+"..."))};$.fn.succeeded=function(){this.find(".loading").remove();return this};$.fn.failed=function(a){if(a){this.find(".loading, .failed").remove();return this.append($("<span>").addClass("failed").text("Failed to get "+a+". Try again."))}else return this.find(".failed").length};this.isEmpty=function(a){var b,c;b=[];for(c in a)__hasProp.call(a,c)&&b.push(1);return!b.length};$.fn.openils=function(a,b){var c,d,g;g=function(){};d=__bind(function(h){var e;return typeof(e=h.ilsevent)!=="undefined"&&e!==
+null||h instanceof Error?this.failed(a):g.call(this.succeeded(),h)},this);this.loading(a);if((c=arguments.length)===4){g=arguments[3];c=i.openils(b,arguments[2],d)}else if(c===3){g=arguments[2];c=i.openils(b,d)}else return this.failed(a).publish("prompt",["Client error","Malformed service method "+b]);$.isArray(c)&&this.failed(a).publish("prompt",["Client error","Undefined service method "+b]);return this};$.fn.parallel=function(a,b,c){this.loading(a);return parallel(b).next(__bind(function(d){var g;
+for(g in b)if(__hasProp.call(b,g))if(d.k instanceof Error)return this.failed(a);return c.call(this.succeeded(),d)},this)).error(__bind(function(){if(!this.failed())return this.failed(a)},this))};return this});