Skip to content
Snippets Groups Projects
Commit b90bde7f authored by Commander-lol's avatar Commander-lol
Browse files

Added the attr() mu object method, analogous to the data() method for regular attributes

parent 8ca6015d
No related branches found
No related tags found
No related merge requests found
...@@ -123,6 +123,15 @@ ...@@ -123,6 +123,15 @@
return e.getAttribute('data-' + key); return e.getAttribute('data-' + key);
} }
}, },
attr: function (key, value) {
var e = this[0];
if (typeof (value) !== 'undefined') {
e.setAttribute(key, value);
return this;
} else {
return e.getAttribute(key);
}
},
trigger: function (eventName, data, bubbles, cancelable) { trigger: function (eventName, data, bubbles, cancelable) {
bubbles = tinyDOM.exists(bubbles) ? bubbles : true; bubbles = tinyDOM.exists(bubbles) ? bubbles : true;
cancelable = tinyDOM.exists(cancelable) ? cancelable : true; cancelable = tinyDOM.exists(cancelable) ? cancelable : true;
......
!function(){"use strict";var a,b,c;Element&&!Element.prototype.matches&&(a=Element.prototype,a.matches=a.matchesSelector||a.mozMatchesSelector||a.msMatchesSelector||a.oMatchesSelector||a.webkitMatchesSelector),b=function(a){if(null===a||"undefined"==typeof a)this.length=0;else if("string"==typeof a){var c,d,b=document.querySelectorAll(a);for(this.length=b.length,c=0;c<b.length;c+=1)d=b.item(c),"undefined"==typeof d.td_prop&&(d.td_prop={isHidden:!1}),this[c]=b.item(c)}else this[0]=a,this.length=1;return this},c=function(a){return new b(a)},c.fn=b.prototype={each:function(a){for(var b=this.length;b--;)a(b,this[b],this);return this},hide:function(){return this.each(function(a,b){b.td_prop.isHidden||(b.style.td_previousDisplay=b.style.display,b.style.display="none",b.td_prop.isHidden=!0)}),this},show:function(){return this.each(function(a,b){b.td_prop.isHidden===!0&&(b.style.display="undefined"!=typeof b.style.td_previousDisplay?b.style.td_previousDisplay:"block",b.td_prop.isHidden=!1)}),this},on:function(a,b,c){return"string"==typeof b?this.each(function(d,e){e.addEventListener(a,function(a){var d=a.target,f=!1;do d&&d.matches(b)?(c.call(d,a),f=!0):(d=d.parentNode,d&&d.matches&&d!==e||(f=!0));while(f!==!0)})}):(c=b,this.each(function(b,d){d.addEventListener(a,c)})),this},first:function(){return"undefined"!=typeof this[0]?this[0]:null},data:function(a,b){var c=this[0];return"undefined"!=typeof b?(c.setAttribute("data-"+a,b),this):c.getAttribute("data-"+a)},trigger:function(a,b,d,e){d=c.exists(d)?d:!0,e=c.exists(e)?e:!0;var f=new CustomEvent(a,b,d,e);return this.each(function(a,b){b.dispatchEvent(f)}),this}},c.exists=function(a){return null!==a&&"undefined"!=typeof a},c.merge=function(a,b){if(this.exists(a)&&this.exists(b)){var c;for(c in b)b.hasOwnProperty(c)&&(a[c]=b[c]);return a}return null},c.byID=function(a){return c(document.getElementById(a))},c.triggerOn=function(a,b,d,e,f){e=c.exists(e)?e:!0,f=c.exists(f)?f:!0,a.dispatchEvent(new CustomEvent(b,d,e,f))},c.ajax=function(a){var d,e,b=new XMLHttpRequest,f={method:"GET",url:"",async:!0,user:null,password:null,responseType:"text",data:null,headers:[],callbacks:{}},g=function(a){return function(b){a(b.currentTarget.response,b)}};if(this.merge(f,a),b.responseType=f.responseType,this.exists(f.callbacks))for(d in f.callbacks)f.callbacks.hasOwnProperty(d)&&b.addEventListener(d,g(f.callbacks[d]));for(b.open(f.method,f.url,f.async,f.user,f.password),e=0;e<f.headers.length;e++)b.setRequestHeader(f.headers[e].header,f.headers[e].value);return b.send(f.data),b},window.μ||(window.μ=c),window.mu||(window.mu=c)}(); !function(){"use strict";var a,b,c;Element&&!Element.prototype.matches&&(a=Element.prototype,a.matches=a.matchesSelector||a.mozMatchesSelector||a.msMatchesSelector||a.oMatchesSelector||a.webkitMatchesSelector),b=function(a){if(null===a||"undefined"==typeof a)this.length=0;else if("string"==typeof a){var c,d,b=document.querySelectorAll(a);for(this.length=b.length,c=0;c<b.length;c+=1)d=b.item(c),"undefined"==typeof d.td_prop&&(d.td_prop={isHidden:!1}),this[c]=b.item(c)}else this[0]=a,this.length=1;return this},c=function(a){return new b(a)},c.fn=b.prototype={each:function(a){for(var b=this.length;b--;)a(b,this[b],this);return this},hide:function(){return this.each(function(a,b){b.td_prop.isHidden||(b.style.td_previousDisplay=b.style.display,b.style.display="none",b.td_prop.isHidden=!0)}),this},show:function(){return this.each(function(a,b){b.td_prop.isHidden===!0&&(b.style.display="undefined"!=typeof b.style.td_previousDisplay?b.style.td_previousDisplay:"block",b.td_prop.isHidden=!1)}),this},on:function(a,b,c){return"string"==typeof b?this.each(function(d,e){e.addEventListener(a,function(a){var d=a.target,f=!1;do d&&d.matches(b)?(c.call(d,a),f=!0):(d=d.parentNode,d&&d.matches&&d!==e||(f=!0));while(f!==!0)})}):(c=b,this.each(function(b,d){d.addEventListener(a,c)})),this},first:function(){return"undefined"!=typeof this[0]?this[0]:null},data:function(a,b){var c=this[0];return"undefined"!=typeof b?(c.setAttribute("data-"+a,b),this):c.getAttribute("data-"+a)},attr:function(a,b){var c=this[0];return"undefined"!=typeof b?(c.setAttribute(a,b),this):c.getAttribute(a)},trigger:function(a,b,d,e){d=c.exists(d)?d:!0,e=c.exists(e)?e:!0;var f=new CustomEvent(a,b,d,e);return this.each(function(a,b){b.dispatchEvent(f)}),this}},c.exists=function(a){return null!==a&&"undefined"!=typeof a},c.merge=function(a,b){if(this.exists(a)&&this.exists(b)){var c;for(c in b)b.hasOwnProperty(c)&&(a[c]=b[c]);return a}return null},c.byID=function(a){return c(document.getElementById(a))},c.triggerOn=function(a,b,d,e,f){e=c.exists(e)?e:!0,f=c.exists(f)?f:!0,a.dispatchEvent(new CustomEvent(b,d,e,f))},c.ajax=function(a){var d,e,b=new XMLHttpRequest,f={method:"GET",url:"",async:!0,user:null,password:null,responseType:"text",data:null,headers:[],callbacks:{}},g=function(a){return function(b){a(b.currentTarget.response,b)}};if(this.merge(f,a),b.responseType=f.responseType,this.exists(f.callbacks))for(d in f.callbacks)f.callbacks.hasOwnProperty(d)&&b.addEventListener(d,g(f.callbacks[d]));for(b.open(f.method,f.url,f.async,f.user,f.password),e=0;e<f.headers.length;e++)b.setRequestHeader(f.headers[e].header,f.headers[e].value);return b.send(f.data),b},window.μ||(window.μ=c),window.mu||(window.mu=c)}();
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment