mirror of
https://gitea.msk.dinamika-avia.ru/Constanta-Design/MI-38.git
synced 2026-01-24 07:05:39 +03:00
33 lines
3.9 KiB
JavaScript
33 lines
3.9 KiB
JavaScript
/******************************************************************************
|
|
Magic XML by Tom Davies
|
|
-----------------------
|
|
Magically implements cross-browser code from w3schools.com/xsl/xsl_client.asp
|
|
to pull in XML data and apply a specified XSLT on marked up elements.
|
|
|
|
More details at: http://tomdavies.azurewebsites.net/magicxml/
|
|
|
|
******************************************************************************/
|
|
/*
|
|
The MIT License (MIT)
|
|
|
|
Copyright (C) 2013 - Tom Davies (tom@t-davies.com)
|
|
|
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
of this software and associated documentation files (the "Software"), to deal
|
|
in the Software without restriction, including without limitation the rights
|
|
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
copies of the Software, and to permit persons to whom the Software is
|
|
furnished to do so, subject to the following conditions:
|
|
|
|
The above copyright notice and this permission notice shall be included in
|
|
all copies or substantial portions of the Software.
|
|
|
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
THE SOFTWARE.
|
|
*/
|
|
+function(e,t,r){function n(e){return e.indexOf('<?xml version="1.0"')>=0}function a(t){var r=e.ActiveXObject||"ActiveXObject"in e?new ActiveXObject("Msxml2.XMLHTTP.3.0"):new XMLHttpRequest;return r.open("GET",t,!1),r.send(),r.responseXML}function i(e){return v.xmlStringParser.parse(e)}function c(){var t=function(){console.error("[Magic XML] No XML string parser available.")};return e.DOMParser?t=function(t){var r=new e.DOMParser;return r.parseFromString(t,"text/xml")}:e.ActiveXObject||"ActiveXObject"in e?t=function(e){var t=new ActiveXObject("Microsoft.XMLDOM");return t.async=!1,t.loadXML(e),t}:console.warn("[Magic XML] No XML string parser available. String parsing will fail if used."),{parse:t}}function o(t){if(e.ActiveXObject||"ActiveXObject"in e){var r=new ActiveXObject("MSXML2.FreeThreadedDOMDocument.6.0");return r.async=!1,r.load(t),r}return a(t)}function s(e,n,a){var i,c=0,o=new XSLTProcessor;if(o.importStylesheet(n),a!==r)for(c;c<a.length;c++)i=a[c],o.setParameter(i.xmlns!==r?i.xmlns:null,i.name,i.value);return o.transformToFragment(e,t)}function u(e,t,n){var a,i=0,c=new ActiveXObject("MSXML2.XSLTemplate.6.0");if(c.stylesheet=t,a=c.createProcessor(),a.input=e,n!==r)for(i;i<n.length;i++)parameter=n[i],a.addParameter(parameter.name,parameter.value,parameter.xmlns);return a.transform(),a.output}var l,m,f=0,v={xmlSourceAttribute:"data-xml",xslSourceAttribute:"data-xslt",xslParamAttribute:"data-xsl-params",xmlStringParser:c()},b={configure:function(e,t,r,n){"string"==typeof e&&(v.xmlSourceAttribute=e),"string"==typeof t&&(v.xslSourceAttribute=t),"string"==typeof r&&(v.xslParamAttribute=r),"function"==typeof n&&(v.xmlStringParser=n)},transform:function(t,r,c){var l=n(t)?i(t):a(t),m=n(r)?i(r):o(r);return e.ActiveXObject||"ActiveXObject"in e?u(l,m,c):s(l,m,c)},transformAndReplace:function(r,n,a,i){var c=b.transform(n,a,i);"string"==typeof r&&(r=t.querySelector(r)),e.ActiveXObject||"ActiveXObject"in e?r.innerHTML=c:r.parentNode.replaceChild(c,r)},parse:function(e){"string"!=typeof e&&(e="");var n=t.querySelectorAll(e+"["+v.xmlSourceAttribute+"]["+v.xslSourceAttribute+"]");for(f=0;f<n.length;f++)m=r,l=n[f],l.attributes[v.xslParamAttribute]&&(m=JSON.parse(l.attributes[v.xslParamAttribute].value)),b.transformAndReplace(l,l.attributes[v.xmlSourceAttribute].value,l.attributes[v.xslSourceAttribute].value,m);0===n.length&&console.warn("[Magic XML] No magic detected on page, is script loaded after all DOM elements?")}};e.magicXML=b}(window,document); |