/** * Modules in this bundle * @license * * smartphoto: * license: MIT (http://opensource.org/licenses/MIT) * author: appleple * homepage: http://developer.a-blogcms.jp * version: 1.6.4 * * a-template: * license: MIT (http://opensource.org/licenses/MIT) * author: steelydylan * version: 0.6.1 * * custom-event-polyfill: * license: MIT (http://opensource.org/licenses/MIT) * contributors: Frank Panetta, Mikhail Reenko , Joscha Feth * homepage: https://github.com/krambuhl/custom-event-polyfill#readme * version: 0.3.0 * * es6-promise-polyfill: * license: MIT (http://opensource.org/licenses/MIT) * author: Roman Dvornov * homepage: https://github.com/lahmatiy/es6-promise-polyfill#readme * version: 1.2.0 * * ie-array-find-polyfill: * license: MIT (http://opensource.org/licenses/MIT) * author: Carlos Abdalla * homepage: https://github.com/abdalla/ie-array-find-polyfill#readme * version: 1.1.0 * * morphdom: * license: MIT (http://opensource.org/licenses/MIT) * author: Patrick Steele-Idem * homepage: https://github.com/patrick-steele-idem/morphdom#readme * version: 2.5.12 * * process: * license: MIT (http://opensource.org/licenses/MIT) * author: Roman Shtylman * homepage: https://github.com/shtylman/node-process#readme * version: 0.11.10 * * timers-browserify: * licenses: MIT (http://opensource.org/licenses/MIT) * author: J. Ryan Stinnett * contributors: Guy Bedford , Ionut-Cristian Florescu , James Halliday , Jan Schär , Johannes Ewald , Jonathan Prins , Matt Esch * homepage: https://github.com/jryans/timers-browserify * version: 1.4.2 * * This header is generated by licensify (https://github.com/twada/licensify) */ (function(f){if(typeof exports==="object"&&typeof module!=="undefined"){module.exports=f()}else if(typeof define==="function"&&define.amd){define([],f)}else{var g;if(typeof window!=="undefined"){g=window}else if(typeof global!=="undefined"){g=global}else if(typeof self!=="undefined"){g=self}else{g=this}g.SmartPhoto = f()}})(function(){var define,module,exports;return (function(){function r(e,n,t){function o(i,f){if(!n[i]){if(!e[i]){var c="function"==typeof require&&require;if(!f&&c)return c(i,!0);if(u)return u(i,!0);var a=new Error("Cannot find module '"+i+"'");throw a.code="MODULE_NOT_FOUND",a}var p=n[i]={exports:{}};e[i][0].call(p.exports,function(r){var n=e[i][1][r];return o(n||r)},p,p.exports,r,e,n,t)}return n[i].exports}for(var u="function"==typeof require&&require,i=0;i { // const d = new $.Deferred(); // promises.push(d); // const src = selector(`#${template}`).getAttribute('src'); // $.ajax({ // url: src, // type: 'GET', // dataType: 'text' // }).success((data) => { // selector(`#${template}`).innerHTML = data; // d.resolve(); // }); // }); // return $.when(...promises); // } }, { key: 'getData', value: function getData() { return JSON.parse(JSON.stringify(this.data)); } }, { key: 'saveData', value: function saveData(key) { var data = JSON.stringify(this.data); localStorage.setItem(key, data); } }, { key: 'setData', value: function setData(opt) { var _this4 = this; Object.keys(opt).forEach(function (key) { if (typeof opt[key] !== 'function') { _this4.data[key] = opt[key]; } }); } }, { key: 'loadData', value: function loadData(key) { var data = JSON.parse(localStorage.getItem(key)); if (data) { this.setData(data); } } }, { key: 'getRand', value: function getRand(a, b) { return ~~(Math.random() * (b - a + 1)) + a; } }, { key: 'getRandText', value: function getRandText(limit) { var ret = ''; var strings = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789'; var length = strings.length; for (var i = 0; i < limit; i += 1) { ret += strings.charAt(Math.floor(this.getRand(0, length))); } return ret; } }, { key: 'getDataFromObj', value: function getDataFromObj(s, o) { s = s.replace(/\[([\w\-\.ぁ-んァ-ヶ亜-熙]+)\]/g, '.$1'); // convert indexes to properties s = s.replace(/^\./, ''); // strip leading dot var a = s.split('.'); while (a.length) { var n = a.shift(); if (n in o) { o = o[n]; } else { return null; } } return o; } }, { key: 'getDataByString', value: function getDataByString(s) { var o = this.data; return this.getDataFromObj(s, o); } }, { key: 'updateDataByString', value: function updateDataByString(path, newValue) { var object = this.data; var stack = path.split('.'); while (stack.length > 1) { object = object[stack.shift()]; } object[stack.shift()] = newValue; } }, { key: 'removeDataByString', value: function removeDataByString(path) { var object = this.data; var stack = path.split('.'); while (stack.length > 1) { object = object[stack.shift()]; } var shift = stack.shift(); if (shift.match(/^\d+$/)) { object.splice(Number(shift), 1); } else { delete object[shift]; } } }, { key: 'resolveBlock', value: function resolveBlock(html, item, i) { var that = this; var touchs = html.match(//g); var touchnots = html.match(//g); var exists = html.match(//g); var empties = html.match(//g); /* タッチブロック解決*/ if (touchs) { for (var k = 0, n = touchs.length; k < n; k += 1) { var start = touchs[k]; start = start.replace(/([\w\-\.ぁ-んァ-ヶ亜-熙]+):touch#([\w\-\.ぁ-んァ-ヶ亜-熙]+)/, '($1):touch#($2)'); var end = start.replace(/BEGIN/, 'END'); var reg = new RegExp(start + '(([\\n\\r\\t]|.)*?)' + end, 'g'); html = html.replace(reg, function (m, key2, val, next) { var itemkey = typeof item[key2] === 'function' ? item[key2].apply(that) : that.getDataFromObj(key2, item); if ('' + itemkey === val) { return next; } return ''; }); } } /* タッチノットブロック解決*/ if (touchnots) { for (var _k = 0, _n = touchnots.length; _k < _n; _k += 1) { var _start = touchnots[_k]; _start = _start.replace(/([\w\-\.ぁ-んァ-ヶ亜-熙]+):touchnot#([\w\-\.ぁ-んァ-ヶ亜-熙]+)/, '($1):touchnot#($2)'); var _end = _start.replace(/BEGIN/, 'END'); var _reg = new RegExp(_start + '(([\\n\\r\\t]|.)*?)' + _end, 'g'); html = html.replace(_reg, function (m, key2, val, next) { var itemkey = typeof item[key2] === 'function' ? item[key2].apply(that) : that.getDataFromObj(key2, item); if ('' + itemkey !== val) { return next; } return ''; }); } } /* existブロックを解決*/ if (exists) { for (var _k2 = 0, _n2 = exists.length; _k2 < _n2; _k2 += 1) { var _start2 = exists[_k2]; _start2 = _start2.replace(/([\w\-\.ぁ-んァ-ヶ亜-熙]+):exist/, '($1):exist'); var _end2 = _start2.replace(/BEGIN/, 'END'); var _reg2 = new RegExp(_start2 + '(([\\n\\r\\t]|.)*?)' + _end2, 'g'); html = html.replace(_reg2, function (m, key2, next) { var itemkey = typeof item[key2] === 'function' ? item[key2].apply(that) : that.getDataFromObj(key2, item); if (itemkey || itemkey === 0) { return next; } return ''; }); } } /* emptyブロックを解決*/ if (empties) { for (var _k3 = 0, _n3 = empties.length; _k3 < _n3; _k3 += 1) { var _start3 = empties[_k3]; _start3 = _start3.replace(/([\w\-\.ぁ-んァ-ヶ亜-熙]+):empty/, '($1):empty'); var _end3 = _start3.replace(/BEGIN/, 'END'); var empty = new RegExp(_start3 + '(([\\n\\r\\t]|.)*?)' + _end3, 'g'); html = html.replace(empty, function (m, key2, next) { var itemkey = typeof item[key2] === 'function' ? item[key2].apply(that) : that.getDataFromObj(key2, item); if (!itemkey && itemkey !== 0) { return next; } return ''; }); } } /* 変数解決*/ html = html.replace(/{([\w\-\.ぁ-んァ-ヶ亜-熙]+)}(\[([\w\-\.ぁ-んァ-ヶ亜-熙]+)\])*/g, function (n, key3, key4, converter) { var data = void 0; if ('' + key3 === 'i') { data = i; } else if (item[key3] || item[key3] === 0) { if (typeof item[key3] === 'function') { data = item[key3].apply(that); } else { data = item[key3]; } } else { if (converter && that.convert && that.convert[converter]) { return that.convert[converter].call(that, ''); } return ''; } if (converter && that.convert && that.convert[converter]) { return that.convert[converter].call(that, data); } return data; }); return html; } /* 絶対パス形式の変数を解決*/ }, { key: 'resolveAbsBlock', value: function resolveAbsBlock(html) { var that = this; html = html.replace(/{(.*?)}/g, function (n, key3) { var data = that.getDataByString(key3); if (typeof data !== 'undefined') { if (typeof data === 'function') { return data.apply(that); } return data; } return n; }); return html; } }, { key: 'resolveInclude', value: function resolveInclude(html) { var include = //g; html = html.replace(include, function (m, key) { return (0, _util.selector)('#' + key).innerHTML; }); return html; } }, { key: 'resolveWith', value: function resolveWith(html) { var width = /(([\n\r\t]|.)*?)/g; html = html.replace(width, function (m, key) { m = m.replace(/data\-bind=['"](.*?)['"]/g, 'data-bind=\'' + key + '.$1\''); return m; }); return html; } }, { key: 'resolveLoop', value: function resolveLoop(html) { var loop = /(([\n\r\t]|.)*?)/g; var that = this; /* ループ文解決*/ html = html.replace(loop, function (m, key, val) { var keyItem = that.getDataByString(key); var keys = []; if (typeof keyItem === 'function') { keys = keyItem.apply(that); } else { keys = keyItem; } var ret = ''; if (keys instanceof Array) { for (var i = 0, n = keys.length; i < n; i += 1) { ret += that.resolveBlock(val, keys[i], i); } } /* エスケープ削除*/ ret = ret.replace(/\\([^\\])/g, '$1'); return ret; }); return html; } }, { key: 'removeData', value: function removeData(arr) { var data = this.data; Object.keys(data).forEach(function (i) { for (var t = 0, n = arr.length; t < n; t += 1) { if (i === arr[t]) { delete data[i]; } } }); return this; } }, { key: 'hasLoop', value: function hasLoop(txt) { var loop = /(([\n\r\t]|.)*?)/g; if (txt.match(loop)) { return true; } return false; } }, { key: 'getHtml', value: function getHtml(query, row) { var template = this.atemplate.find(function (item) { return item.id === query; }); var html = ''; if (template && template.html) { html = template.html; } if (row) { html = query; } if (!html) { return ''; } var data = this.data; /* インクルード解決*/ html = this.resolveInclude(html); /* with解決*/ html = this.resolveWith(html); /* ループ解決*/ while (this.hasLoop(html)) { html = this.resolveLoop(html); } /* 変数解決*/ html = this.resolveBlock(html, data); /* エスケープ削除*/ html = html.replace(/\\([^\\])/g, '$1'); /* 絶対パスで指定された変数を解決*/ html = this.resolveAbsBlock(html); /* 空行削除*/ return html.replace(/^([\t ])*\n/gm, ''); } }, { key: 'update', value: function update() { var _this5 = this; var renderWay = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 'html'; var part = arguments[1]; var templates = this.templates; if (this.beforeUpdated) { this.beforeUpdated(); } var _loop = function _loop(i, n) { var tem = templates[i]; var query = '#' + tem; var html = _this5.getHtml(tem); var target = (0, _util.selector)('[data-id=\'' + tem + '\']'); if (!target) { (0, _util.selector)(query).insertAdjacentHTML('afterend', '
'); if (renderWay === 'text') { (0, _util.selector)('[data-id=\'' + tem + '\']').innerText = html; } else { (0, _util.selector)('[data-id=\'' + tem + '\']').innerHTML = html; } } else if (renderWay === 'text') { target.innerText = html; } else if (part) { var doc = document.createElement('div'); doc.innerHTML = html; var partHtml = doc.querySelector(part).outerHTML; (0, _morphdom2.default)(target.querySelector(part), partHtml); } else { (0, _morphdom2.default)(target, '
' + html + '
'); } var template = _this5.atemplate.find(function (item) { return item.id === tem; }); if (!template.binded) { template.binded = true; _this5.addDataBind((0, _util.selector)('[data-id=\'' + tem + '\']')); _this5.addActionBind((0, _util.selector)('[data-id=\'' + tem + '\']')); } }; for (var i = 0, n = templates.length; i < n; i += 1) { _loop(i, n); } this.updateBindingData(part); if (this.onUpdated) { this.onUpdated(part); } return this; } }, { key: 'updateBindingData', value: function updateBindingData(part) { var _this6 = this; var templates = this.templates; for (var i = 0, n = templates.length; i < n; i += 1) { var temp = templates[i]; var _template = (0, _util.selector)('[data-id=\'' + temp + '\']'); if (part) { _template = _template.querySelector(part); } var binds = _template.querySelectorAll('[data-bind]'); [].forEach.call(binds, function (item) { var data = _this6.getDataByString(item.getAttribute('data-bind')); if (item.getAttribute('type') === 'checkbox' || item.getAttribute('type') === 'radio') { if (data === item.value) { item.checked = true; } } else { // if(item !== document.activeElement) { item.value = data; // } } }); var onewaybinds = _template.querySelectorAll('[data-bind-oneway]'); [].forEach.call(onewaybinds, function (item) { var data = _this6.getDataByString(item.getAttribute('data-bind-oneway')); if (item.getAttribute('type') === 'checkbox' || item.getAttribute('type') === 'radio') { if (data === item.value) { item.checked = true; } } else { // if(item !== document.activeElement) { item.value = data; // } } }); } return this; } }, { key: 'applyMethod', value: function applyMethod(method) { var _method2; for (var _len = arguments.length, args = Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) { args[_key - 1] = arguments[_key]; } return (_method2 = this.method)[method].apply(_method2, args); } }, { key: 'getComputedProp', value: function getComputedProp(prop) { return this.data[prop].apply(this); } }, { key: 'remove', value: function remove(path) { var object = this.data; var stack = path.split('.'); while (stack.length > 1) { object = object[stack.shift()]; } var shift = stack.shift(); if (shift.match(/^\d+$/)) { object.splice(Number(shift), 1); } else { delete object[shift]; } return this; } }]); return aTemplate; }(); exports.default = aTemplate; module.exports = exports['default']; },{"./util":2,"ie-array-find-polyfill":5,"morphdom":6}],2:[function(require,module,exports){ 'use strict'; Object.defineProperty(exports, "__esModule", { value: true }); var matches = exports.matches = function matches(element, query) { var matches = (element.document || element.ownerDocument).querySelectorAll(query); var i = matches.length; while (--i >= 0 && matches.item(i) !== element) {} return i > -1; }; var selector = exports.selector = function selector(_selector) { return document.querySelector(_selector); }; var findAncestor = exports.findAncestor = function findAncestor(element, selector) { if (typeof element.closest === 'function') { return element.closest(selector) || null; } while (element && element !== document) { if (matches(element, selector)) { return element; } element = element.parentElement; } return null; }; var listenerList = []; var on = exports.on = function on(element, query, eventNames, fn) { var capture = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : false; var events = eventNames.split(' '); events.forEach(function (event) { var listener = function listener(e) { var delegateTarget = findAncestor(e.target, query); if (delegateTarget) { e.delegateTarget = delegateTarget; fn(e); } }; listenerList.push({ listener: listener, element: element, query: query, event: event, capture: capture }); element.addEventListener(event, listener, capture); }); }; var off = exports.off = function off(element, query, eventNames) { var events = eventNames.split(' '); events.forEach(function (event) { listenerList.forEach(function (item, index) { if (item.element === element && item.query === query && item.event === event) { element.removeEventListener(event, item.listener, item.capture); listenerList.splice(index, 1); } }); }); }; },{}],3:[function(require,module,exports){ // Polyfill for creating CustomEvents on IE9/10/11 // code pulled from: // https://github.com/d4tocchini/customevent-polyfill // https://developer.mozilla.org/en-US/docs/Web/API/CustomEvent#Polyfill try { var ce = new window.CustomEvent('test'); ce.preventDefault(); if (ce.defaultPrevented !== true) { // IE has problems with .preventDefault() on custom events // http://stackoverflow.com/questions/23349191 throw new Error('Could not prevent default'); } } catch(e) { var CustomEvent = function(event, params) { var evt, origPrevent; params = params || { bubbles: false, cancelable: false, detail: undefined }; evt = document.createEvent("CustomEvent"); evt.initCustomEvent(event, params.bubbles, params.cancelable, params.detail); origPrevent = evt.preventDefault; evt.preventDefault = function () { origPrevent.call(this); try { Object.defineProperty(this, 'defaultPrevented', { get: function () { return true; } }); } catch(e) { this.defaultPrevented = true; } }; return evt; }; CustomEvent.prototype = window.Event.prototype; window.CustomEvent = CustomEvent; // expose definition to window } },{}],4:[function(require,module,exports){ (function (global,setImmediate){ (function(global){ // // Check for native Promise and it has correct interface // var NativePromise = global['Promise']; var nativePromiseSupported = NativePromise && // Some of these methods are missing from // Firefox/Chrome experimental implementations 'resolve' in NativePromise && 'reject' in NativePromise && 'all' in NativePromise && 'race' in NativePromise && // Older version of the spec had a resolver object // as the arg rather than a function (function(){ var resolve; new NativePromise(function(r){ resolve = r; }); return typeof resolve === 'function'; })(); // // export if necessary // if (typeof exports !== 'undefined' && exports) { // node.js exports.Promise = nativePromiseSupported ? NativePromise : Promise; exports.Polyfill = Promise; } else { // AMD if (typeof define == 'function' && define.amd) { define(function(){ return nativePromiseSupported ? NativePromise : Promise; }); } else { // in browser add to global if (!nativePromiseSupported) global['Promise'] = Promise; } } // // Polyfill // var PENDING = 'pending'; var SEALED = 'sealed'; var FULFILLED = 'fulfilled'; var REJECTED = 'rejected'; var NOOP = function(){}; function isArray(value) { return Object.prototype.toString.call(value) === '[object Array]'; } // async calls var asyncSetTimer = typeof setImmediate !== 'undefined' ? setImmediate : setTimeout; var asyncQueue = []; var asyncTimer; function asyncFlush(){ // run promise callbacks for (var i = 0; i < asyncQueue.length; i++) asyncQueue[i][0](asyncQueue[i][1]); // reset async asyncQueue asyncQueue = []; asyncTimer = false; } function asyncCall(callback, arg){ asyncQueue.push([callback, arg]); if (!asyncTimer) { asyncTimer = true; asyncSetTimer(asyncFlush, 0); } } function invokeResolver(resolver, promise) { function resolvePromise(value) { resolve(promise, value); } function rejectPromise(reason) { reject(promise, reason); } try { resolver(resolvePromise, rejectPromise); } catch(e) { rejectPromise(e); } } function invokeCallback(subscriber){ var owner = subscriber.owner; var settled = owner.state_; var value = owner.data_; var callback = subscriber[settled]; var promise = subscriber.then; if (typeof callback === 'function') { settled = FULFILLED; try { value = callback(value); } catch(e) { reject(promise, e); } } if (!handleThenable(promise, value)) { if (settled === FULFILLED) resolve(promise, value); if (settled === REJECTED) reject(promise, value); } } function handleThenable(promise, value) { var resolved; try { if (promise === value) throw new TypeError('A promises callback cannot return that same promise.'); if (value && (typeof value === 'function' || typeof value === 'object')) { var then = value.then; // then should be retrived only once if (typeof then === 'function') { then.call(value, function(val){ if (!resolved) { resolved = true; if (value !== val) resolve(promise, val); else fulfill(promise, val); } }, function(reason){ if (!resolved) { resolved = true; reject(promise, reason); } }); return true; } } } catch (e) { if (!resolved) reject(promise, e); return true; } return false; } function resolve(promise, value){ if (promise === value || !handleThenable(promise, value)) fulfill(promise, value); } function fulfill(promise, value){ if (promise.state_ === PENDING) { promise.state_ = SEALED; promise.data_ = value; asyncCall(publishFulfillment, promise); } } function reject(promise, reason){ if (promise.state_ === PENDING) { promise.state_ = SEALED; promise.data_ = reason; asyncCall(publishRejection, promise); } } function publish(promise) { var callbacks = promise.then_; promise.then_ = undefined; for (var i = 0; i < callbacks.length; i++) { invokeCallback(callbacks[i]); } } function publishFulfillment(promise){ promise.state_ = FULFILLED; publish(promise); } function publishRejection(promise){ promise.state_ = REJECTED; publish(promise); } /** * @class */ function Promise(resolver){ if (typeof resolver !== 'function') throw new TypeError('Promise constructor takes a function argument'); if (this instanceof Promise === false) throw new TypeError('Failed to construct \'Promise\': Please use the \'new\' operator, this object constructor cannot be called as a function.'); this.then_ = []; invokeResolver(resolver, this); } Promise.prototype = { constructor: Promise, state_: PENDING, then_: null, data_: undefined, then: function(onFulfillment, onRejection){ var subscriber = { owner: this, then: new this.constructor(NOOP), fulfilled: onFulfillment, rejected: onRejection }; if (this.state_ === FULFILLED || this.state_ === REJECTED) { // already resolved, call callback async asyncCall(invokeCallback, subscriber); } else { // subscribe this.then_.push(subscriber); } return subscriber.then; }, 'catch': function(onRejection) { return this.then(null, onRejection); } }; Promise.all = function(promises){ var Class = this; if (!isArray(promises)) throw new TypeError('You must pass an array to Promise.all().'); return new Class(function(resolve, reject){ var results = []; var remaining = 0; function resolver(index){ remaining++; return function(value){ results[index] = value; if (!--remaining) resolve(results); }; } for (var i = 0, promise; i < promises.length; i++) { promise = promises[i]; if (promise && typeof promise.then === 'function') promise.then(resolver(i), reject); else results[i] = promise; } if (!remaining) resolve(results); }); }; Promise.race = function(promises){ var Class = this; if (!isArray(promises)) throw new TypeError('You must pass an array to Promise.race().'); return new Class(function(resolve, reject) { for (var i = 0, promise; i < promises.length; i++) { promise = promises[i]; if (promise && typeof promise.then === 'function') promise.then(resolve, reject); else resolve(promise); } }); }; Promise.resolve = function(value){ var Class = this; if (value && typeof value === 'object' && value.constructor === Class) return value; return new Class(function(resolve){ resolve(value); }); }; Promise.reject = function(reason){ var Class = this; return new Class(function(resolve, reject){ reject(reason); }); }; })(typeof window != 'undefined' ? window : typeof global != 'undefined' ? global : typeof self != 'undefined' ? self : this); }).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {},require("timers").setImmediate) },{"timers":8}],5:[function(require,module,exports){ 'use strict'; if (!Array.prototype.find) { Object.defineProperty(Array.prototype, 'find', { value: function (predicate) { if (this == null) { throw new TypeError('this is null or not defined'); } var obj = Object(this); var len = obj.length >>> 0; if (typeof predicate !== 'function') { throw new TypeError('predicate must be a function'); } var thisArg = arguments[1]; var index = 0; while (index < len) { var iValue = obj[index]; if (predicate.call(thisArg, iValue, index, obj)) { return iValue; } index++; } return undefined; } }); } },{}],6:[function(require,module,exports){ 'use strict'; var DOCUMENT_FRAGMENT_NODE = 11; function morphAttrs(fromNode, toNode) { var toNodeAttrs = toNode.attributes; var attr; var attrName; var attrNamespaceURI; var attrValue; var fromValue; // document-fragments dont have attributes so lets not do anything if (toNode.nodeType === DOCUMENT_FRAGMENT_NODE || fromNode.nodeType === DOCUMENT_FRAGMENT_NODE) { return; } // update attributes on original DOM element for (var i = toNodeAttrs.length - 1; i >= 0; i--) { attr = toNodeAttrs[i]; attrName = attr.name; attrNamespaceURI = attr.namespaceURI; attrValue = attr.value; if (attrNamespaceURI) { attrName = attr.localName || attrName; fromValue = fromNode.getAttributeNS(attrNamespaceURI, attrName); if (fromValue !== attrValue) { if (attr.prefix === 'xmlns'){ attrName = attr.name; // It's not allowed to set an attribute with the XMLNS namespace without specifying the `xmlns` prefix } fromNode.setAttributeNS(attrNamespaceURI, attrName, attrValue); } } else { fromValue = fromNode.getAttribute(attrName); if (fromValue !== attrValue) { fromNode.setAttribute(attrName, attrValue); } } } // Remove any extra attributes found on the original DOM element that // weren't found on the target element. var fromNodeAttrs = fromNode.attributes; for (var d = fromNodeAttrs.length - 1; d >= 0; d--) { attr = fromNodeAttrs[d]; attrName = attr.name; attrNamespaceURI = attr.namespaceURI; if (attrNamespaceURI) { attrName = attr.localName || attrName; if (!toNode.hasAttributeNS(attrNamespaceURI, attrName)) { fromNode.removeAttributeNS(attrNamespaceURI, attrName); } } else { if (!toNode.hasAttribute(attrName)) { fromNode.removeAttribute(attrName); } } } } var range; // Create a range object for efficently rendering strings to elements. var NS_XHTML = 'http://www.w3.org/1999/xhtml'; var doc = typeof document === 'undefined' ? undefined : document; var HAS_TEMPLATE_SUPPORT = !!doc && 'content' in doc.createElement('template'); var HAS_RANGE_SUPPORT = !!doc && doc.createRange && 'createContextualFragment' in doc.createRange(); function createFragmentFromTemplate(str) { var template = doc.createElement('template'); template.innerHTML = str; return template.content.childNodes[0]; } function createFragmentFromRange(str) { if (!range) { range = doc.createRange(); range.selectNode(doc.body); } var fragment = range.createContextualFragment(str); return fragment.childNodes[0]; } function createFragmentFromWrap(str) { var fragment = doc.createElement('body'); fragment.innerHTML = str; return fragment.childNodes[0]; } /** * This is about the same * var html = new DOMParser().parseFromString(str, 'text/html'); * return html.body.firstChild; * * @method toElement * @param {String} str */ function toElement(str) { str = str.trim(); if (HAS_TEMPLATE_SUPPORT) { // avoid restrictions on content for things like `Hi` which // createContextualFragment doesn't support //