7 lines
13 KiB
JavaScript
7 lines
13 KiB
JavaScript
|
|
/*
|
||
|
|
* defiant.js [v1.4.1]
|
||
|
|
* http://www.defiantjs.com
|
||
|
|
* Copyright (c) 2013-2017, Hakan Bilgin <hbi@longscript.com>
|
||
|
|
* Licensed under the MIT License
|
||
|
|
*/
|
||
|
|
if(function(e,t){var n={init:function(){return this},work_handler:function(e){var t=Array.prototype.slice.call(e.data,1),n=e.data[0],r=tree[n].apply(tree,t);postMessage([n,r])},setup:function(t){var r=e.URL||e.webkitURL,a="var tree = {"+this.parse(t).join(",")+"};",s=new Blob([a+'self.addEventListener("message", '+this.work_handler.toString()+", false);"],{type:"text/javascript"}),o=new Worker(r.createObjectURL(s));return o.onmessage=function(e){var t=Array.prototype.slice.call(e.data,1),r=e.data[0];n.observer.emit("x10:"+r,t)},o},call_handler:function(e,t){return function(){var r=Array.prototype.slice.call(arguments,0,-1),a=arguments[arguments.length-1];r.unshift(e),n.observer.on("x10:"+e,function(e){a(e.detail[0])}),t.postMessage(r)}},compile:function(e){var t,n=this.setup("function"==typeof e?{func:e}:e),r={};if("function"==typeof e)return r.func=this.call_handler("func",n),r.func;for(t in e)r[t]=this.call_handler(t,n);return r},parse:function(e,n){var r,a,s,o=[];for(r in e)if(s=e[r],null!==s)if(s!==t){switch(s.constructor){case Date:a="new Date("+s.valueOf()+")";break;case Object:a="{"+this.parse(s).join(",")+"}";break;case Array:a="["+this.parse(s,!0).join(",")+"]";break;case String:a='"'+s.replace(/"/g,'\\"')+'"';break;case RegExp:case Function:a=s.toString();break;default:a=s}n?o.push(a):o.push(r+":"+a)}else o.push(r+":undefined");else o.push(r+":null");return o},observer:function(){var e={};return{on:function(t,n){e[t]||(e[t]=[]),e[t].unshift(n)},off:function(t,n){if(e[t]){var r=e[t].indexOf(n);e[t].splice(r,1)}},emit:function(t,n){if(e[t])for(var r={type:t,detail:n,isCanceled:!1,cancelBubble:function(){this.isCanceled=!0}},a=e[t].length;a--;){if(r.isCanceled)return;e[t][a](r)}}}}()};"undefined"==typeof module?e.x10=n.init():module.exports=n.init()}(this),function(e,t,n){"use strict";var r={is_ie:/(msie|trident)/i.test(navigator.userAgent),is_safari:/safari/i.test(navigator.userAgent),env:"production",xml_decl:'<?xml version="1.0" encoding="utf-8"?>',namespace:'xmlns:d="defiant-namespace"',tabsize:4,render:function(e,t){var n,r,a,s,o=new XSLTProcessor,i=document.createElement("span"),l={match:"/"};switch(typeof e){case"object":this.extend(l,e),l.data||(l.data=t);break;case"string":l.template=e,l.data=t;break;default:throw"error"}if(l.data=JSON.toXML(l.data),n='//xsl:template[@name="'+l.template+'"]',this.xsl_template||this.gatherTemplates(),l.sorter&&(s=this.node.selectSingleNode(this.xsl_template,n+"//xsl:for-each//xsl:sort"),s&&(l.sorter.order&&s.setAttribute("order",l.sorter.order),l.sorter.select&&s.setAttribute("select",l.sorter.select),s.setAttribute("data-type",l.sorter.type||"text"))),a=this.node.selectSingleNode(this.xsl_template,n),a.setAttribute("match",l.match),o.importStylesheet(this.xsl_template),i.appendChild(o.transformToFragment(l.data,document)),a.removeAttribute("match"),this.is_safari){r=i.getElementsByTagName("script");for(var c=0,u=r.length;c<u;c++)r[c].defer=!0}return i.innerHTML},gatherTemplates:function(){for(var e=document.getElementsByTagName("script"),t="",n=0,r=e.length;n<r;n++)"defiant/xsl-template"===e[n].type&&(t+=e[n].innerHTML);this.xsl_template=this.xmlFromString('<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" '+this.namespace+">"+t.replace(/defiant:(\w+)/g,"$1")+"</xsl:stylesheet>")},getSnapshot:function(e,t){return JSON.toXML(e,t||!0)},xmlFromString:function(e){var t,n;return e=e.replace(/>\s{1,}</g,"><"),null===e.trim().match(/<\?xml/)&&(e=this.xml_decl+e),"undefined"!=typeof ActiveXObject?(n=new ActiveXObject("Msxml2.DOMDocument"),n.loadXML(e),e.indexOf("xsl:stylesheet")===-1&&n.setProperty("SelectionLanguage","XPath")):(t=new DOMParser,n=t.parseFromString(e,"text/xml")),n},extend:function(e,t){for(var n in t)e[n]&&"object"==typeof t[n]?this.extend(e[n],t[n]):e[n]=t[n];return e},node:{}};e.Defiant=t.exports=r}("undefined"!=typeof window?window:{},"undefined"!=typeof module?module:{}),"undefined"==typeof XSLTProcessor){var XSLTProcessor=function(){};XSLTProcessor.prototype={importStylesheet:function(e){this.xsldoc=e},transformToFragment:functi
|