-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpluggable.min.js
More file actions
1 lines (1 loc) · 2.2 KB
/
pluggable.min.js
File metadata and controls
1 lines (1 loc) · 2.2 KB
1
function pluggable(){var n=this;n.filters={},n.merged_filters={},n.current_filter=[],n.logging=!1,n.add_filter=function(t,i,r,e){if(void 0===r)r=10;if(void 0===e)e=1;if("string"==typeof i||"function"==typeof i){n.logging&&console.log("ADDING FILTER `"+String(i).substring(0,40)+"` to hook `"+t+"`");var o=n.build_unique_id(t,i,r);return void 0===n.filters[t]&&(n.filters[t]={}),void 0===n.filters[t][r]&&(n.filters[t][r]={}),n.filters[t][r][o]={function:i,accepted_args:e},delete n.merged_filters[t],!0}return n.logging&&console.warn("problem with filter on "+t+", function (parameter 2) must be passed as a string!"),!1},n.apply_filters=function(t,i,r){var e=[];if("array"==typeof r?e=e.concat(r):"object"==typeof r&&(e=r),void 0!==n.filters.all&&(n.current_filter.push(t),n.call_all_hook(e)),void 0===n.filters[t])return void 0!==n.filters.all&&n.current_filter.pop(),i;"undefined"==n.filters.all&&n.current_filter.push(t),"undefined"==n.merged_filters[t]&&(n.ksort(n.filters[t]),n.merged_filters[t]=!0);for(var o in n.filters[t])if(n.filters[t].hasOwnProperty(o)){var l=n.filters[t][o];for(var f in l)if(l.hasOwnProperty(f)){var u=l[f],s=null;if(void 0!==u.function)if(n.logging&&console.log("CALLING FUNCTION `"+String(u.function).substring(0,40)+"` to hook `"+t+"`"),"function"==typeof u.function)s=u.function(i,e);else if(u.function)if(/\./g.test(u.function)){var a=u.function.split(".");2==a.length?s=window[a[0]][a[1]](i,e):n.logging&&console.warn("WARNING: filter function `"+u.function+"` can only be at most 2 levels! ( eg: user.login NOT user.actions.login )")}else"function"==typeof window[u.function]?s=window[u.function](i,e):n.logging&&console.warn("WARNING: filter function `"+u.function+"` does not exist!");null!=s&&(i=s)}}return n.current_filter.pop(),i},n.call_all_hook=function(n){},n.build_unique_id=function(n,t,i){var r=String.fromCharCode(65+Math.floor(26*Math.random()));return Date.now=Date.now||function(){return+new Date},uniqid=r+Date.now()},n.hash_string=function(n){var t,i,r=0;if(0==n.length)return r;for(t=0,i=n.length;t<i;t++)r=(r<<5)-r+n.charCodeAt(t),r|=0;return r},n.ksort=function(n){var t=[],i=[],r=0;for(e in n)i[r++]=e;r=(i=i.sort()).length;for(var e=0;e<r;e++)t[i[e]]=n[i[e]];return t}}window.plug=new pluggable;