forked from inkling/backbone.native
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbackbone.native.min.js
More file actions
1 lines (1 loc) · 3.47 KB
/
backbone.native.min.js
File metadata and controls
1 lines (1 loc) · 3.47 KB
1
(function(){"use strict";function e(e){e[s]||(e[s]=0===u.length?++c:u.pop());var t=e[s];return l[t]||(l[t]=[])}function t(e){var t=e[s];l[t]&&(l[t]=null,e[s]=null,u.push(t))}function n(t,n,r,o){"function"==typeof r&&(o=r,r=null);var s=i.exec(n);n=s[1]||null;var c=s[2]||null;if(n){var l=o,u=o;l=r?function(e){for(var n=e.target;n&&n!==t;n=n.parentElement)if(a.call(n,r)){var o=u.call(n,e,n);return o===!1&&(e.stopPropagation(),e.preventDefault()),o}}:function(e){var n=u.call(t,e,t);return n===!1&&(e.stopPropagation(),e.preventDefault()),n},t.addEventListener(n,l,!1),e(t).push({eventName:n,callback:o,handler:l,namespace:c,selector:r})}}function r(n,r,o,a){"function"==typeof o&&(a=o,o=null);var s=i.exec(r||"");r=s[1];var c=s[2],l=e(n)||[];if(r||c||o||a){var u=l.filter(function(e){return!(c&&e.namespace!==c||r&&e.eventName!==r||a&&e.callback!==a||o&&e.selector!==o)});u.forEach(function(e){n.removeEventListener(e.eventName,e.handler,!1),l.splice(l.indexOf(e),1)}),0===l.length&&t(n)}else l.forEach(function(e){n.removeEventListener(e.eventName,e.handler,!1)}),t(n)}function o(e,t){if(t=t||document,!(this instanceof o))return new o(e,t);if(e)if("string"==typeof e)if(/^\s*</.test(e)){var n=document.createElement("div");n.innerHTML=e,this[0]=n.firstChild,n.removeChild(n.firstChild),this.length=1}else e=t.querySelector(e),null!==e?(this[0]=e,this.length=1):this.length=0;else this[0]=e,this.length=1;else this.length=0}var i=/^([^.]+)?(?:\.([^.]+))?$/,a=Element.prototype.matchesSelector||null;a||["webkit","moz","o","ms"].forEach(function(e){var t=Element.prototype[e+"MatchesSelector"];t&&(a=t)});var s="backboneNativeKey"+Math.random(),c=1,l={},u=[];if(o.prototype={hide:null,appendTo:null,find:null,attr:function(e){return Object.keys(e).forEach(function(t){switch(t){case"html":this[0].innerHTML=e[t];break;case"text":this[0].textContent=e[t];break;case"class":this[0].className=e[t];break;default:this[0].setAttribute(t,e[t])}},this),this},html:function(e){return this[0].innerHTML=e,this},remove:function(){var e=this[0];return e.parentElement&&e.parentElement.removeChild(e),function t(e){r(e);for(var n=0,o=e.childNodes.length;o>n;n++)e.childNodes[n].nodeType!==Node.TEXT_NODE&&t(e.childNodes[n])}(e),this},on:function(e,t,r){return n(this[0],e,t,r),this},off:function(e,t,n){return r(this[0],e,t,n),this},bind:function(e,t){return this.on(e,t)},unbind:function(e,t){return this.off(e,t)},delegate:function(e,t,n){return this.on(t,e,n)},undelegate:function(e,t,n){return this.off(t,e,n)}},o.ajax=function(e){e=e||{};var t=e.type||"GET",n=e.url,r=void 0===e.processData?!0:!!e.processData,o=e.data;if(r&&"object"==typeof o){var i=Object.keys(o).map(function(e){return encodeURIComponent(e)+"="+encodeURIComponent(o[e])});o=i.join("&")}!o||"GET"!==t&&"HEAD"!==t||(n+=(-1===n.indexOf("?")?"?":"&")+o,o=void 0);var a=new XMLHttpRequest;return a.open(t,n,!0),e.contentType&&a.setRequestHeader("Content-Type",e.contentType),e.beforeSend&&e.beforeSend(a),a.onload=function(){var t=!1,n=a.responseText;if("json"===e.dataType)try{n=JSON.parse(n)}catch(r){t=!0}!t&&a.status>=200&&300>a.status?e.success&&e.success(n,a.statusText,a):e.error&&e.error(a)}.bind(this),a.onerror=a.onabort=function(){e.error&&e.error(a)},a.send(o),a},o.on=n,o.off=r,"undefined"!=typeof exports)module.exports=o;else{var f=this,h=f.Backbone?f.Backbone.Native:null,d=f.$;f.Backbone&&(f.Backbone.Native=o),f.$=o,o.noConflict=function(e){return f.$=d,e&&(f.Backbone.Native=h),o},f.Backbone&&(f.Backbone.setDomLibrary?f.Backbone.setDomLibrary(o):f.Backbone.$=o)}}).call(this);