forked from dlueth/qoopido.js
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsupport.js
1 lines (1 loc) · 2.87 KB
/
support.js
1
(function(e,t,n,r){"use strict";var i="qoopido",s="support",o=function(){return[].push.apply(arguments,[t,n,r]),t[i]=t[i]||{},t[i][s]=e.apply(null,arguments)};typeof define=="function"&&define.amd?define(["./base","q"],o):o(t[i].base,t.Q)})(function(e,t,n,r,i){"use strict";function u(){return arguments.length>1?arguments[1].toUpperCase():arguments[0].charAt(0).toUpperCase()+arguments[0].slice(1)}var s=/-([a-z])/gi,o={prefix:null,property:{},method:{},element:{},promises:{prefix:null,property:{},method:{},test:{}}};return e.extend({test:{},testMultiple:function(){var n,r=[],s=0;for(s;(n=arguments[s])!==i;s++)switch(typeof n){case"string":r.push(this.test[n]());break;case"boolean":var o=t.defer();n?o.resolve():o.reject(),r.push(o.promise);break;default:r.push(n)}return t.all(r)},getElement:function(t,n){var i=o.element[t]=o.element[t]||t!=="image"?r.createElement(t):new Image;return n=!!n,n?i.cloneNode(!1):i},getPrefix:function(){var t,n=o.prefix||null;if(n===null){var r=this.getElement("div").style,i=/^(Moz|WebKit|Khtml|ms|O|Icab)(?=[A-Z])/;n=!1;for(t in r)i.test(t)&&(n=t.match(i)[0]);n===!1&&"WebkitOpacity"in r&&(n="WebKit"),n===!1&&"KhtmlOpacity"in r&&(n="Khtml"),n=o.prefix=n===!1?!1:{method:n,properties:[n.toLowerCase(),u(n.toLowerCase())]}}return n},getProperty:function(t){t=t.replace(s,u);var n=o.property[t]||null;if(n===null){n=!1;var r,a=0,f=this.getElement("div"),l=u(t),c=(this.getPrefix()||{properties:[]}).properties,h=(t+" "+c.join(l+" ")+l).split(" ");for(a;(r=h[a])!==i;a++)if(f.style[r]!==i){n=r;break}o.property[t]=n}return n},getMethod:function(t,r){r=r||n;var s=r.tagName,a=o.method[s]=o.method[s]||{},f=a[t]=o.method[s][t]||null;if(f===null){f=!1;var l,c,h=0,p=u(t),d=this.getPrefix();d!==!1?l=(t+" "+d.method+p+" "+d.properties.join(p+" ")+p).split(" "):l=[t];for(h;(c=l[h])!==i;h++)if(r[c]!==i&&(typeof r[c]=="function"||typeof r[c]=="object")){f=c;break}o.method[s][t]=f}return f},supportsPrefix:function(){return!!this.getPrefix()},supportsProperty:function(t){return!!this.getProperty(t)},supportsMethod:function(t,n){return!!this.getMethod(t,n)},testPrefix:function(){var n=o.promises.prefix;if(n===null){var r=t.defer(),i=this.getPrefix();i?r.resolve(i):r.reject(),n=o.promises.prefix=r.promise}return n},testProperty:function(n){var r=o.promises.property[n]||null;if(r===null){var i=t.defer(),s=this.getProperty(n);s?i.resolve(s):i.reject(),r=o.promises.property[n]=i.promise}return r},testMethod:function(r,i){i=i||n;var s=i.tagName,u=o.promises.method[s]=o.promises.method[s]||{},a=u[r]=o.promises.method[s][r]||null;if(a===null){var f=t.defer(),l=this.getMethod(r,i);l?f.resolve(l):f.reject(),a=o.promises.method[s][r]=f.promise}return a},addTest:function(n,r){return this.test[n]=function(){var e=o.promises.test[n]||null;if(e===null){var i=t.defer(),s=Array.prototype.slice.call(arguments);s.splice(0,0,i),r.apply(null,s),e=o.promises.test[n]=i.promise}return e}}})},window,document);