diff --git a/build/mobify.js b/build/mobify.js index b4148bb0..c8fb5f65 100644 --- a/build/mobify.js +++ b/build/mobify.js @@ -410,9 +410,10 @@ Capture.prototype.createDocumentFragments = function() { }; /** - * Returns an escaped HTML representation of the captured DOM + * Returns an HTML representation of the captured DOM with resources enabled. + * (escapedHTMLString remains for backwards compatibility) */ -Capture.prototype.escapedHTMLString = function() { +Capture.prototype.enabledHTMLString = Capture.prototype.escapedHTMLString = function() { var doc = this.capturedDoc; var html = Capture.enable(Utils.outerHTML(doc.documentElement), this.prefix); var htmlWithDoctype = this.doctype + html; @@ -423,11 +424,11 @@ Capture.prototype.escapedHTMLString = function() { * Rewrite the document with a new html string */ Capture.prototype.render = function(htmlString) { - var escapedHTMLString; + var enabledHTMLString; if (!htmlString) { - escapedHTMLString = this.escapedHTMLString(); + enabledHTMLString = this.enabledHTMLString(); } else { - escapedHTMLString = Capture.enable(htmlString, this.prefix); + enabledHTMLString = Capture.enable(htmlString, this.prefix); } var doc = this.sourceDoc; @@ -438,7 +439,7 @@ Capture.prototype.render = function(htmlString) { // Asynchronously render the new document setTimeout(function(){ doc.open("text/html", "replace"); - doc.write(escapedHTMLString); + doc.write(enabledHTMLString); doc.close(); }); }; diff --git a/build/mobify.min.js b/build/mobify.min.js index f1d1bed9..b0e34a06 100644 --- a/build/mobify.min.js +++ b/build/mobify.min.js @@ -1 +1 @@ -!function a(b,c,d){function e(g,h){if(!c[g]){if(!b[g]){var i="function"==typeof require&&require;if(!h&&i)return i(g,!0);if(f)return f(g,!0);throw new Error("Cannot find module '"+g+"'")}var j=c[g]={exports:{}};b[g][0].call(j.exports,function(a){var c=b[g][1][a];return e(c?c:a)},j,j.exports,a,b,c,d)}return c[g].exports}for(var f="function"==typeof require&&require,g=0;g":"plaintext"==d?b.textContent:"script"==d&&(/mobify/.test(b.src)||/mobify/i.test(b.textContent))?"":b.outerHTML||b.nodeValue||a.outerHTML(b)}).join(""):""}window.Mobify&&!window.Mobify.capturing&&document.getElementsByTagName("plaintext").length&&(window.Mobify.capturing=!0);var f=/()/gi,g={style:' media="mobify-media"',script:' type="text/mobify-script"'},h=new RegExp(a.values(g).join("|"),"g"),i={img:["src"],source:["src"],iframe:["src"],script:["src","type"],link:["href"],style:["media"]},j=new RegExp("<("+a.keys(i).join("|")+")([\\s\\S]*?)>","gi"),k={},l={};for(var m in i)if(i.hasOwnProperty(m)){var n=i[m];n.forEach(function(a){l[a]=!0}),k[m]=new RegExp("\\s+((?:"+n.join("|")+")\\s*=\\s*(?:('|\")[\\s\\S]+?\\2))","gi")}var o=document.createElement("div"),p=function(a,b){this.sourceDoc=a,this.prefix=b||"x-",window.Mobify&&(window.Mobify.prefix=this.prefix)};return p.init=p.initCapture=function(b,c,d){var c=c||document,e=function(b,c,d){var e=new p(c,d),f=p.createDocumentFragmentsStrings(e.sourceDoc);a.extend(e,f);var g=e.createDocumentFragments();a.extend(e,g),b(e)};if(a.domIsReady(c))e(b,c,d);else{var f=!1,g=function(){f||(f=!0,h&&clearInterval(h),e(b,c,d))},h=setInterval(function(){a.domIsReady(c)&&g()},100);c.addEventListener("readystatechange",g,!1)}},p.removeClosingTagsAtEndOfString=function(a){var b=a.match(/((<\/[^>]+>)+)$/);return b?a.substring(0,a.length-b[0].length):a},p.removeTargetSelf=function(a){return a.replace(/target=("_self"|\'_self\')/gi,"")},p.cloneAttributes=function(a,b){var c=a.match(/^<(\w+)([\s\S]*)$/i);return o.innerHTML=""}}(),d=/()|(?=<\/script)/i,e=a.split(d),h=e.map(function(a){var b;return a?/^|(<\/head\s*>|'\"]*|'[^']*?'|\"[^\"]*?\")*>)([\\s\\S]*)$").exec(captured.headContent);if(j&&(captured.headOpenTag=j[1],captured.headContent=j[2]),"/"!=i[1][1]){captured.bodyContent=i[0];var k=/^((?:[^>'"]*|'[^']*?'|"[^"]*?")*>)([\s\S]*)$/.exec(captured.bodyContent);k&&(captured.bodyOpenTag=k[1],captured.bodyContent=k[2]);break}captured.bodyContent=h.slice(i.index+i[1].length)}return captured},p.prototype.restore=function(){var b=this,c=b.sourceDoc,d=function(){c.removeEventListener("readystatechange",d,!1),setTimeout(function(){c.open(),c.write(b.all()),c.close()},15)};a.domIsReady(c)?d():c.addEventListener("readystatechange",d,!1)},p.prototype.createDocumentFragments=function(){var a={},b=a.capturedDoc=document.implementation.createHTMLDocument(""),c=a.htmlEl=b.documentElement,d=a.headEl=c.firstChild,e=a.bodyEl=c.lastChild;p.cloneAttributes(this.htmlOpenTag,c),p.cloneAttributes(this.headOpenTag,d),p.cloneAttributes(this.bodyOpenTag,e),e.innerHTML=p.disable(this.bodyContent,this.prefix);var f=b.querySelectorAll("head");if(f.length>1)for(;f[1].hasChildNodes();)f[1].removeChild(f[1].lastChild);var g=p.disable(this.headContent,this.prefix);try{d.innerHTML=g}catch(h){var i=d.getElementsByTagName("title")[0];i&&d.removeChild(i),p.setElementContentFromString(d,g)}return a},p.prototype.escapedHTMLString=function(){var b=this.capturedDoc,c=p.enable(a.outerHTML(b.documentElement),this.prefix),d=this.doctype+c;return d},p.prototype.render=function(a){var b;b=a?p.enable(a,this.prefix):this.escapedHTMLString();var c=this.sourceDoc;window.Mobify&&(window.Mobify.capturing=!1),setTimeout(function(){c.open("text/html","replace"),c.write(b),c.close()})},p.prototype.getCapturedDoc=function(){return this.capturedDoc},p.getMobifyLibrary=function(a){var a=a||document,b=a.getElementById("mobify-js");return b||(b=a.getElementsByTagName("script")[0],b.id="mobify-js",b.setAttribute("class","mobify")),b},p.getPostload=function(a){var a=a||document,b=void 0,c=window.Mobify.Tag&&window.Mobify.Tag.options&&window.Mobify.Tag.getOptions(Mobify.Tag.options)||{},d=c.post&&c.post.toString()||window.Mobify.mainExecutable;return d?(b=document.createElement("script"),b.innerHTML="var postload = "+d+"; postload();",b.id="postload",b.setAttribute("class","mobify")):b=a.getElementById("main-executable"),b},p.insertMobifyScripts=function(a,b){var c=p.getMobifyLibrary(a),d=b.head||b.getElementsByTagName("head")[0];if(d){var e=p.getPostload(a);if(e){var f=b.importNode(e,!1);e.src||(f.innerHTML=e.innerHTML),d.insertBefore(f,d.firstChild)}var g=b.importNode(c,!1);d.insertBefore(g,d.firstChild)}},p.prototype.renderCapturedDoc=function(){if(p.insertMobifyScripts(this.sourceDoc,this.capturedDoc),window.Mobify&&window.Mobify.points){var a=this.bodyEl,b=this.capturedDoc.createElement("div");b.id="mobify-point",b.setAttribute("style","display: none;"),b.innerHTML=window.Mobify.points[0],a.insertBefore(b,a.firstChild)}this.render()},p.patchAnchorLinks=b,p})},{"./patchAnchorLinks.js":5,"./utils.js":8}],2:[function(a,b,c){!function(d,e){if("function"==typeof define&&define.amd)define(["mobifyjs/utils"],e);else if("object"==typeof c){var f=a("./utils.js");b.exports=e(f)}else d.CssOptimize=e(d.Utils)}(this,function(a){var b=window.cssOptimize={};b.getCssUrl=function(b,d){var e=a.extend({},c,d),f=[e.protoAndHost];return e.projectName&&f.push("project-"+e.projectName),f.push(e.endpoint),f.push(b),f.join("/")},b._rewriteHref=function(c,d){var e,f=c.getAttribute(d.targetAttribute);f&&(e=a.absolutify(f),a.httpUrl(e)&&(c.setAttribute("data-orig-href",f),c.setAttribute(d.targetAttribute,b.getCssUrl(e,d)),d.onerror&&c.setAttribute("onerror",d.onerror)))},b.optimize=function(d,e){for(var f,g=a.extend({},c,e),h=0,i=d.length;i>h;h++)f=d[h],"LINK"===f.nodeName&&"stylesheet"===f.getAttribute("rel")&&f.getAttribute(g.targetAttribute)&&!f.hasAttribute("mobify-optimized")&&(f.setAttribute("mobify-optimized",""),b._rewriteHref(f,g))};var c=(b.restoreOriginalHref=function(a){var b;a.target.removeAttribute("onerror"),(b=a.target.getAttribute("data-orig-href"))&&a.target.setAttribute("href",b)},b._defaults={protoAndHost:"//jazzcat.mobify.com",endpoint:"cssoptimizer",projectName:"oss-"+location.hostname.replace(/[^\w]/g,"-"),targetAttribute:"x-href",onerror:"Mobify.CssOptimize.restoreOriginalHref(event);"});return b})},{"./utils.js":8}],3:[function(a,b,c){!function(d,e){if("function"==typeof define&&define.amd)define(["mobifyjs/utils"],e);else if("object"==typeof c){var f=a("./utils.js");b.exports=e(f)}else d.Jazzcat=e(d.Utils)}(this,function(a){var b={cache:{},options:{},utils:{}},c="Mobify-Jazzcat-Cache-v1.0";b.reset=function(a){b.cache=a||{}},b.get=function(a,c){var d=b.cache[a.split("#")[0]];return d&&c&&(d.lastUsed=Date.now()),d},b.set=function(a,c){b.cache[a]=c},b.load=function(a){var d,e,f=localStorage.getItem(c);if(a&&void 0!==a.overrideTime&&(e={overrideTime:a.overrideTime}),f){try{f=JSON.parse(f)}catch(g){return}for(d in f)f.hasOwnProperty(d)&&!b.utils.isStale(f[d],e)&&b.set(d,f[d])}};var d=!0;b.save=function(e){var f,g=10;return d?(d=!1,void function h(){var i=function(){var i,j,k,l=9007199254740991;f=f||a.clone(b.cache);try{j=JSON.stringify(f)}catch(m){return d=!0,e&&e(m)}try{localStorage.setItem(c,j)}catch(m){if(!--g)return d=!0,e&&e(m);for(var n in f)if(f.hasOwnProperty(n)){if(i=f[n],!i.lastUsed){k=n,l=0;break}i.lastUsed<=l&&(k=n,l=i.lastUsed)}return delete f[k],h()}d=!0,e&&e()};a.domIsReady()?i():setTimeout(h,15)}()):e&&e("Save currently in progress")};var e=/^\s*(public|private|no-cache|no-store)\s*$/,f=/^\s*(max-age)\s*=\s*(\d+)\s*$/;b.utils.ccParse=function(a){var b,c={};return a.split(",").forEach(function(a){(b=e.exec(a))?c[b[1]]=!0:(b=f.exec(a))&&(c[b[1]]=parseInt(b[2],10))}),c},b.utils.isStale=function(a,c){var d,e,f,g,h=864e5,i=a.headers||{},j=i["cache-control"],k=Date.now(),l=Date.parse(i.date),m=i["last-modified"];return l&&l+6e5>k?!1:c&&(g=c.overrideTime)&&l?k>l+60*g*1e3:j&&l?(j=b.utils.ccParse(j),!j["max-age"]||j["no-store"]||j["no-cache"]?!0:k>l+1e3*j["max-age"]):i.expires&&(d=Date.parse(i.expires))?k>d:m&&(m=Date.parse(m))&&l&&(f=l-m,e=k-l,.1*f>e&&h>e)?!1:!0};var g=window.Jazzcat={httpCache:b,write:document.write};g.isIncompatibleBrowser=function(b){var c=/(firefox)[\/\s](\d+)|(opera[\s\S]*version[\/\s](11|12))/i.exec(b||navigator.userAgent);return c&&c[1]&&+c[2]<12||c&&c[3]||!a.supportsLocalStorage()||!window.JSON?!0:!1},g.cacheLoaderInserted=!1,g.optimizeScripts=function(c,d){if(d&&void 0!==d.cacheOverrideTime&&a.extend(b.options,{overrideTime:d.cacheOverrideTime}),c=Array.prototype.slice.call(c),!c.length||g.isIncompatibleBrowser())return c;d=a.extend({},g.defaults,d||{});for(var e,f="jsonp"===d.responseType,h=d.concat,i=function(a,b){if(a){var c=g.getLoaderScript(b,d);a.parentNode.insertBefore(c,a)}},j={head:{firstScript:void 0,urls:[]},body:{firstScript:void 0,urls:[]}},k=0,l=c.length;l>k;k++){var m=c[k];if(!(m.hasAttribute("mobify-optimized")||m.hasAttribute("skip-optimize")||/mobify/i.test(m.className))&&(e=m.getAttribute(d.attribute),e&&(e=a.absolutify(e),a.httpUrl(e)))){if(f&&!g.cacheLoaderInserted){b.load(b.options);var n=g.getHttpCacheLoaderScript();m.parentNode.insertBefore(n,m),g.cacheLoaderInserted=!0}var o="HEAD"===m.parentNode.nodeName?"head":"body";if(f){if(b.get(e)||(h?(void 0===j[o].firstScript&&(j[o].firstScript=m),j[o].urls.push(e)):i(m,[e])),m.type="text/mobify-script",m.hasAttribute("onload")){var p=m.getAttribute("onload");m.innerHTML=d.execCallback+"('"+e+"', '"+p.replace(/'/g,"\\'")+"');",m.removeAttribute("onload")}else m.innerHTML=d.execCallback+"('"+e+"');";m.removeAttribute(d.attribute)}else if(h)void 0===j[o].firstScript&&(j[o].firstScript=m),j[o].urls.push(e);else{var q=g.getURL([e],d);m.setAttribute(d.attribute,q)}}}if(h&&(i(j.head.firstScript,j.head.urls),i(j.body.firstScript,j.body.urls)),!f&&h)for(var k=0,l=c.length;l>k;k++){var m=c[k];m.getAttribute(d.attribute)&&m.parentNode.removeChild(m)}return c},g.getHttpCacheLoaderScript=function(){var a=document.createElement("script");return a.type="text/mobify-script",a.innerHTML=b.options.overrideTime?"Jazzcat.httpCache.load("+JSON.stringify(b.options)+");":"Jazzcat.httpCache.load();",a},g.getLoaderScript=function(a,b){var c;return a&&a.length&&(c=document.createElement("script"),c.setAttribute("mobify-optimized",""),c.setAttribute(b.attribute,g.getURL(a,b))),c},g.getURL=function(b,c){var c=a.extend({},g.defaults,c||{});return c.base+(c.projectName?"/project-"+c.projectName:"")+"/"+c.responseType+("jsonp"===c.responseType?"/"+c.loadCallback:"")+"/"+encodeURIComponent(JSON.stringify(b.slice().sort()))};var h=/(<\/scr)(ipt\s*>)/gi;return g.exec=function(a,c){var d,e=b.get(a,!0),f="";c?(c=";"+c+";",f=' onload="'+c+'"'):c="",e?(d='data-orig-src="'+a+'"',d+=">"+e.body.replace(h,"$1\\$2")+c):d='src="'+a+'"'+f+">",g.write.call(document,"")},g.load=function(a){var c,d=0,e=!1;if(a){for(;c=a[d++];)"ready"==c.status&&c.statusCode>=200&&c.statusCode<300&&(e=!0,b.set(encodeURI(c.url),c));e&&b.save()}},g.defaults={selector:"script",attribute:"x-src",base:"//jazzcat.mobify.com",responseType:"jsonp",execCallback:"Jazzcat.exec",loadCallback:"Jazzcat.load",concat:!1,projectName:""},g})},{"./utils.js":8}],4:[function(a,b,c){!function(d,e){if("function"==typeof a&&"function"==typeof define&&define.amd)a(["mobifyjs/utils","mobifyjs/capture","mobifyjs/resizeImages","mobifyjs/jazzcat","mobifyjs/unblockify","mobifyjs/cssOptimize","mobifyjs/external/picturefill"],e,void 0,!0);else if("object"==typeof c){var f=a("./utils"),g=a("./capture"),h=a("./resizeImages"),i=a("./jazzcat"),j=a("./cssOptimize"),k=a("./unblockify");b.exports=e(f,g,h,i,k,j)}}(this,function(a,b,c,d,e,f){var g=window.Mobify=window.Mobify||{};return g.Utils=a,g.Capture=b,g.ResizeImages=c,g.Jazzcat=d,g.CssOptimize=f,g.Unblockify=e,g.api="2.0",g})},{"./capture":1,"./cssOptimize":2,"./jazzcat":3,"./resizeImages":6,"./unblockify":7,"./utils":8}],5:[function(a,b,c){!function(d,e){if("function"==typeof define&&define.amd)define(["mobifyjs/utils"],e);else if("object"==typeof c){var f=a("./utils.js");b.exports=e(f)}else d.Jazzcat=e(d.Utils)}(this,function(a){var b=function(a){return a=window.navigator.userAgent,/firefox|fennec/i.test(a)},c=function(a){var b=a.body;if(b&&b.addEventListener){var c=function(a){var b=a.target,c=function(a){return"A"==a.nodeName&&/^#/.test(a.getAttribute("href"))};if(c(b)){var e="undefined"!=typeof a.defaultPrevented?a.defaultPrevented:a.getPreventDefault&&a.getPreventDefault();if(!e){a.preventDefault(),a.defaultPrevented=!1;var f=!0;a.preventDefault=function(){a.defaultPrevented=!0,f=!1},setTimeout(function(){f&&d(b.getAttribute("href"))},50)}}},d=function(b){var c,d=/^#([^\s]*)/,e=b.match(d);if(e&&""===e[1])c=a.body;else if(e&&e[1])var c=a.getElementById(e[1]);c&&c.scrollIntoView&&c.scrollIntoView()};b.addEventListener("click",c,!1)}},d=function(){b()&&a.waitForReady(document,c)};return d})},{"./utils.js":8}],6:[function(a,b,c){!function(d,e){"function"==typeof define&&define.amd?define(["mobifyjs/utils"],e):"object"==typeof c?b.exports=e(a("./utils.js")):d.ResizeImages=e(d.Utils)}(this,function(a){function b(b){if(a.supportsLocalStorage()){var c={supported:b,date:Date.now()};localStorage.setItem(d,JSON.stringify(c))}}var c=window.ResizeImages={},d="Mobify-Webp-Support-v2";c.userAgentWebpDetect=function(a){var b=/(Android\s|Chrome\/|Opera9.8*Version\/..\.|Opera..\.)/i,c=new RegExp("(Android\\s(0|1|2|3|(4(?!.*Chrome)))\\.)|(Chrome\\/[0-8]\\.)|(Chrome\\/9\\.0\\.)|(Chrome\\/1[4-6]\\.)|(Android\\sChrome\\/1.\\.)|(Android\\sChrome\\/20\\.)|(Chrome\\/(1.|20|21|22)\\.)|(Opera.*(Version/|Opera\\s)(10|11)\\.)","i");return b.test(a)?c.test(a)?!1:!0:!1},c.dataUriWebpDetect=function(a){var c=new Image;c.onload=function(){var d=1===c.width?!0:!1;b(d),a&&a(d)},c.src="data:image/webp;base64,UklGRkoAAABXRUJQVlA4WAoAAAAQAAAAAAAAAAAAQUxQSAwAAAABBxAR/Q9ERP8DAABWUDggGAAAADABAJ0BKgEAAQABgBwlpAADcAD+/gbQAA=="},c.supportsWebp=function(e){if(a.supportsLocalStorage()){var f,g=localStorage.getItem(d);if(g&&(f=JSON.parse(g)),f&&Date.now()-f.date<6048e5)return f.supported}c.dataUriWebpDetect(e);var h=c.userAgentWebpDetect(navigator.userAgent);return b(h),h},c.getImageURL=function(a,b){var d=b;d||(d=c.processOptions());var e=[d.proto+d.host];if(d.projectName){var f="project-"+d.projectName;e.push(f)}return d.cacheHours&&e.push("c"+d.cacheHours),d.format?e.push(d.format+(d.quality||"")):d.quality&&e.push("q"+d.quality),d.maxWidth&&(e.push(d.maxWidth),d.maxHeight&&e.push(d.maxHeight)),e.push(a),e.join("/")},c._rewriteSrcAttribute=function(b,d,e){if(e=b.getAttribute(d.sourceAttribute)||e){var g=a.absolutify(e);a.httpUrl(g)&&(d.onerror&&b.setAttribute("onerror",d.onerror),b.setAttribute(d.targetAttribute,c.getImageURL(g,d)),b.setAttribute("data-orig-src",e),f||d.sourceAttribute==d.targetAttribute||b.removeAttribute(d.sourceAttribute))}},c._resizeSourceElement=function(b,d,e){var f=b.getAttribute("data-width"),g=d;f&&(g=a.clone(d),g.maxWidth=f),c._rewriteSrcAttribute(b,g,e)},c._crawlPictureElement=function(a,b){var d=a.getElementsByTagName("source");if(0!==d.length&&!a.hasAttribute("mobify-optimized")){a.setAttribute("mobify-optimized","");for(var e=a.getAttribute("data-src"),f=0,g=d.length;g>f;f++)c._resizeSourceElement(d[f],b,e)}};var e=[320,640,768,1080,1536,2048,4e3];c._getBinnedDimension=function(a){for(var b=0,c=0,d=e.length;d>c&&(b=e[c],!(b>=a));c++);return b},c._shouldResize=function(b){var c=a.getMetaViewportProperties(b);return c?!c["initial-scale"]&&c.width?"device-width"==c.width:!c.width&&c["initial-scale"]?"1"==c["initial-scale"]:c.width&&c["initial-scale"]?(initialScale=parseInt(c["initial-scale"]),initialScale>=1&&"device-width"==c.width):!1:!1},c.processOptions=function(b){var d=a.clone(c.defaults);if(b&&a.extend(d,b),null==d.resize&&b.document){var e=c._shouldResize(b.document);c.defaults.resize=d.resize=e}if(!d.format&&d.webp&&(d.format="webp"),d.resize){var f=d.devicePixelRatio||window.devicePixelRatio,g=a.getPhysicalScreenSize(f),h=d.maxWidth||c._getBinnedDimension(g.width),i=d.maxHeight||void 0;f&&d.maxWidth&&(h*=f,d.maxHeight&&(i*=f)),d.maxWidth=Math.ceil(h),d.maxHeight&&i&&(d.maxHeight=Math.ceil(i))}else d.maxWidth=d.maxHeight=d.devicePixelRatio=null;return d},c.resize=function(a,b){if(a.length){b&&!b.document&&(b.document=a[0].ownerDocument);for(var d=c.processOptions(b),e=0;ed;d++){var f=b[d];c.body.appendChild(f)}},c.unblock=function(a){var d=b.prototype.insertMobifyScripts;b.prototype.insertMobifyScripts=function(){d.call(this);var b=this.capturedDoc;c.moveScripts(a,b)}},c})},{"./capture.js":1,"./utils.js":8}],8:[function(a,b,c){!function(a,d){"function"==typeof define&&define.amd?define([],d):"object"==typeof c?b.exports=d():a.Utils=d()}(this,function(){var a={};a.extend=function(a){return[].slice.call(arguments,1).forEach(function(b){for(var c in b)void 0!==b[c]&&(a[c]=b[c])}),a},a.keys=function(a){var b=[];for(var c in a)a.hasOwnProperty(c)&&b.push(c);return b},a.values=function(a){var b=[];for(var c in a)a.hasOwnProperty(c)&&b.push(a[c]);return b},a.clone=function(a){var b={};for(var c in a)a.hasOwnProperty(c)&&(b[c]=a[c]);return b};var b=document.createElement("a");a.absolutify=function(a){return b.href=a,b.href};var c=/^https?/;a.httpUrl=function(a){return c.test(a)},a.outerHTML=function(a){if(a.outerHTML)return a.outerHTML;var b=document.createElement("div");b.appendChild(a.cloneNode(!0));var c=b.innerHTML;return b=null,c},a.getDoctype=function(a){a=a||document;var b=a.doctype||[].filter.call(a.childNodes,function(a){return a.nodeType==Node.DOCUMENT_TYPE_NODE})[0];return b?"":""},a.getMetaViewportProperties=function(a){var b=/,\s?/;a=a||document;var c={},d=a.querySelectorAll('meta[name="viewport"]');if(0==d.length)return!1;var e=d[0].getAttribute("content");if(null==e)return!1;for(var f=e.split(b),g=0;g=2){var i=h[0],j=h[1];c[i]=j}}return c},a.removeBySelector=function(b,c){c=c||document;var d=c.querySelectorAll(b);return a.removeElements(d,c)},a.removeElements=function(a,b){b=b||document;for(var c=0,d=a.length;d>c;c++){var e=a[c];e.parentNode.removeChild(e)}return a};var d;return a.supportsLocalStorage=function(){if(void 0!==d)return d;var a="modernizr";try{localStorage.setItem(a,a),localStorage.removeItem(a),d=!0}catch(b){d=!1}return d},a.matchMedia=function(a){"use strict";var b,c=a.documentElement,d=c.firstElementChild||c.firstChild,e=a.createElement("body"),f=a.createElement("div");return f.id="mq-test-1",f.style.cssText="position:absolute;top:-100em",e.style.background="none",e.appendChild(f),function(a){return f.innerHTML='­',c.insertBefore(e,d),b=42===f.offsetWidth,c.removeChild(e),{matches:b,media:a}}},a.domIsReady=function(a){var a=a||document;return a.attachEvent?"complete"===a.readyState:"loading"!==a.readyState},a.getPhysicalScreenSize=function(a){function b(b){var c=a||window.devicePixelRatio||1;return b.width=Math.round(b.width*c),b.height=Math.round(b.height*c),b}var c=navigator.userAgent.match(/ip(hone|od|ad)/i),d=(navigator.userAgent.match(/android (\d)/i)||{})[1],e={width:window.outerWidth,height:window.outerHeight};if(!c)return d>3?b(e):e;var f=window.orientation%180;return f?(e.height=screen.width,e.width=screen.height):(e.width=screen.width,e.height=screen.height),b(e)},a.waitForReady=function(b,c){var d=!1,e=function(){d||(d=!0,f&&clearInterval(f),c(b))},f=setInterval(function(){a.domIsReady(b)&&e()},100);b.addEventListener("readystatechange",e,!1)},a})},{}]},{},[4]); \ No newline at end of file diff --git a/src/capture.js b/src/capture.js index d30a2beb..a9fa04ea 100644 --- a/src/capture.js +++ b/src/capture.js @@ -409,9 +409,10 @@ Capture.prototype.createDocumentFragments = function() { }; /** - * Returns an escaped HTML representation of the captured DOM + * Returns an HTML representation of the captured DOM with resources enabled. + * (escapedHTMLString remains for backwards compatibility) */ -Capture.prototype.escapedHTMLString = function() { +Capture.prototype.enabledHTMLString = Capture.prototype.escapedHTMLString = function() { var doc = this.capturedDoc; var html = Capture.enable(Utils.outerHTML(doc.documentElement), this.prefix); var htmlWithDoctype = this.doctype + html; @@ -422,11 +423,11 @@ Capture.prototype.escapedHTMLString = function() { * Rewrite the document with a new html string */ Capture.prototype.render = function(htmlString) { - var escapedHTMLString; + var enabledHTMLString; if (!htmlString) { - escapedHTMLString = this.escapedHTMLString(); + enabledHTMLString = this.enabledHTMLString(); } else { - escapedHTMLString = Capture.enable(htmlString, this.prefix); + enabledHTMLString = Capture.enable(htmlString, this.prefix); } var doc = this.sourceDoc; @@ -437,7 +438,7 @@ Capture.prototype.render = function(htmlString) { // Asynchronously render the new document setTimeout(function(){ doc.open("text/html", "replace"); - doc.write(escapedHTMLString); + doc.write(enabledHTMLString); doc.close(); }); }; diff --git a/tests/capture.html b/tests/capture.html index bde3707a..c4ffaa56 100644 --- a/tests/capture.html +++ b/tests/capture.html @@ -135,7 +135,7 @@ \n\ \n\ \n"; - var html = capture.escapedHTMLString(capturedDoc); + var html = capture.enabledHTMLString(capturedDoc); equal(html, expectedHtml, "Passed!"); start(); }, doc); diff --git a/www/_includes/nav-docsv2.md b/www/_includes/nav-docsv2.md index 82963c85..c73847c3 100644 --- a/www/_includes/nav-docsv2.md +++ b/www/_includes/nav-docsv2.md @@ -5,7 +5,7 @@ - [`Capture.init()`]({{ site.baseurl }}/v2/docs/capturing/#captureinitcallback-document-prefixx-) - [`getCapturedDoc()`]({{ site.baseurl }}/v2/docs/capturing/#getcaptureddoc) - [`capturing` variable]({{ site.baseurl }}/v2/docs/capturing/#capturing-variable) - - [`escapedHTMLString()`]({{ site.baseurl }}/v2/docs/capturing/#escapedhtmlstring) + - [`enabledHTMLString()`]({{ site.baseurl }}/v2/docs/capturing/#enabledhtmlstring) - [`render(htmlString)`]({{ site.baseurl }}/v2/docs/capturing/#renderhtmlstring) - [`renderCapturedDoc()`]({{ site.baseurl }}/v2/docs/capturing/#rendercaptureddoc) - [`restore()`]({{ site.baseurl }}/v2/docs/capturing/#restore) diff --git a/www/v2/docs/capturing.md b/www/v2/docs/capturing.md index 461a7c43..e4224ca2 100644 --- a/www/v2/docs/capturing.md +++ b/www/v2/docs/capturing.md @@ -93,7 +93,7 @@ Mobify.js is run again in a non-capturing context (at this time } -## `escapedHTMLString()` +## `enabledHTMLString()` Returns a string representation of the `captured document`, but with all resources enabled (prefix removed). Can be considered an @@ -102,7 +102,7 @@ alternative to `capturedDoc.outerHTML`. **Usage/Example:** Mobify.Capture.init(function(capture){ - var htmlString = capture.escapedHTMLString(); + var htmlString = capture.enabledHTMLString(); }); ## `render(htmlString)`