1
0
Fork 0
wmdeit_kaform/js/kube.min.js

2 lines
54 KiB
JavaScript
Raw Normal View History

2020-02-20 13:45:47 +00:00
!function(){var t={};t.settings={},t.post=function(t){return new e("post",t)},t.get=function(t){return new e("get",t)};var e=function(e,i){var s={method:e,url:"",before:function(){},success:function(){},error:function(){},data:!1,async:!0,headers:{}};this.p=this.extend(s,i),this.p=this.extend(this.p,t.settings),this.p.method=this.p.method.toUpperCase(),this.prepareData(),this.xhr=new XMLHttpRequest,this.xhr.open(this.p.method,this.p.url,this.p.async),this.setHeaders();var n="function"==typeof this.p.before?this.p.before(this.xhr):!0;n!==!1&&this.send()};e.prototype={extend:function(t,e){if(e)for(var i in e)t[i]=e[i];return t},prepareData:function(){"POST"!==this.p.method||this.isFormData()||(this.p.headers["Content-Type"]="application/x-www-form-urlencoded"),"object"!=typeof this.p.data||this.isFormData()||(this.p.data=this.toParams(this.p.data)),"GET"===this.p.method&&(this.p.url=this.p.data?this.p.url+"?"+this.p.data:this.p.url)},setHeaders:function(){this.xhr.setRequestHeader("X-Requested-With",this.p.headers["X-Requested-With"]||"XMLHttpRequest");for(var t in this.p.headers)this.xhr.setRequestHeader(t,this.p.headers[t])},isFormData:function(){return"undefined"!=typeof window.FormData&&this.p.data instanceof window.FormData},isComplete:function(){return!(this.xhr.status<200||this.xhr.status>=300&&304!==this.xhr.status)},send:function(){this.p.async?(this.xhr.onload=this.loaded.bind(this),this.xhr.send(this.p.data)):(this.xhr.send(this.p.data),this.loaded.call(this))},loaded:function(){if(this.isComplete()){var t=this.xhr.response,e=this.parseJson(t);t=e?e:t,"function"==typeof this.p.success&&this.p.success(t,this.xhr)}else"function"==typeof this.p.error&&this.p.error(this.xhr.statusText)},parseJson:function(t){try{var e=JSON.parse(t);if(e&&"object"==typeof e)return e}catch(i){}return!1},toParams:function(t){return Object.keys(t).map(function(e){return encodeURIComponent(e)+"="+encodeURIComponent(t[e])}).join("&")}};var i=[0],s="data"+ +new Date,n="is-hidden",o="is-hidden-mobile",a=function(t,e){return this.parse(t,e)};a.ready=function(t){"loading"!=document.readyState?t():document.addEventListener("DOMContentLoaded",t)},a.prototype={get dom(){return!0},get length(){return this.nodes.length},parse:function(t,e){var i,s=/^\s*<(\w+|!)[^>]*>/;if(t){if(t.dom)return this.nodes=t.nodes,t;i="string"!=typeof t?t.nodeType&&11===t.nodeType?t.childNodes:t.nodeType||t===window?[t]:t:s.test(t)?this.create(t):this._query(t,e)}else i=[];this.nodes=this._slice(i)},create:function(t){if(/^<(\w+)\s*\/?>(?:<\/\1>|)$/.test(t))return[document.createElement(RegExp.$1)];var e=[],i=document.createElement("div"),s=i.childNodes;i.innerHTML=t;for(var n=0,o=s.length;o>n;n++)e.push(s[n]);return e},add:function(t){this.nodes=this.nodes.concat(this._toArray(t))},get:function(t){return this.nodes[t||0]||!1},getAll:function(){return this.nodes},eq:function(t){return new a(this.nodes[t])},first:function(){return new a(this.nodes[0])},last:function(){return new a(this.nodes[this.nodes.length-1])},contents:function(){return this.get().childNodes},each:function(t){for(var e=this.nodes.length,i=0;e>i;i++)t.call(this,this.nodes[i].dom?this.nodes[i].get():this.nodes[i],i);return this},is:function(t){return this.filter(t).length>0},filter:function(t){var e;return void 0===t?this:(e="function"==typeof t?t:function(e){return t instanceof Node?t===e:t&&t.dom?-1!==t.nodes.indexOf(e):(e.matches=e.matches||e.msMatchesSelector||e.webkitMatchesSelector,1===e.nodeType?e.matches(t||"*"):!1)},new a(this.nodes.filter(e)))},not:function(t){return this.filter(function(e){return!new a(e).is(t||!0)})},find:function(t){var e=[];return this.each(function(i){for(var s=this._query(t||"*",i),n=0;n<s.length;n++)e.push(s[n])}),new a(e)},children:function(t){var e=[];return this.each(function(t){if(t.children)for(var i=t.children,s=0;s<i.length;s++)e.push(i[s])}),new a(e).filter(t)},parent:function(t){var e=[];return this.each(function(t){t.parentNode&&e.push(t.parentNode)}),new a(e).filter(t)},parents:function(t,e){e=this._getContext(e);var i=[];return this.each(function(s){for(va
t=t.replace(e[i],this.get(s))}return t},get:function(t){return"undefined"!=typeof this.vars[t]?this.vars[t]:""}}),r.add("service","options",{init:function(t,e,i){return this.app=t,this.utils=t.utils,"global"===e?this._build(i):this._buildElement(i)},_build:function(t){return t?this._extendFromElements(t):{}},_buildElement:function(t){return r.extend({},t.data())},_extendFromElements:function(t){return t.hasOwnProperty("append")?this.utils.extendData(t,t.append):t}}),r.add("service","response",{init:function(t){this.app=t},parse:function(t){if(""===t)return!1;var e="object"==typeof t?t:JSON.parse(t);if(void 0!==e[0])for(var i in e)this._parseItem(e[i]);else this._parseItem(e);return e},_parseItem:function(t){if("location"===t.type)top.location.href=t.data;else if("message"===t.type)this.message.show(t.data);else for(var e in t.data){var i=t.data[e],s=r.dom(e);"value"===t.type?(i=null===i||i===!1?0:i,i=i===!0?1:i,s.val(i)):"html"===t.type?(i=null===i||i===!1?"":i,s.html(this._stripslashes(i))):"addClass"===t.type?s.addClass(i):"removeClass"===t.type?s.removeClass(i):"show"===t.type?s.removeClass("is-hidden"):"hide"===t.type?s.addClass("is-hidden"):"animate"===t.type&&this.animate.run(s,i)}return t},_stripslashes:function(t){return(t+"").replace(/\0/g,"0").replace(/\\([\\'"])/g,"$1")}}),r.add("service","progress",{init:function(t){this.app=t,this.$body=t.$body,this.defaults={selector:"kube-progress",target:!1,value:100},this.$progress=!1,this.$progressBar=!1},stop:function(){if(this.$progress=!1,this.$progressBar=!1,r.dom("#"+this.params.selector).remove(),this.params.target){var t=r.dom(this.params.target);t.removeClass("is-relative")}},show:function(t){this._buildDefaults(t),this._build()},hide:function(t){this.$progress&&(this._buildDefaults(t),this.animate.run(this.$progress,"fadeOut",this.stop.bind(this)))},update:function(t){this._buildDefaults(t),this.$progress||this._build(),this._setValue()},_buildDefaults:function(t){this.params=r.extend({},this.defaults,t)},_build:function(){if(this.stop(),this.$progress=r.dom("<div>"),this.$progress.attr("id",this.params.selector),this.$progress.addClass(this.params.selector),this.$progressBar=r.dom("<span>"),this.$progress.append(this.$progressBar),this.params.target){var t=r.dom(this.params.target);"static"===t.css("position")&&t.addClass("is-relative"),t.append(this.$progress)}else this.$progress.addClass("is-fixed"),this.$body.append(this.$progress)},_setValue:function(){this.$progressBar.css("width",this.params.value+"%")}}),r.add("service","message",{init:function(t){this.app=t,this.defaults={name:!1,delay:7,message:"",position:"right",positions:["is-left","is-right","is-center","is-centered","is-line"],type:!1,types:["is-error","is-success","is-focus","is-black"],selector:"kube-message"},this.currentAnimation=[],this.animation={line:["slideInDown","slideOutUp"],centered:["slideInDown","slideOutUp"],left:["slideInLeft","slideOutLeft"],right:["slideInRight","slideOutRight"]},this.$message=!1,this.timeout=!1},stop:function(){clearTimeout(this.timeout),r.dom("#"+this.params.selector).remove(),this.$message=!1,this.$doc.off(".kube.message")},show:function(t){this._buildDefaults(t),this.stop(),this._build(),this._open()},hide:function(t){this._buildDefaults(t),this._close()},_broadcast:function(t){t="message."+t,t=this.params.name!==!1?[this.params.name,t]:t,this.app.broadcast(t,this)},_buildDefaults:function(t){this.params=r.extend({},this.defaults,t)},_buildAnimation:function(){this.currentAnimation=this.animation[this.params.position]},_buildClose:function(){this.$message.on("click.kube.message",this._close.bind(this))},_buildType:function(){this.params.type&&(this.$message.removeClass(this.params.types.join(" ")),this.$message.addClass(this.params.type))},_buildPosition:function(){this.$message.removeClass(this.params.positions.join(" ")),this.$message.addClass("is-"+this.params.position)},_buildMessage:function(){this.$message.html(this.params.message)},_build:function(){this.$message=r.dom("<div>"),this.$message.attr("id",this.params.selector),this.$message.addClass("mes