Comparing version 1.0.3 to 1.0.4
@@ -45,3 +45,3 @@ { | ||
"devDependencies": { | ||
"qunit": "^1.18.0", | ||
"qunit": "^1.19.0", | ||
"jquery": "jquery#^1.11.3", | ||
@@ -48,0 +48,0 @@ "jquery2": "jquery#^2.1.4", |
@@ -0,1 +1,5 @@ | ||
### 1.0.4 | ||
* Fix IOS 9 safari scaling issues. | ||
* Update dependencies. | ||
### 1.0.3 | ||
@@ -2,0 +6,0 @@ * Migrate from legacy to container-based infrastructure on Travis. |
/* | ||
* Remodal - v1.0.3 | ||
* Remodal - v1.0.4 | ||
* Responsive, lightweight, fast, synchronized with CSS animations, fully customizable modal window plugin with declarative configuration and hash tracking. | ||
@@ -126,2 +126,10 @@ * http://vodkabears.github.io/remodal/ | ||
/** | ||
* Is iOS? | ||
* @private | ||
* @const | ||
* @type {Boolean} | ||
*/ | ||
var IS_IOS = /iPad|iPhone|iPod/.test(navigator.platform); | ||
/** | ||
* Current modal | ||
@@ -241,2 +249,6 @@ * @private | ||
function lockScreen() { | ||
if (IS_IOS) { | ||
return; | ||
} | ||
var $html = $('html'); | ||
@@ -263,2 +275,6 @@ var lockedClass = namespacify('is-locked'); | ||
function unlockScreen() { | ||
if (IS_IOS) { | ||
return; | ||
} | ||
var $html = $('html'); | ||
@@ -265,0 +281,0 @@ var lockedClass = namespacify('is-locked'); |
/* | ||
* Remodal - v1.0.3 | ||
* Remodal - v1.0.4 | ||
* Responsive, lightweight, fast, synchronized with CSS animations, fully customizable modal window plugin with declarative configuration and hash tracking. | ||
@@ -10,2 +10,2 @@ * http://vodkabears.github.io/remodal/ | ||
!function(a,b){"function"==typeof define&&define.amd?define(["jquery"],function(c){return b(a,c)}):"object"==typeof exports?b(a,require("jquery")):b(a,a.jQuery||a.Zepto)}(this,function(a,b){"use strict";function c(a){if(w&&"none"===a.css("animation-name")&&"none"===a.css("-webkit-animation-name")&&"none"===a.css("-moz-animation-name")&&"none"===a.css("-o-animation-name")&&"none"===a.css("-ms-animation-name"))return 0;var b,c,d,e,f=a.css("animation-duration")||a.css("-webkit-animation-duration")||a.css("-moz-animation-duration")||a.css("-o-animation-duration")||a.css("-ms-animation-duration")||"0s",g=a.css("animation-delay")||a.css("-webkit-animation-delay")||a.css("-moz-animation-delay")||a.css("-o-animation-delay")||a.css("-ms-animation-delay")||"0s",h=a.css("animation-iteration-count")||a.css("-webkit-animation-iteration-count")||a.css("-moz-animation-iteration-count")||a.css("-o-animation-iteration-count")||a.css("-ms-animation-iteration-count")||"1";for(f=f.split(", "),g=g.split(", "),h=h.split(", "),e=0,c=f.length,b=Number.NEGATIVE_INFINITY;c>e;e++)d=parseFloat(f[e])*parseInt(h[e],10)+parseFloat(g[e]),d>b&&(b=d);return d}function d(){if(b(document.body).height()<=b(window).height())return 0;var a,c,d=document.createElement("div"),e=document.createElement("div");return d.style.visibility="hidden",d.style.width="100px",document.body.appendChild(d),a=d.offsetWidth,d.style.overflow="scroll",e.style.width="100%",d.appendChild(e),c=e.offsetWidth,d.parentNode.removeChild(d),a-c}function e(){var a,c,e=b("html"),f=k("is-locked");e.hasClass(f)||(c=b(document.body),a=parseInt(c.css("padding-right"),10)+d(),c.css("padding-right",a+"px"),e.addClass(f))}function f(){var a,c,e=b("html"),f=k("is-locked");e.hasClass(f)&&(c=b(document.body),a=parseInt(c.css("padding-right"),10)-d(),c.css("padding-right",a+"px"),e.removeClass(f))}function g(a,b,c,d){var e=k("is",b),f=[k("is",u.CLOSING),k("is",u.OPENING),k("is",u.CLOSED),k("is",u.OPENED)].join(" ");a.$bg.removeClass(f).addClass(e),a.$overlay.removeClass(f).addClass(e),a.$wrapper.removeClass(f).addClass(e),a.$modal.removeClass(f).addClass(e),a.state=b,!c&&a.$modal.trigger({type:b,reason:d},[{reason:d}])}function h(a,d,e){var f=0,g=function(a){a.target===this&&f++},h=function(a){a.target===this&&0===--f&&(b.each(["$bg","$overlay","$wrapper","$modal"],function(a,b){e[b].off(r+" "+s)}),d())};b.each(["$bg","$overlay","$wrapper","$modal"],function(a,b){e[b].on(r,g).on(s,h)}),a(),0===c(e.$bg)&&0===c(e.$overlay)&&0===c(e.$wrapper)&&0===c(e.$modal)&&(b.each(["$bg","$overlay","$wrapper","$modal"],function(a,b){e[b].off(r+" "+s)}),d())}function i(a){a.state!==u.CLOSED&&(b.each(["$bg","$overlay","$wrapper","$modal"],function(b,c){a[c].off(r+" "+s)}),a.$bg.removeClass(a.settings.modifier),a.$overlay.removeClass(a.settings.modifier).hide(),a.$wrapper.hide(),f(),g(a,u.CLOSED,!0))}function j(a){var b,c,d,e,f={};for(a=a.replace(/\s*:\s*/g,":").replace(/\s*,\s*/g,","),b=a.split(","),e=0,c=b.length;c>e;e++)b[e]=b[e].split(":"),d=b[e][1],("string"==typeof d||d instanceof String)&&(d="true"===d||("false"===d?!1:d)),("string"==typeof d||d instanceof String)&&(d=isNaN(d)?d:+d),f[b[e][0]]=d;return f}function k(){for(var a=q,b=0;b<arguments.length;++b)a+="-"+arguments[b];return a}function l(){var a,c,d=location.hash.replace("#","");if(d){try{c=b("[data-"+p+"-id="+d.replace(new RegExp("/","g"),"\\/")+"]")}catch(e){}c&&c.length&&(a=b[p].lookup[c.data(p)],a&&a.settings.hashTracking&&a.open())}else n&&n.state===u.OPENED&&n.settings.hashTracking&&n.close()}function m(a,c){var d=b(document.body),e=this;e.settings=b.extend({},t,c),e.index=b[p].lookup.push(e)-1,e.state=u.CLOSED,e.$overlay=b("."+k("overlay")),e.$overlay.length||(e.$overlay=b("<div>").addClass(k("overlay")+" "+k("is",u.CLOSED)).hide(),d.append(e.$overlay)),e.$bg=b("."+k("bg")).addClass(k("is",u.CLOSED)),e.$modal=a.addClass(q+" "+k("is-initialized")+" "+e.settings.modifier+" "+k("is",u.CLOSED)).attr("tabindex","-1"),e.$wrapper=b("<div>").addClass(k("wrapper")+" "+e.settings.modifier+" "+k("is",u.CLOSED)).hide().append(e.$modal),d.append(e.$wrapper),e.$wrapper.on("click."+q,"[data-"+p+'-action="close"]',function(a){a.preventDefault(),e.close()}),e.$wrapper.on("click."+q,"[data-"+p+'-action="cancel"]',function(a){a.preventDefault(),e.$modal.trigger(v.CANCELLATION),e.settings.closeOnCancel&&e.close(v.CANCELLATION)}),e.$wrapper.on("click."+q,"[data-"+p+'-action="confirm"]',function(a){a.preventDefault(),e.$modal.trigger(v.CONFIRMATION),e.settings.closeOnConfirm&&e.close(v.CONFIRMATION)}),e.$wrapper.on("click."+q,function(a){var c=b(a.target);c.hasClass(k("wrapper"))&&e.settings.closeOnOutsideClick&&e.close()})}var n,o,p="remodal",q=a.REMODAL_GLOBALS&&a.REMODAL_GLOBALS.NAMESPACE||p,r=b.map(["animationstart","webkitAnimationStart","MSAnimationStart","oAnimationStart"],function(a){return a+"."+q}).join(" "),s=b.map(["animationend","webkitAnimationEnd","MSAnimationEnd","oAnimationEnd"],function(a){return a+"."+q}).join(" "),t=b.extend({hashTracking:!0,closeOnConfirm:!0,closeOnCancel:!0,closeOnEscape:!0,closeOnOutsideClick:!0,modifier:""},a.REMODAL_GLOBALS&&a.REMODAL_GLOBALS.DEFAULTS),u={CLOSING:"closing",CLOSED:"closed",OPENING:"opening",OPENED:"opened"},v={CONFIRMATION:"confirmation",CANCELLATION:"cancellation"},w=function(){var a=document.createElement("div").style;return void 0!==a.animationName||void 0!==a.WebkitAnimationName||void 0!==a.MozAnimationName||void 0!==a.msAnimationName||void 0!==a.OAnimationName}();m.prototype.open=function(){var a,c=this;c.state!==u.OPENING&&c.state!==u.CLOSING&&(a=c.$modal.attr("data-"+p+"-id"),a&&c.settings.hashTracking&&(o=b(window).scrollTop(),location.hash=a),n&&n!==c&&i(n),n=c,e(),c.$bg.addClass(c.settings.modifier),c.$overlay.addClass(c.settings.modifier).show(),c.$wrapper.show().scrollTop(0),c.$modal.focus(),h(function(){g(c,u.OPENING)},function(){g(c,u.OPENED)},c))},m.prototype.close=function(a){var c=this;c.state!==u.OPENING&&c.state!==u.CLOSING&&(c.settings.hashTracking&&c.$modal.attr("data-"+p+"-id")===location.hash.substr(1)&&(location.hash="",b(window).scrollTop(o)),h(function(){g(c,u.CLOSING,!1,a)},function(){c.$bg.removeClass(c.settings.modifier),c.$overlay.removeClass(c.settings.modifier).hide(),c.$wrapper.hide(),f(),g(c,u.CLOSED,!1,a)},c))},m.prototype.getState=function(){return this.state},m.prototype.destroy=function(){var a,c=b[p].lookup;i(this),this.$wrapper.remove(),delete c[this.index],a=b.grep(c,function(a){return!!a}).length,0===a&&(this.$overlay.remove(),this.$bg.removeClass(k("is",u.CLOSING)+" "+k("is",u.OPENING)+" "+k("is",u.CLOSED)+" "+k("is",u.OPENED)))},b[p]={lookup:[]},b.fn[p]=function(a){var c,d;return this.each(function(e,f){d=b(f),null==d.data(p)?(c=new m(d,a),d.data(p,c.index),c.settings.hashTracking&&d.attr("data-"+p+"-id")===location.hash.substr(1)&&c.open()):c=b[p].lookup[d.data(p)]}),c},b(document).ready(function(){b(document).on("click","[data-"+p+"-target]",function(a){a.preventDefault();var c=a.currentTarget,d=c.getAttribute("data-"+p+"-target"),e=b("[data-"+p+"-id="+d+"]");b[p].lookup[e.data(p)].open()}),b(document).find("."+q).each(function(a,c){var d=b(c),e=d.data(p+"-options");e?("string"==typeof e||e instanceof String)&&(e=j(e)):e={},d[p](e)}),b(document).on("keydown."+q,function(a){n&&n.settings.closeOnEscape&&n.state===u.OPENED&&27===a.keyCode&&n.close()}),b(window).on("hashchange."+q,l)})}); | ||
!function(a,b){"function"==typeof define&&define.amd?define(["jquery"],function(c){return b(a,c)}):"object"==typeof exports?b(a,require("jquery")):b(a,a.jQuery||a.Zepto)}(this,function(a,b){"use strict";function c(a){if(w&&"none"===a.css("animation-name")&&"none"===a.css("-webkit-animation-name")&&"none"===a.css("-moz-animation-name")&&"none"===a.css("-o-animation-name")&&"none"===a.css("-ms-animation-name"))return 0;var b,c,d,e,f=a.css("animation-duration")||a.css("-webkit-animation-duration")||a.css("-moz-animation-duration")||a.css("-o-animation-duration")||a.css("-ms-animation-duration")||"0s",g=a.css("animation-delay")||a.css("-webkit-animation-delay")||a.css("-moz-animation-delay")||a.css("-o-animation-delay")||a.css("-ms-animation-delay")||"0s",h=a.css("animation-iteration-count")||a.css("-webkit-animation-iteration-count")||a.css("-moz-animation-iteration-count")||a.css("-o-animation-iteration-count")||a.css("-ms-animation-iteration-count")||"1";for(f=f.split(", "),g=g.split(", "),h=h.split(", "),e=0,c=f.length,b=Number.NEGATIVE_INFINITY;c>e;e++)d=parseFloat(f[e])*parseInt(h[e],10)+parseFloat(g[e]),d>b&&(b=d);return d}function d(){if(b(document.body).height()<=b(window).height())return 0;var a,c,d=document.createElement("div"),e=document.createElement("div");return d.style.visibility="hidden",d.style.width="100px",document.body.appendChild(d),a=d.offsetWidth,d.style.overflow="scroll",e.style.width="100%",d.appendChild(e),c=e.offsetWidth,d.parentNode.removeChild(d),a-c}function e(){if(!x){var a,c,e=b("html"),f=k("is-locked");e.hasClass(f)||(c=b(document.body),a=parseInt(c.css("padding-right"),10)+d(),c.css("padding-right",a+"px"),e.addClass(f))}}function f(){if(!x){var a,c,e=b("html"),f=k("is-locked");e.hasClass(f)&&(c=b(document.body),a=parseInt(c.css("padding-right"),10)-d(),c.css("padding-right",a+"px"),e.removeClass(f))}}function g(a,b,c,d){var e=k("is",b),f=[k("is",u.CLOSING),k("is",u.OPENING),k("is",u.CLOSED),k("is",u.OPENED)].join(" ");a.$bg.removeClass(f).addClass(e),a.$overlay.removeClass(f).addClass(e),a.$wrapper.removeClass(f).addClass(e),a.$modal.removeClass(f).addClass(e),a.state=b,!c&&a.$modal.trigger({type:b,reason:d},[{reason:d}])}function h(a,d,e){var f=0,g=function(a){a.target===this&&f++},h=function(a){a.target===this&&0===--f&&(b.each(["$bg","$overlay","$wrapper","$modal"],function(a,b){e[b].off(r+" "+s)}),d())};b.each(["$bg","$overlay","$wrapper","$modal"],function(a,b){e[b].on(r,g).on(s,h)}),a(),0===c(e.$bg)&&0===c(e.$overlay)&&0===c(e.$wrapper)&&0===c(e.$modal)&&(b.each(["$bg","$overlay","$wrapper","$modal"],function(a,b){e[b].off(r+" "+s)}),d())}function i(a){a.state!==u.CLOSED&&(b.each(["$bg","$overlay","$wrapper","$modal"],function(b,c){a[c].off(r+" "+s)}),a.$bg.removeClass(a.settings.modifier),a.$overlay.removeClass(a.settings.modifier).hide(),a.$wrapper.hide(),f(),g(a,u.CLOSED,!0))}function j(a){var b,c,d,e,f={};for(a=a.replace(/\s*:\s*/g,":").replace(/\s*,\s*/g,","),b=a.split(","),e=0,c=b.length;c>e;e++)b[e]=b[e].split(":"),d=b[e][1],("string"==typeof d||d instanceof String)&&(d="true"===d||("false"===d?!1:d)),("string"==typeof d||d instanceof String)&&(d=isNaN(d)?d:+d),f[b[e][0]]=d;return f}function k(){for(var a=q,b=0;b<arguments.length;++b)a+="-"+arguments[b];return a}function l(){var a,c,d=location.hash.replace("#","");if(d){try{c=b("[data-"+p+"-id="+d.replace(new RegExp("/","g"),"\\/")+"]")}catch(e){}c&&c.length&&(a=b[p].lookup[c.data(p)],a&&a.settings.hashTracking&&a.open())}else n&&n.state===u.OPENED&&n.settings.hashTracking&&n.close()}function m(a,c){var d=b(document.body),e=this;e.settings=b.extend({},t,c),e.index=b[p].lookup.push(e)-1,e.state=u.CLOSED,e.$overlay=b("."+k("overlay")),e.$overlay.length||(e.$overlay=b("<div>").addClass(k("overlay")+" "+k("is",u.CLOSED)).hide(),d.append(e.$overlay)),e.$bg=b("."+k("bg")).addClass(k("is",u.CLOSED)),e.$modal=a.addClass(q+" "+k("is-initialized")+" "+e.settings.modifier+" "+k("is",u.CLOSED)).attr("tabindex","-1"),e.$wrapper=b("<div>").addClass(k("wrapper")+" "+e.settings.modifier+" "+k("is",u.CLOSED)).hide().append(e.$modal),d.append(e.$wrapper),e.$wrapper.on("click."+q,"[data-"+p+'-action="close"]',function(a){a.preventDefault(),e.close()}),e.$wrapper.on("click."+q,"[data-"+p+'-action="cancel"]',function(a){a.preventDefault(),e.$modal.trigger(v.CANCELLATION),e.settings.closeOnCancel&&e.close(v.CANCELLATION)}),e.$wrapper.on("click."+q,"[data-"+p+'-action="confirm"]',function(a){a.preventDefault(),e.$modal.trigger(v.CONFIRMATION),e.settings.closeOnConfirm&&e.close(v.CONFIRMATION)}),e.$wrapper.on("click."+q,function(a){var c=b(a.target);c.hasClass(k("wrapper"))&&e.settings.closeOnOutsideClick&&e.close()})}var n,o,p="remodal",q=a.REMODAL_GLOBALS&&a.REMODAL_GLOBALS.NAMESPACE||p,r=b.map(["animationstart","webkitAnimationStart","MSAnimationStart","oAnimationStart"],function(a){return a+"."+q}).join(" "),s=b.map(["animationend","webkitAnimationEnd","MSAnimationEnd","oAnimationEnd"],function(a){return a+"."+q}).join(" "),t=b.extend({hashTracking:!0,closeOnConfirm:!0,closeOnCancel:!0,closeOnEscape:!0,closeOnOutsideClick:!0,modifier:""},a.REMODAL_GLOBALS&&a.REMODAL_GLOBALS.DEFAULTS),u={CLOSING:"closing",CLOSED:"closed",OPENING:"opening",OPENED:"opened"},v={CONFIRMATION:"confirmation",CANCELLATION:"cancellation"},w=function(){var a=document.createElement("div").style;return void 0!==a.animationName||void 0!==a.WebkitAnimationName||void 0!==a.MozAnimationName||void 0!==a.msAnimationName||void 0!==a.OAnimationName}(),x=/iPad|iPhone|iPod/.test(navigator.platform);m.prototype.open=function(){var a,c=this;c.state!==u.OPENING&&c.state!==u.CLOSING&&(a=c.$modal.attr("data-"+p+"-id"),a&&c.settings.hashTracking&&(o=b(window).scrollTop(),location.hash=a),n&&n!==c&&i(n),n=c,e(),c.$bg.addClass(c.settings.modifier),c.$overlay.addClass(c.settings.modifier).show(),c.$wrapper.show().scrollTop(0),c.$modal.focus(),h(function(){g(c,u.OPENING)},function(){g(c,u.OPENED)},c))},m.prototype.close=function(a){var c=this;c.state!==u.OPENING&&c.state!==u.CLOSING&&(c.settings.hashTracking&&c.$modal.attr("data-"+p+"-id")===location.hash.substr(1)&&(location.hash="",b(window).scrollTop(o)),h(function(){g(c,u.CLOSING,!1,a)},function(){c.$bg.removeClass(c.settings.modifier),c.$overlay.removeClass(c.settings.modifier).hide(),c.$wrapper.hide(),f(),g(c,u.CLOSED,!1,a)},c))},m.prototype.getState=function(){return this.state},m.prototype.destroy=function(){var a,c=b[p].lookup;i(this),this.$wrapper.remove(),delete c[this.index],a=b.grep(c,function(a){return!!a}).length,0===a&&(this.$overlay.remove(),this.$bg.removeClass(k("is",u.CLOSING)+" "+k("is",u.OPENING)+" "+k("is",u.CLOSED)+" "+k("is",u.OPENED)))},b[p]={lookup:[]},b.fn[p]=function(a){var c,d;return this.each(function(e,f){d=b(f),null==d.data(p)?(c=new m(d,a),d.data(p,c.index),c.settings.hashTracking&&d.attr("data-"+p+"-id")===location.hash.substr(1)&&c.open()):c=b[p].lookup[d.data(p)]}),c},b(document).ready(function(){b(document).on("click","[data-"+p+"-target]",function(a){a.preventDefault();var c=a.currentTarget,d=c.getAttribute("data-"+p+"-target"),e=b("[data-"+p+"-id="+d+"]");b[p].lookup[e.data(p)].open()}),b(document).find("."+q).each(function(a,c){var d=b(c),e=d.data(p+"-options");e?("string"==typeof e||e instanceof String)&&(e=j(e)):e={},d[p](e)}),b(document).on("keydown."+q,function(a){n&&n.settings.closeOnEscape&&n.state===u.OPENED&&27===a.keyCode&&n.close()}),b(window).on("hashchange."+q,l)})}); |
@@ -16,14 +16,13 @@ { | ||
], | ||
"version": "1.18.0", | ||
"version": "1.19.0", | ||
"homepage": "https://github.com/jquery/qunit", | ||
"_release": "1.18.0", | ||
"_release": "1.19.0", | ||
"_resolution": { | ||
"type": "version", | ||
"tag": "1.18.0", | ||
"commit": "87e5b64ab1cfa558770a8af20911c27c12440d82" | ||
"tag": "1.19.0", | ||
"commit": "467e7e34652ad7d5883ce9c568461cf8c5e172a8" | ||
}, | ||
"_source": "git://github.com/jquery/qunit.git", | ||
"_target": "~1.18.0", | ||
"_originalSource": "qunit", | ||
"_direct": true | ||
"_target": "^1.19.0", | ||
"_originalSource": "qunit" | ||
} |
@@ -84,3 +84,3 @@ Authors ordered by first contribution | ||
Nathan Dauber <nathan@radialogica.com> | ||
Michał Gołębiowski <m.goleb@gmail.com> | ||
Michał Gołębiowski <m.goleb@gmail.com> | ||
XhmikosR <xhmikosr@yahoo.com> | ||
@@ -106,1 +106,7 @@ Patrick Stapleton <github@gdi2290.com> | ||
Gaurav Mittal <gaurav.mittal@students.iiit.ac.in> | ||
Kevin Partington <kevin.partington@kernelpanicstudios.com> | ||
Braulio Valdivielso Martínez <brlvldvlsmrtnz@gmail.com> | ||
Shinnosuke Watanabe <snnskwtnb@gmail.com> | ||
Aurelio De Rosa <aurelioderosa@gmail.com> | ||
Toh Chee Chuan <chuan@yokestudio.com> | ||
Stefan Penner <stefan.penner@gmail.com> |
@@ -16,3 +16,3 @@ { | ||
], | ||
"version": "1.18.0" | ||
"version": "1.19.0" | ||
} |
@@ -7,5 +7,3 @@ { | ||
"test/index.html", | ||
"test/startError.html", | ||
"test/logs.html", | ||
"test/setTimeout.html", | ||
"test/amd.html" | ||
@@ -18,7 +16,3 @@ ], | ||
"firefox_current", | ||
"opera_12_1", | ||
"opera_previous", | ||
"opera_current", | ||
"safari_5_1", | ||
"safari_6", | ||
"safari_previous", | ||
@@ -32,15 +26,8 @@ "safari_current", | ||
"ie_11", | ||
"edge_latest", | ||
{ | ||
"os": "iOS", | ||
"os_version": "6.0" | ||
}, | ||
{ | ||
"os": "iOS", | ||
"os_version": "7.0" | ||
}, | ||
{ | ||
"os": "iOS", | ||
"os_version": "8.0" | ||
"os_version": "8.3" | ||
} | ||
] | ||
} |
@@ -0,1 +1,22 @@ | ||
1.19.0 / 2015-09-01 | ||
================== | ||
* Assert: Add support to ES6' Map and Set equiv objects | ||
* Build: Enable IRC notifications for Travis CI | ||
* Build: Add 'Readme' to commitplease components | ||
* Build: Remove unintended QUnit global export on Node | ||
* Build: Remove testSwarm job | ||
* Core: Implement QUnit.stack | ||
* Dump: Escape backslash when quoting strings | ||
* HTML Reporter: Avoid readyState issue with PhantomJS | ||
* HTML Reporter: HTML reporter enhancements for negative asserts | ||
* HTML Reporter: Show diff only when it helps | ||
* Tests: Avoid loosen errors on autostart test | ||
* Tests: HTML Reporter tests are now isolated with reordering disabled | ||
* Tests: Rename stack error tests | ||
* Test: Release module hooks to avoid memory leaks | ||
* Test: Don't pass Promise fulfillment value to QUnit.start | ||
* Test: Source Displayed Even for Passed Test | ||
1.18.0 / 2015-04-03 | ||
@@ -2,0 +23,0 @@ ================== |
@@ -1,3 +0,2 @@ | ||
[](http://jenkins.jquery.com/job/QUnit/) | ||
[](https://coveralls.io/r/jquery/qunit) | ||
[](https://travis-ci.org/jquery/qunit) [](https://coveralls.io/github/jquery/qunit) | ||
@@ -4,0 +3,0 @@ # [QUnit](http://qunitjs.com) - A JavaScript Unit Testing Framework. |
(function() { | ||
// Don't load the HTML Reporter on non-Browser environments | ||
if ( typeof window === "undefined" || !window.document ) { | ||
return; | ||
} | ||
// Deprecated QUnit.init - Ref #530 | ||
@@ -60,7 +65,2 @@ // Re-initialize the configuration options | ||
// Don't load the HTML Reporter on non-Browser environments | ||
if ( typeof window === "undefined" ) { | ||
return; | ||
} | ||
var config = QUnit.config, | ||
@@ -639,5 +639,11 @@ hasOwn = Object.prototype.hasOwnProperty, | ||
function stripHtml( string ) { | ||
// strip tags, html entity and whitespaces | ||
return string.replace(/<\/?[^>]+(>|$)/g, "").replace(/\"/g, "").replace(/\s+/g, ""); | ||
} | ||
QUnit.log(function( details ) { | ||
var assertList, assertLi, | ||
message, expected, actual, | ||
message, expected, actual, diff, | ||
showDiff = false, | ||
testItem = id( "qunit-test-output-" + details.testId ); | ||
@@ -657,3 +663,8 @@ | ||
if ( !details.result && hasOwn.call( details, "expected" ) ) { | ||
expected = escapeText( QUnit.dump.parse( details.expected ) ); | ||
if ( details.negative ) { | ||
expected = escapeText( "NOT " + QUnit.dump.parse( details.expected ) ); | ||
} else { | ||
expected = escapeText( QUnit.dump.parse( details.expected ) ); | ||
} | ||
actual = escapeText( QUnit.dump.parse( details.actual ) ); | ||
@@ -665,15 +676,27 @@ message += "<table><tr class='test-expected'><th>Expected: </th><td><pre>" + | ||
if ( actual !== expected ) { | ||
message += "<tr class='test-actual'><th>Result: </th><td><pre>" + | ||
actual + "</pre></td></tr>" + | ||
"<tr class='test-diff'><th>Diff: </th><td><pre>" + | ||
QUnit.diff( expected, actual ) + "</pre></td></tr>"; | ||
} else { | ||
if ( expected.indexOf( "[object Array]" ) !== -1 || | ||
expected.indexOf( "[object Object]" ) !== -1 ) { | ||
message += "<tr class='test-message'><th>Message: </th><td>" + | ||
"Diff suppressed as the depth of object is more than current max depth (" + | ||
QUnit.config.maxDepth + ").<p>Hint: Use <code>QUnit.dump.maxDepth</code> to " + | ||
" run with a higher max depth or <a href='" + setUrl({ maxDepth: -1 }) + "'>" + | ||
"Rerun</a> without max depth.</p></td></tr>"; | ||
actual + "</pre></td></tr>"; | ||
// Don't show diff if actual or expected are booleans | ||
if ( !( /^(true|false)$/.test( actual ) ) && | ||
!( /^(true|false)$/.test( expected ) ) ) { | ||
diff = QUnit.diff( expected, actual ); | ||
showDiff = stripHtml( diff ).length !== | ||
stripHtml( expected ).length + | ||
stripHtml( actual ).length; | ||
} | ||
// Don't show diff if expected and actual are totally different | ||
if ( showDiff ) { | ||
message += "<tr class='test-diff'><th>Diff: </th><td><pre>" + | ||
diff + "</pre></td></tr>"; | ||
} | ||
} else if ( expected.indexOf( "[object Array]" ) !== -1 || | ||
expected.indexOf( "[object Object]" ) !== -1 ) { | ||
message += "<tr class='test-message'><th>Message: </th><td>" + | ||
"Diff suppressed as the depth of object is more than current max depth (" + | ||
QUnit.config.maxDepth + ").<p>Hint: Use <code>QUnit.dump.maxDepth</code> to " + | ||
" run with a higher max depth or <a href='" + setUrl({ maxDepth: -1 }) + "'>" + | ||
"Rerun</a> without max depth.</p></td></tr>"; | ||
} | ||
@@ -706,3 +729,3 @@ | ||
var testTitle, time, testItem, assertList, | ||
good, bad, testCounts, skipped, | ||
good, bad, testCounts, skipped, sourceName, | ||
tests = id( "qunit-tests" ); | ||
@@ -762,6 +785,27 @@ | ||
} | ||
// Show the source of the test when showing assertions | ||
if ( details.source ) { | ||
sourceName = document.createElement( "p" ); | ||
sourceName.innerHTML = "<strong>Source: </strong>" + details.source; | ||
addClass( sourceName, "qunit-source" ); | ||
if ( bad === 0 ) { | ||
addClass( sourceName, "qunit-collapsed" ); | ||
} | ||
addEvent( testTitle, "click", function() { | ||
toggleClass( sourceName, "qunit-collapsed" ); | ||
}); | ||
testItem.appendChild( sourceName ); | ||
} | ||
}); | ||
if ( defined.document ) { | ||
if ( document.readyState === "complete" ) { | ||
// Avoid readyState issue with phantomjs | ||
// Ref: #818 | ||
var notPhantom = ( function( p ) { | ||
return !( p && p.version && p.version.major > 0 ); | ||
} )( window.phantom ); | ||
if ( notPhantom && document.readyState === "complete" ) { | ||
QUnit.load(); | ||
@@ -768,0 +812,0 @@ } else { |
@@ -41,3 +41,3 @@ function Assert( testContext ) { | ||
// Exports test.push() to the user API | ||
push: function( /* result, actual, expected, message */ ) { | ||
push: function( /* result, actual, expected, message, negative */ ) { | ||
var assert = this, | ||
@@ -77,3 +77,3 @@ currentTest = ( assert instanceof Assert && assert.test ) || QUnit.config.current; | ||
QUnit.dump.parse( result ) ); | ||
this.push( !result, result, false, message ); | ||
this.push( !result, result, false, message, true ); | ||
}, | ||
@@ -88,3 +88,3 @@ | ||
/*jshint eqeqeq:false */ | ||
this.push( expected != actual, actual, expected, message ); | ||
this.push( expected != actual, actual, expected, message, true ); | ||
}, | ||
@@ -101,3 +101,3 @@ | ||
expected = objectValues( expected ); | ||
this.push( !QUnit.equiv( actual, expected ), actual, expected, message ); | ||
this.push( !QUnit.equiv( actual, expected ), actual, expected, message, true ); | ||
}, | ||
@@ -110,3 +110,3 @@ | ||
notDeepEqual: function( actual, expected, message ) { | ||
this.push( !QUnit.equiv( actual, expected ), actual, expected, message ); | ||
this.push( !QUnit.equiv( actual, expected ), actual, expected, message, true ); | ||
}, | ||
@@ -119,3 +119,3 @@ | ||
notStrictEqual: function( actual, expected, message ) { | ||
this.push( expected !== actual, actual, expected, message ); | ||
this.push( expected !== actual, actual, expected, message, true ); | ||
}, | ||
@@ -186,1 +186,21 @@ | ||
}()); | ||
function errorString( error ) { | ||
var name, message, | ||
resultErrorString = error.toString(); | ||
if ( resultErrorString.substring( 0, 7 ) === "[object" ) { | ||
name = error.name ? error.name.toString() : "Error"; | ||
message = error.message ? error.message.toString() : ""; | ||
if ( name && message ) { | ||
return name + ": " + message; | ||
} else if ( name ) { | ||
return name; | ||
} else if ( message ) { | ||
return message; | ||
} else { | ||
return "Error"; | ||
} | ||
} else { | ||
return resultErrorString; | ||
} | ||
} |
@@ -1,203 +0,9 @@ | ||
var QUnit, | ||
config, | ||
onErrorFnPrev, | ||
loggingCallbacks = {}, | ||
fileName = ( sourceFromStacktrace( 0 ) || "" ).replace( /(:\d+)+\)?/, "" ).replace( /.+\//, "" ), | ||
toString = Object.prototype.toString, | ||
hasOwn = Object.prototype.hasOwnProperty, | ||
// Keep a local reference to Date (GH-283) | ||
Date = window.Date, | ||
now = Date.now || function() { | ||
return new Date().getTime(); | ||
}, | ||
globalStartCalled = false, | ||
runStarted = false, | ||
setTimeout = window.setTimeout, | ||
clearTimeout = window.clearTimeout, | ||
defined = { | ||
document: window.document !== undefined, | ||
setTimeout: window.setTimeout !== undefined, | ||
sessionStorage: (function() { | ||
var x = "qunit-test-string"; | ||
try { | ||
sessionStorage.setItem( x, x ); | ||
sessionStorage.removeItem( x ); | ||
return true; | ||
} catch ( e ) { | ||
return false; | ||
} | ||
}()) | ||
}, | ||
/** | ||
* Provides a normalized error string, correcting an issue | ||
* with IE 7 (and prior) where Error.prototype.toString is | ||
* not properly implemented | ||
* | ||
* Based on http://es5.github.com/#x15.11.4.4 | ||
* | ||
* @param {String|Error} error | ||
* @return {String} error message | ||
*/ | ||
errorString = function( error ) { | ||
var name, message, | ||
errorString = error.toString(); | ||
if ( errorString.substring( 0, 7 ) === "[object" ) { | ||
name = error.name ? error.name.toString() : "Error"; | ||
message = error.message ? error.message.toString() : ""; | ||
if ( name && message ) { | ||
return name + ": " + message; | ||
} else if ( name ) { | ||
return name; | ||
} else if ( message ) { | ||
return message; | ||
} else { | ||
return "Error"; | ||
} | ||
} else { | ||
return errorString; | ||
} | ||
}, | ||
/** | ||
* Makes a clone of an object using only Array or Object as base, | ||
* and copies over the own enumerable properties. | ||
* | ||
* @param {Object} obj | ||
* @return {Object} New object with only the own properties (recursively). | ||
*/ | ||
objectValues = function( obj ) { | ||
var key, val, | ||
vals = QUnit.is( "array", obj ) ? [] : {}; | ||
for ( key in obj ) { | ||
if ( hasOwn.call( obj, key ) ) { | ||
val = obj[ key ]; | ||
vals[ key ] = val === Object( val ) ? objectValues( val ) : val; | ||
} | ||
} | ||
return vals; | ||
}; | ||
QUnit.urlParams = urlParams; | ||
QUnit = {}; | ||
// Figure out if we're running the tests from a server or not | ||
QUnit.isLocal = !( defined.document && window.location.protocol !== "file:" ); | ||
/** | ||
* Config object: Maintain internal state | ||
* Later exposed as QUnit.config | ||
* `config` initialized at top of scope | ||
*/ | ||
config = { | ||
// The queue of tests to run | ||
queue: [], | ||
// Expose the current QUnit version | ||
QUnit.version = "@VERSION"; | ||
// block until document ready | ||
blocking: true, | ||
// by default, run previously failed tests first | ||
// very useful in combination with "Hide passed tests" checked | ||
reorder: true, | ||
// by default, modify document.title when suite is done | ||
altertitle: true, | ||
// by default, scroll to top of the page when suite is done | ||
scrolltop: true, | ||
// when enabled, all tests must call expect() | ||
requireExpects: false, | ||
// depth up-to which object will be dumped | ||
maxDepth: 5, | ||
// add checkboxes that are persisted in the query-string | ||
// when enabled, the id is set to `true` as a `QUnit.config` property | ||
urlConfig: [ | ||
{ | ||
id: "hidepassed", | ||
label: "Hide passed tests", | ||
tooltip: "Only show tests and assertions that fail. Stored as query-strings." | ||
}, | ||
{ | ||
id: "noglobals", | ||
label: "Check for Globals", | ||
tooltip: "Enabling this will test if any test introduces new properties on the " + | ||
"`window` object. Stored as query-strings." | ||
}, | ||
{ | ||
id: "notrycatch", | ||
label: "No try-catch", | ||
tooltip: "Enabling this will run tests outside of a try-catch block. Makes debugging " + | ||
"exceptions in IE reasonable. Stored as query-strings." | ||
} | ||
], | ||
// Set of all modules. | ||
modules: [], | ||
// The first unnamed module | ||
currentModule: { | ||
name: "", | ||
tests: [] | ||
}, | ||
callbacks: {} | ||
}; | ||
// Push a loose unnamed module to the modules collection | ||
config.modules.push( config.currentModule ); | ||
// Initialize more QUnit.config and QUnit.urlParams | ||
(function() { | ||
var i, current, | ||
location = window.location || { search: "", protocol: "file:" }, | ||
params = location.search.slice( 1 ).split( "&" ), | ||
length = params.length, | ||
urlParams = {}; | ||
if ( params[ 0 ] ) { | ||
for ( i = 0; i < length; i++ ) { | ||
current = params[ i ].split( "=" ); | ||
current[ 0 ] = decodeURIComponent( current[ 0 ] ); | ||
// allow just a key to turn on a flag, e.g., test.html?noglobals | ||
current[ 1 ] = current[ 1 ] ? decodeURIComponent( current[ 1 ] ) : true; | ||
if ( urlParams[ current[ 0 ] ] ) { | ||
urlParams[ current[ 0 ] ] = [].concat( urlParams[ current[ 0 ] ], current[ 1 ] ); | ||
} else { | ||
urlParams[ current[ 0 ] ] = current[ 1 ]; | ||
} | ||
} | ||
} | ||
if ( urlParams.filter === true ) { | ||
delete urlParams.filter; | ||
} | ||
QUnit.urlParams = urlParams; | ||
// String search anywhere in moduleName+testName | ||
config.filter = urlParams.filter; | ||
if ( urlParams.maxDepth ) { | ||
config.maxDepth = parseInt( urlParams.maxDepth, 10 ) === -1 ? | ||
Number.POSITIVE_INFINITY : | ||
urlParams.maxDepth; | ||
} | ||
config.testId = []; | ||
if ( urlParams.testId ) { | ||
// Ensure that urlParams.testId is an array | ||
urlParams.testId = decodeURIComponent( urlParams.testId ).split( "," ); | ||
for ( i = 0; i < urlParams.testId.length; i++ ) { | ||
config.testId.push( urlParams.testId[ i ] ); | ||
} | ||
} | ||
// Figure out if we're running the tests from a server or not | ||
QUnit.isLocal = location.protocol === "file:"; | ||
// Expose the current QUnit version | ||
QUnit.version = "@VERSION"; | ||
}()); | ||
// Root QUnit object. | ||
// `QUnit` initialized at top of scope | ||
extend( QUnit, { | ||
@@ -229,38 +35,8 @@ | ||
// DEPRECATED: QUnit.asyncTest() will be removed in QUnit 2.0. | ||
asyncTest: function( testName, expected, callback ) { | ||
if ( arguments.length === 2 ) { | ||
callback = expected; | ||
expected = null; | ||
} | ||
asyncTest: asyncTest, | ||
QUnit.test( testName, expected, callback, true ); | ||
}, | ||
test: test, | ||
test: function( testName, expected, callback, async ) { | ||
var test; | ||
skip: skip, | ||
if ( arguments.length === 2 ) { | ||
callback = expected; | ||
expected = null; | ||
} | ||
test = new Test({ | ||
testName: testName, | ||
expected: expected, | ||
async: async, | ||
callback: callback | ||
}); | ||
test.queue(); | ||
}, | ||
skip: function( testName ) { | ||
var test = new Test({ | ||
testName: testName, | ||
skip: true | ||
}); | ||
test.queue(); | ||
}, | ||
// DEPRECATED: The functionality of QUnit.start() will be altered in QUnit 2.0. | ||
@@ -328,40 +104,6 @@ // In QUnit 2.0, invoking it will ONLY affect the `QUnit.config.autostart` blocking behavior. | ||
// Safe object type checking | ||
is: function( type, obj ) { | ||
return QUnit.objectType( obj ) === type; | ||
}, | ||
is: is, | ||
objectType: function( obj ) { | ||
if ( typeof obj === "undefined" ) { | ||
return "undefined"; | ||
} | ||
objectType: objectType, | ||
// Consider: typeof null === object | ||
if ( obj === null ) { | ||
return "null"; | ||
} | ||
var match = toString.call( obj ).match( /^\[object\s(.*)\]$/ ), | ||
type = match && match[ 1 ] || ""; | ||
switch ( type ) { | ||
case "Number": | ||
if ( isNaN( obj ) ) { | ||
return "nan"; | ||
} | ||
return "number"; | ||
case "String": | ||
case "Boolean": | ||
case "Array": | ||
case "Date": | ||
case "RegExp": | ||
case "Function": | ||
return type.toLowerCase(); | ||
} | ||
if ( typeof obj === "object" ) { | ||
return "object"; | ||
} | ||
return undefined; | ||
}, | ||
extend: extend, | ||
@@ -387,199 +129,12 @@ | ||
} | ||
}, | ||
stack: function( offset ) { | ||
offset = ( offset || 0 ) + 2; | ||
return sourceFromStacktrace( offset ); | ||
} | ||
}); | ||
// Register logging callbacks | ||
(function() { | ||
var i, l, key, | ||
callbacks = [ "begin", "done", "log", "testStart", "testDone", | ||
"moduleStart", "moduleDone" ]; | ||
registerLoggingCallbacks( QUnit ); | ||
function registerLoggingCallback( key ) { | ||
var loggingCallback = function( callback ) { | ||
if ( QUnit.objectType( callback ) !== "function" ) { | ||
throw new Error( | ||
"QUnit logging methods require a callback function as their first parameters." | ||
); | ||
} | ||
config.callbacks[ key ].push( callback ); | ||
}; | ||
// DEPRECATED: This will be removed on QUnit 2.0.0+ | ||
// Stores the registered functions allowing restoring | ||
// at verifyLoggingCallbacks() if modified | ||
loggingCallbacks[ key ] = loggingCallback; | ||
return loggingCallback; | ||
} | ||
for ( i = 0, l = callbacks.length; i < l; i++ ) { | ||
key = callbacks[ i ]; | ||
// Initialize key collection of logging callback | ||
if ( QUnit.objectType( config.callbacks[ key ] ) === "undefined" ) { | ||
config.callbacks[ key ] = []; | ||
} | ||
QUnit[ key ] = registerLoggingCallback( key ); | ||
} | ||
})(); | ||
// `onErrorFnPrev` initialized at top of scope | ||
// Preserve other handlers | ||
onErrorFnPrev = window.onerror; | ||
// Cover uncaught exceptions | ||
// Returning true will suppress the default browser handler, | ||
// returning false will let it run. | ||
window.onerror = function( error, filePath, linerNr ) { | ||
var ret = false; | ||
if ( onErrorFnPrev ) { | ||
ret = onErrorFnPrev( error, filePath, linerNr ); | ||
} | ||
// Treat return value as window.onerror itself does, | ||
// Only do our handling if not suppressed. | ||
if ( ret !== true ) { | ||
if ( QUnit.config.current ) { | ||
if ( QUnit.config.current.ignoreGlobalErrors ) { | ||
return true; | ||
} | ||
QUnit.pushFailure( error, filePath + ":" + linerNr ); | ||
} else { | ||
QUnit.test( "global failure", extend(function() { | ||
QUnit.pushFailure( error, filePath + ":" + linerNr ); | ||
}, { validTest: true } ) ); | ||
} | ||
return false; | ||
} | ||
return ret; | ||
}; | ||
function done() { | ||
var runtime, passed; | ||
config.autorun = true; | ||
// Log the last module results | ||
if ( config.previousModule ) { | ||
runLoggingCallbacks( "moduleDone", { | ||
name: config.previousModule.name, | ||
tests: config.previousModule.tests, | ||
failed: config.moduleStats.bad, | ||
passed: config.moduleStats.all - config.moduleStats.bad, | ||
total: config.moduleStats.all, | ||
runtime: now() - config.moduleStats.started | ||
}); | ||
} | ||
delete config.previousModule; | ||
runtime = now() - config.started; | ||
passed = config.stats.all - config.stats.bad; | ||
runLoggingCallbacks( "done", { | ||
failed: config.stats.bad, | ||
passed: passed, | ||
total: config.stats.all, | ||
runtime: runtime | ||
}); | ||
} | ||
// Doesn't support IE6 to IE9, it will return undefined on these browsers | ||
// See also https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/Error/Stack | ||
function extractStacktrace( e, offset ) { | ||
offset = offset === undefined ? 4 : offset; | ||
var stack, include, i; | ||
if ( e.stack ) { | ||
stack = e.stack.split( "\n" ); | ||
if ( /^error$/i.test( stack[ 0 ] ) ) { | ||
stack.shift(); | ||
} | ||
if ( fileName ) { | ||
include = []; | ||
for ( i = offset; i < stack.length; i++ ) { | ||
if ( stack[ i ].indexOf( fileName ) !== -1 ) { | ||
break; | ||
} | ||
include.push( stack[ i ] ); | ||
} | ||
if ( include.length ) { | ||
return include.join( "\n" ); | ||
} | ||
} | ||
return stack[ offset ]; | ||
// Support: Safari <=6 only | ||
} else if ( e.sourceURL ) { | ||
// exclude useless self-reference for generated Error objects | ||
if ( /qunit.js$/.test( e.sourceURL ) ) { | ||
return; | ||
} | ||
// for actual exceptions, this is useful | ||
return e.sourceURL + ":" + e.line; | ||
} | ||
} | ||
function sourceFromStacktrace( offset ) { | ||
var error = new Error(); | ||
// Support: Safari <=7 only, IE <=10 - 11 only | ||
// Not all browsers generate the `stack` property for `new Error()`, see also #636 | ||
if ( !error.stack ) { | ||
try { | ||
throw error; | ||
} catch ( err ) { | ||
error = err; | ||
} | ||
} | ||
return extractStacktrace( error, offset ); | ||
} | ||
function synchronize( callback, last ) { | ||
if ( QUnit.objectType( callback ) === "array" ) { | ||
while ( callback.length ) { | ||
synchronize( callback.shift() ); | ||
} | ||
return; | ||
} | ||
config.queue.push( callback ); | ||
if ( config.autorun && !config.blocking ) { | ||
process( last ); | ||
} | ||
} | ||
function process( last ) { | ||
function next() { | ||
process( last ); | ||
} | ||
var start = now(); | ||
config.depth = ( config.depth || 0 ) + 1; | ||
while ( config.queue.length && !config.blocking ) { | ||
if ( !defined.setTimeout || config.updateRate <= 0 || | ||
( ( now() - start ) < config.updateRate ) ) { | ||
if ( config.current ) { | ||
// Reset async tracking for each phase of the Test lifecycle | ||
config.current.usedAsync = false; | ||
} | ||
config.queue.shift()(); | ||
} else { | ||
setTimeout( next, 13 ); | ||
break; | ||
} | ||
} | ||
config.depth--; | ||
if ( last && !config.blocking && !config.queue.length && config.depth === 0 ) { | ||
done(); | ||
} | ||
} | ||
function begin() { | ||
@@ -621,20 +176,27 @@ var i, l, | ||
function resumeProcessing() { | ||
runStarted = true; | ||
function process( last ) { | ||
function next() { | ||
process( last ); | ||
} | ||
var start = now(); | ||
config.depth = ( config.depth || 0 ) + 1; | ||
// A slight delay to allow this iteration of the event loop to finish (more assertions, etc.) | ||
if ( defined.setTimeout ) { | ||
setTimeout(function() { | ||
if ( config.current && config.current.semaphore > 0 ) { | ||
return; | ||
while ( config.queue.length && !config.blocking ) { | ||
if ( !defined.setTimeout || config.updateRate <= 0 || | ||
( ( now() - start ) < config.updateRate ) ) { | ||
if ( config.current ) { | ||
// Reset async tracking for each phase of the Test lifecycle | ||
config.current.usedAsync = false; | ||
} | ||
if ( config.timeout ) { | ||
clearTimeout( config.timeout ); | ||
} | ||
begin(); | ||
}, 13 ); | ||
} else { | ||
begin(); | ||
config.queue.shift()(); | ||
} else { | ||
setTimeout( next, 13 ); | ||
break; | ||
} | ||
} | ||
config.depth--; | ||
if ( last && !config.blocking && !config.queue.length && config.depth === 0 ) { | ||
done(); | ||
} | ||
} | ||
@@ -659,121 +221,49 @@ | ||
function saveGlobal() { | ||
config.pollution = []; | ||
function resumeProcessing() { | ||
runStarted = true; | ||
if ( config.noglobals ) { | ||
for ( var key in window ) { | ||
if ( hasOwn.call( window, key ) ) { | ||
// in Opera sometimes DOM element ids show up here, ignore them | ||
if ( /^qunit-test-output/.test( key ) ) { | ||
continue; | ||
} | ||
config.pollution.push( key ); | ||
// A slight delay to allow this iteration of the event loop to finish (more assertions, etc.) | ||
if ( defined.setTimeout ) { | ||
setTimeout(function() { | ||
if ( config.current && config.current.semaphore > 0 ) { | ||
return; | ||
} | ||
} | ||
} | ||
} | ||
function checkPollution() { | ||
var newGlobals, | ||
deletedGlobals, | ||
old = config.pollution; | ||
saveGlobal(); | ||
newGlobals = diff( config.pollution, old ); | ||
if ( newGlobals.length > 0 ) { | ||
QUnit.pushFailure( "Introduced global variable(s): " + newGlobals.join( ", " ) ); | ||
} | ||
deletedGlobals = diff( old, config.pollution ); | ||
if ( deletedGlobals.length > 0 ) { | ||
QUnit.pushFailure( "Deleted global variable(s): " + deletedGlobals.join( ", " ) ); | ||
} | ||
} | ||
// returns a new Array with the elements that are in a but not in b | ||
function diff( a, b ) { | ||
var i, j, | ||
result = a.slice(); | ||
for ( i = 0; i < result.length; i++ ) { | ||
for ( j = 0; j < b.length; j++ ) { | ||
if ( result[ i ] === b[ j ] ) { | ||
result.splice( i, 1 ); | ||
i--; | ||
break; | ||
if ( config.timeout ) { | ||
clearTimeout( config.timeout ); | ||
} | ||
} | ||
} | ||
return result; | ||
} | ||
function extend( a, b, undefOnly ) { | ||
for ( var prop in b ) { | ||
if ( hasOwn.call( b, prop ) ) { | ||
// Avoid "Member not found" error in IE8 caused by messing with window.constructor | ||
if ( !( prop === "constructor" && a === window ) ) { | ||
if ( b[ prop ] === undefined ) { | ||
delete a[ prop ]; | ||
} else if ( !( undefOnly && typeof a[ prop ] !== "undefined" ) ) { | ||
a[ prop ] = b[ prop ]; | ||
} | ||
} | ||
} | ||
begin(); | ||
}, 13 ); | ||
} else { | ||
begin(); | ||
} | ||
return a; | ||
} | ||
function runLoggingCallbacks( key, args ) { | ||
var i, l, callbacks; | ||
function done() { | ||
var runtime, passed; | ||
callbacks = config.callbacks[ key ]; | ||
for ( i = 0, l = callbacks.length; i < l; i++ ) { | ||
callbacks[ i ]( args ); | ||
} | ||
} | ||
config.autorun = true; | ||
// DEPRECATED: This will be removed on 2.0.0+ | ||
// This function verifies if the loggingCallbacks were modified by the user | ||
// If so, it will restore it, assign the given callback and print a console warning | ||
function verifyLoggingCallbacks() { | ||
var loggingCallback, userCallback; | ||
for ( loggingCallback in loggingCallbacks ) { | ||
if ( QUnit[ loggingCallback ] !== loggingCallbacks[ loggingCallback ] ) { | ||
userCallback = QUnit[ loggingCallback ]; | ||
// Restore the callback function | ||
QUnit[ loggingCallback ] = loggingCallbacks[ loggingCallback ]; | ||
// Assign the deprecated given callback | ||
QUnit[ loggingCallback ]( userCallback ); | ||
if ( window.console && window.console.warn ) { | ||
window.console.warn( | ||
"QUnit." + loggingCallback + " was replaced with a new value.\n" + | ||
"Please, check out the documentation on how to apply logging callbacks.\n" + | ||
"Reference: http://api.qunitjs.com/category/callbacks/" | ||
); | ||
} | ||
} | ||
// Log the last module results | ||
if ( config.previousModule ) { | ||
runLoggingCallbacks( "moduleDone", { | ||
name: config.previousModule.name, | ||
tests: config.previousModule.tests, | ||
failed: config.moduleStats.bad, | ||
passed: config.moduleStats.all - config.moduleStats.bad, | ||
total: config.moduleStats.all, | ||
runtime: now() - config.moduleStats.started | ||
}); | ||
} | ||
} | ||
delete config.previousModule; | ||
// from jquery.js | ||
function inArray( elem, array ) { | ||
if ( array.indexOf ) { | ||
return array.indexOf( elem ); | ||
} | ||
runtime = now() - config.started; | ||
passed = config.stats.all - config.stats.bad; | ||
for ( var i = 0, length = array.length; i < length; i++ ) { | ||
if ( array[ i ] === elem ) { | ||
return i; | ||
} | ||
} | ||
return -1; | ||
runLoggingCallbacks( "done", { | ||
failed: config.stats.bad, | ||
passed: passed, | ||
total: config.stats.all, | ||
runtime: runtime | ||
}); | ||
} |
@@ -1,3 +0,1 @@ | ||
/*istanbul ignore next */ | ||
// jscs:disable maximumLineLength | ||
/* | ||
@@ -30,1059 +28,1085 @@ * This file is a modified version of google-diff-match-patch's JavaScript implementation | ||
* | ||
* QUnit.diff( "the quick brown fox jumped over", "the quick fox jumps over" ) === "the quick <del>brown </del> fox jump<ins>s</ins><del>ed</del over" | ||
*/ | ||
QUnit.diff = (function() { | ||
QUnit.diff = ( function() { | ||
function DiffMatchPatch() { | ||
} | ||
function DiffMatchPatch() { | ||
// DIFF FUNCTIONS | ||
// Defaults. | ||
// Redefine these in your program to override the defaults. | ||
// Number of seconds to map a diff before giving up (0 for infinity). | ||
this.DiffTimeout = 1.0; | ||
// Cost of an empty edit operation in terms of edit characters. | ||
this.DiffEditCost = 4; | ||
} | ||
// DIFF FUNCTIONS | ||
/** | ||
* The data structure representing a diff is an array of tuples: | ||
* [[DIFF_DELETE, 'Hello'], [DIFF_INSERT, 'Goodbye'], [DIFF_EQUAL, ' world.']] | ||
* which means: delete 'Hello', add 'Goodbye' and keep ' world.' | ||
*/ | ||
var DIFF_DELETE = -1, | ||
/** | ||
* The data structure representing a diff is an array of tuples: | ||
* [[DIFF_DELETE, 'Hello'], [DIFF_INSERT, 'Goodbye'], [DIFF_EQUAL, ' world.']] | ||
* which means: delete 'Hello', add 'Goodbye' and keep ' world.' | ||
*/ | ||
var DIFF_DELETE = -1, | ||
DIFF_INSERT = 1, | ||
DIFF_EQUAL = 0; | ||
/** | ||
* Find the differences between two texts. Simplifies the problem by stripping | ||
* any common prefix or suffix off the texts before diffing. | ||
* @param {string} text1 Old string to be diffed. | ||
* @param {string} text2 New string to be diffed. | ||
* @param {boolean=} optChecklines Optional speedup flag. If present and false, | ||
* then don't run a line-level diff first to identify the changed areas. | ||
* Defaults to true, which does a faster, slightly less optimal diff. | ||
* @param {number} optDeadline Optional time when the diff should be complete | ||
* by. Used internally for recursive calls. Users should set DiffTimeout | ||
* instead. | ||
* @return {!Array.<!DiffMatchPatch.Diff>} Array of diff tuples. | ||
*/ | ||
DiffMatchPatch.prototype.DiffMain = function( text1, text2, optChecklines, optDeadline ) { | ||
var deadline, checklines, commonlength, | ||
/** | ||
* Find the differences between two texts. Simplifies the problem by stripping | ||
* any common prefix or suffix off the texts before diffing. | ||
* @param {string} text1 Old string to be diffed. | ||
* @param {string} text2 New string to be diffed. | ||
* @param {boolean=} optChecklines Optional speedup flag. If present and false, | ||
* then don't run a line-level diff first to identify the changed areas. | ||
* Defaults to true, which does a faster, slightly less optimal diff. | ||
* @return {!Array.<!DiffMatchPatch.Diff>} Array of diff tuples. | ||
*/ | ||
DiffMatchPatch.prototype.DiffMain = function( text1, text2, optChecklines ) { | ||
var deadline, checklines, commonlength, | ||
commonprefix, commonsuffix, diffs; | ||
// Set a deadline by which time the diff must be complete. | ||
if ( typeof optDeadline === "undefined" ) { | ||
if ( this.DiffTimeout <= 0 ) { | ||
optDeadline = Number.MAX_VALUE; | ||
} else { | ||
optDeadline = ( new Date() ).getTime() + this.DiffTimeout * 1000; | ||
} | ||
} | ||
deadline = optDeadline; | ||
// Check for null inputs. | ||
if ( text1 === null || text2 === null ) { | ||
throw new Error( "Null input. (DiffMain)" ); | ||
} | ||
// The diff must be complete in up to 1 second. | ||
deadline = ( new Date() ).getTime() + 1000; | ||
// Check for equality (speedup). | ||
if ( text1 === text2 ) { | ||
if ( text1 ) { | ||
return [ | ||
[ DIFF_EQUAL, text1 ] | ||
]; | ||
} | ||
return []; | ||
} | ||
// Check for null inputs. | ||
if ( text1 === null || text2 === null ) { | ||
throw new Error( "Null input. (DiffMain)" ); | ||
} | ||
if ( typeof optChecklines === "undefined" ) { | ||
optChecklines = true; | ||
} | ||
// Check for equality (speedup). | ||
if ( text1 === text2 ) { | ||
if ( text1 ) { | ||
return [ | ||
[ DIFF_EQUAL, text1 ] | ||
]; | ||
} | ||
return []; | ||
} | ||
checklines = optChecklines; | ||
if ( typeof optChecklines === "undefined" ) { | ||
optChecklines = true; | ||
} | ||
// Trim off common prefix (speedup). | ||
commonlength = this.diffCommonPrefix( text1, text2 ); | ||
commonprefix = text1.substring( 0, commonlength ); | ||
text1 = text1.substring( commonlength ); | ||
text2 = text2.substring( commonlength ); | ||
checklines = optChecklines; | ||
// Trim off common suffix (speedup). | ||
///////// | ||
commonlength = this.diffCommonSuffix( text1, text2 ); | ||
commonsuffix = text1.substring( text1.length - commonlength ); | ||
text1 = text1.substring( 0, text1.length - commonlength ); | ||
text2 = text2.substring( 0, text2.length - commonlength ); | ||
// Trim off common prefix (speedup). | ||
commonlength = this.diffCommonPrefix( text1, text2 ); | ||
commonprefix = text1.substring( 0, commonlength ); | ||
text1 = text1.substring( commonlength ); | ||
text2 = text2.substring( commonlength ); | ||
// Compute the diff on the middle block. | ||
diffs = this.diffCompute( text1, text2, checklines, deadline ); | ||
// Trim off common suffix (speedup). | ||
commonlength = this.diffCommonSuffix( text1, text2 ); | ||
commonsuffix = text1.substring( text1.length - commonlength ); | ||
text1 = text1.substring( 0, text1.length - commonlength ); | ||
text2 = text2.substring( 0, text2.length - commonlength ); | ||
// Restore the prefix and suffix. | ||
if ( commonprefix ) { | ||
diffs.unshift( [ DIFF_EQUAL, commonprefix ] ); | ||
} | ||
if ( commonsuffix ) { | ||
diffs.push( [ DIFF_EQUAL, commonsuffix ] ); | ||
} | ||
this.diffCleanupMerge( diffs ); | ||
return diffs; | ||
}; | ||
// Compute the diff on the middle block. | ||
diffs = this.diffCompute( text1, text2, checklines, deadline ); | ||
/** | ||
* Reduce the number of edits by eliminating operationally trivial equalities. | ||
* @param {!Array.<!DiffMatchPatch.Diff>} diffs Array of diff tuples. | ||
*/ | ||
DiffMatchPatch.prototype.diffCleanupEfficiency = function( diffs ) { | ||
var changes, equalities, equalitiesLength, lastequality, | ||
// Restore the prefix and suffix. | ||
if ( commonprefix ) { | ||
diffs.unshift( [ DIFF_EQUAL, commonprefix ] ); | ||
} | ||
if ( commonsuffix ) { | ||
diffs.push( [ DIFF_EQUAL, commonsuffix ] ); | ||
} | ||
this.diffCleanupMerge( diffs ); | ||
return diffs; | ||
}; | ||
/** | ||
* Reduce the number of edits by eliminating operationally trivial equalities. | ||
* @param {!Array.<!DiffMatchPatch.Diff>} diffs Array of diff tuples. | ||
*/ | ||
DiffMatchPatch.prototype.diffCleanupEfficiency = function( diffs ) { | ||
var changes, equalities, equalitiesLength, lastequality, | ||
pointer, preIns, preDel, postIns, postDel; | ||
changes = false; | ||
equalities = []; // Stack of indices where equalities are found. | ||
equalitiesLength = 0; // Keeping our own length var is faster in JS. | ||
/** @type {?string} */ | ||
lastequality = null; | ||
// Always equal to diffs[equalities[equalitiesLength - 1]][1] | ||
pointer = 0; // Index of current position. | ||
// Is there an insertion operation before the last equality. | ||
preIns = false; | ||
// Is there a deletion operation before the last equality. | ||
preDel = false; | ||
// Is there an insertion operation after the last equality. | ||
postIns = false; | ||
// Is there a deletion operation after the last equality. | ||
postDel = false; | ||
while ( pointer < diffs.length ) { | ||
if ( diffs[ pointer ][ 0 ] === DIFF_EQUAL ) { // Equality found. | ||
if ( diffs[ pointer ][ 1 ].length < this.DiffEditCost && ( postIns || postDel ) ) { | ||
// Candidate found. | ||
equalities[ equalitiesLength++ ] = pointer; | ||
preIns = postIns; | ||
preDel = postDel; | ||
lastequality = diffs[ pointer ][ 1 ]; | ||
} else { | ||
// Not a candidate, and can never become one. | ||
equalitiesLength = 0; | ||
lastequality = null; | ||
} | ||
postIns = postDel = false; | ||
} else { // An insertion or deletion. | ||
if ( diffs[ pointer ][ 0 ] === DIFF_DELETE ) { | ||
postDel = true; | ||
} else { | ||
postIns = true; | ||
} | ||
/* | ||
* Five types to be split: | ||
* <ins>A</ins><del>B</del>XY<ins>C</ins><del>D</del> | ||
* <ins>A</ins>X<ins>C</ins><del>D</del> | ||
* <ins>A</ins><del>B</del>X<ins>C</ins> | ||
* <ins>A</del>X<ins>C</ins><del>D</del> | ||
* <ins>A</ins><del>B</del>X<del>C</del> | ||
*/ | ||
if ( lastequality && ( ( preIns && preDel && postIns && postDel ) || | ||
( ( lastequality.length < this.DiffEditCost / 2 ) && | ||
( preIns + preDel + postIns + postDel ) === 3 ) ) ) { | ||
// Duplicate record. | ||
diffs.splice( equalities[equalitiesLength - 1], 0, [ DIFF_DELETE, lastequality ] ); | ||
// Change second copy to insert. | ||
diffs[ equalities[ equalitiesLength - 1 ] + 1 ][ 0 ] = DIFF_INSERT; | ||
equalitiesLength--; // Throw away the equality we just deleted; | ||
lastequality = null; | ||
if (preIns && preDel) { | ||
// No changes made which could affect previous entry, keep going. | ||
postIns = postDel = true; | ||
equalitiesLength = 0; | ||
} else { | ||
equalitiesLength--; // Throw away the previous equality. | ||
pointer = equalitiesLength > 0 ? equalities[ equalitiesLength - 1 ] : -1; | ||
postIns = postDel = false; | ||
} | ||
changes = true; | ||
} | ||
} | ||
pointer++; | ||
} | ||
changes = false; | ||
equalities = []; // Stack of indices where equalities are found. | ||
equalitiesLength = 0; // Keeping our own length var is faster in JS. | ||
/** @type {?string} */ | ||
lastequality = null; | ||
// Always equal to diffs[equalities[equalitiesLength - 1]][1] | ||
pointer = 0; // Index of current position. | ||
// Is there an insertion operation before the last equality. | ||
preIns = false; | ||
// Is there a deletion operation before the last equality. | ||
preDel = false; | ||
// Is there an insertion operation after the last equality. | ||
postIns = false; | ||
// Is there a deletion operation after the last equality. | ||
postDel = false; | ||
while ( pointer < diffs.length ) { | ||
if ( changes ) { | ||
this.diffCleanupMerge( diffs ); | ||
} | ||
}; | ||
// Equality found. | ||
if ( diffs[ pointer ][ 0 ] === DIFF_EQUAL ) { | ||
if ( diffs[ pointer ][ 1 ].length < 4 && ( postIns || postDel ) ) { | ||
/** | ||
* Convert a diff array into a pretty HTML report. | ||
* @param {!Array.<!DiffMatchPatch.Diff>} diffs Array of diff tuples. | ||
* @param {integer} string to be beautified. | ||
* @return {string} HTML representation. | ||
*/ | ||
DiffMatchPatch.prototype.diffPrettyHtml = function( diffs ) { | ||
var op, data, x, html = []; | ||
for ( x = 0; x < diffs.length; x++ ) { | ||
op = diffs[x][0]; // Operation (insert, delete, equal) | ||
data = diffs[x][1]; // Text of change. | ||
switch ( op ) { | ||
case DIFF_INSERT: | ||
html[x] = "<ins>" + data + "</ins>"; | ||
break; | ||
case DIFF_DELETE: | ||
html[x] = "<del>" + data + "</del>"; | ||
break; | ||
case DIFF_EQUAL: | ||
html[x] = "<span>" + data + "</span>"; | ||
break; | ||
} | ||
} | ||
return html.join(""); | ||
}; | ||
// Candidate found. | ||
equalities[ equalitiesLength++ ] = pointer; | ||
preIns = postIns; | ||
preDel = postDel; | ||
lastequality = diffs[ pointer ][ 1 ]; | ||
} else { | ||
/** | ||
* Determine the common prefix of two strings. | ||
* @param {string} text1 First string. | ||
* @param {string} text2 Second string. | ||
* @return {number} The number of characters common to the start of each | ||
* string. | ||
*/ | ||
DiffMatchPatch.prototype.diffCommonPrefix = function( text1, text2 ) { | ||
var pointermid, pointermax, pointermin, pointerstart; | ||
// Quick check for common null cases. | ||
if ( !text1 || !text2 || text1.charAt(0) !== text2.charAt(0) ) { | ||
return 0; | ||
} | ||
// Binary search. | ||
// Performance analysis: http://neil.fraser.name/news/2007/10/09/ | ||
pointermin = 0; | ||
pointermax = Math.min( text1.length, text2.length ); | ||
pointermid = pointermax; | ||
pointerstart = 0; | ||
while ( pointermin < pointermid ) { | ||
if ( text1.substring( pointerstart, pointermid ) === text2.substring( pointerstart, pointermid ) ) { | ||
pointermin = pointermid; | ||
pointerstart = pointermin; | ||
} else { | ||
pointermax = pointermid; | ||
} | ||
pointermid = Math.floor( ( pointermax - pointermin ) / 2 + pointermin ); | ||
} | ||
return pointermid; | ||
}; | ||
// Not a candidate, and can never become one. | ||
equalitiesLength = 0; | ||
lastequality = null; | ||
} | ||
postIns = postDel = false; | ||
/** | ||
* Determine the common suffix of two strings. | ||
* @param {string} text1 First string. | ||
* @param {string} text2 Second string. | ||
* @return {number} The number of characters common to the end of each string. | ||
*/ | ||
DiffMatchPatch.prototype.diffCommonSuffix = function( text1, text2 ) { | ||
var pointermid, pointermax, pointermin, pointerend; | ||
// Quick check for common null cases. | ||
if (!text1 || !text2 || text1.charAt(text1.length - 1) !== text2.charAt(text2.length - 1)) { | ||
return 0; | ||
} | ||
// Binary search. | ||
// Performance analysis: http://neil.fraser.name/news/2007/10/09/ | ||
pointermin = 0; | ||
pointermax = Math.min(text1.length, text2.length); | ||
pointermid = pointermax; | ||
pointerend = 0; | ||
while ( pointermin < pointermid ) { | ||
if (text1.substring( text1.length - pointermid, text1.length - pointerend ) === | ||
text2.substring( text2.length - pointermid, text2.length - pointerend ) ) { | ||
pointermin = pointermid; | ||
pointerend = pointermin; | ||
} else { | ||
pointermax = pointermid; | ||
} | ||
pointermid = Math.floor( ( pointermax - pointermin ) / 2 + pointermin ); | ||
} | ||
return pointermid; | ||
}; | ||
// An insertion or deletion. | ||
} else { | ||
/** | ||
* Find the differences between two texts. Assumes that the texts do not | ||
* have any common prefix or suffix. | ||
* @param {string} text1 Old string to be diffed. | ||
* @param {string} text2 New string to be diffed. | ||
* @param {boolean} checklines Speedup flag. If false, then don't run a | ||
* line-level diff first to identify the changed areas. | ||
* If true, then run a faster, slightly less optimal diff. | ||
* @param {number} deadline Time when the diff should be complete by. | ||
* @return {!Array.<!DiffMatchPatch.Diff>} Array of diff tuples. | ||
* @private | ||
*/ | ||
DiffMatchPatch.prototype.diffCompute = function( text1, text2, checklines, deadline ) { | ||
var diffs, longtext, shorttext, i, hm, | ||
if ( diffs[ pointer ][ 0 ] === DIFF_DELETE ) { | ||
postDel = true; | ||
} else { | ||
postIns = true; | ||
} | ||
/* | ||
* Five types to be split: | ||
* <ins>A</ins><del>B</del>XY<ins>C</ins><del>D</del> | ||
* <ins>A</ins>X<ins>C</ins><del>D</del> | ||
* <ins>A</ins><del>B</del>X<ins>C</ins> | ||
* <ins>A</del>X<ins>C</ins><del>D</del> | ||
* <ins>A</ins><del>B</del>X<del>C</del> | ||
*/ | ||
if ( lastequality && ( ( preIns && preDel && postIns && postDel ) || | ||
( ( lastequality.length < 2 ) && | ||
( preIns + preDel + postIns + postDel ) === 3 ) ) ) { | ||
// Duplicate record. | ||
diffs.splice( | ||
equalities[ equalitiesLength - 1 ], | ||
0, | ||
[ DIFF_DELETE, lastequality ] | ||
); | ||
// Change second copy to insert. | ||
diffs[ equalities[ equalitiesLength - 1 ] + 1 ][ 0 ] = DIFF_INSERT; | ||
equalitiesLength--; // Throw away the equality we just deleted; | ||
lastequality = null; | ||
if ( preIns && preDel ) { | ||
// No changes made which could affect previous entry, keep going. | ||
postIns = postDel = true; | ||
equalitiesLength = 0; | ||
} else { | ||
equalitiesLength--; // Throw away the previous equality. | ||
pointer = equalitiesLength > 0 ? equalities[ equalitiesLength - 1 ] : -1; | ||
postIns = postDel = false; | ||
} | ||
changes = true; | ||
} | ||
} | ||
pointer++; | ||
} | ||
if ( changes ) { | ||
this.diffCleanupMerge( diffs ); | ||
} | ||
}; | ||
/** | ||
* Convert a diff array into a pretty HTML report. | ||
* @param {!Array.<!DiffMatchPatch.Diff>} diffs Array of diff tuples. | ||
* @param {integer} string to be beautified. | ||
* @return {string} HTML representation. | ||
*/ | ||
DiffMatchPatch.prototype.diffPrettyHtml = function( diffs ) { | ||
var op, data, x, | ||
html = []; | ||
for ( x = 0; x < diffs.length; x++ ) { | ||
op = diffs[ x ][ 0 ]; // Operation (insert, delete, equal) | ||
data = diffs[ x ][ 1 ]; // Text of change. | ||
switch ( op ) { | ||
case DIFF_INSERT: | ||
html[ x ] = "<ins>" + data + "</ins>"; | ||
break; | ||
case DIFF_DELETE: | ||
html[ x ] = "<del>" + data + "</del>"; | ||
break; | ||
case DIFF_EQUAL: | ||
html[ x ] = "<span>" + data + "</span>"; | ||
break; | ||
} | ||
} | ||
return html.join( "" ); | ||
}; | ||
/** | ||
* Determine the common prefix of two strings. | ||
* @param {string} text1 First string. | ||
* @param {string} text2 Second string. | ||
* @return {number} The number of characters common to the start of each | ||
* string. | ||
*/ | ||
DiffMatchPatch.prototype.diffCommonPrefix = function( text1, text2 ) { | ||
var pointermid, pointermax, pointermin, pointerstart; | ||
// Quick check for common null cases. | ||
if ( !text1 || !text2 || text1.charAt( 0 ) !== text2.charAt( 0 ) ) { | ||
return 0; | ||
} | ||
// Binary search. | ||
// Performance analysis: http://neil.fraser.name/news/2007/10/09/ | ||
pointermin = 0; | ||
pointermax = Math.min( text1.length, text2.length ); | ||
pointermid = pointermax; | ||
pointerstart = 0; | ||
while ( pointermin < pointermid ) { | ||
if ( text1.substring( pointerstart, pointermid ) === | ||
text2.substring( pointerstart, pointermid ) ) { | ||
pointermin = pointermid; | ||
pointerstart = pointermin; | ||
} else { | ||
pointermax = pointermid; | ||
} | ||
pointermid = Math.floor( ( pointermax - pointermin ) / 2 + pointermin ); | ||
} | ||
return pointermid; | ||
}; | ||
/** | ||
* Determine the common suffix of two strings. | ||
* @param {string} text1 First string. | ||
* @param {string} text2 Second string. | ||
* @return {number} The number of characters common to the end of each string. | ||
*/ | ||
DiffMatchPatch.prototype.diffCommonSuffix = function( text1, text2 ) { | ||
var pointermid, pointermax, pointermin, pointerend; | ||
// Quick check for common null cases. | ||
if ( !text1 || | ||
!text2 || | ||
text1.charAt( text1.length - 1 ) !== text2.charAt( text2.length - 1 ) ) { | ||
return 0; | ||
} | ||
// Binary search. | ||
// Performance analysis: http://neil.fraser.name/news/2007/10/09/ | ||
pointermin = 0; | ||
pointermax = Math.min( text1.length, text2.length ); | ||
pointermid = pointermax; | ||
pointerend = 0; | ||
while ( pointermin < pointermid ) { | ||
if ( text1.substring( text1.length - pointermid, text1.length - pointerend ) === | ||
text2.substring( text2.length - pointermid, text2.length - pointerend ) ) { | ||
pointermin = pointermid; | ||
pointerend = pointermin; | ||
} else { | ||
pointermax = pointermid; | ||
} | ||
pointermid = Math.floor( ( pointermax - pointermin ) / 2 + pointermin ); | ||
} | ||
return pointermid; | ||
}; | ||
/** | ||
* Find the differences between two texts. Assumes that the texts do not | ||
* have any common prefix or suffix. | ||
* @param {string} text1 Old string to be diffed. | ||
* @param {string} text2 New string to be diffed. | ||
* @param {boolean} checklines Speedup flag. If false, then don't run a | ||
* line-level diff first to identify the changed areas. | ||
* If true, then run a faster, slightly less optimal diff. | ||
* @param {number} deadline Time when the diff should be complete by. | ||
* @return {!Array.<!DiffMatchPatch.Diff>} Array of diff tuples. | ||
* @private | ||
*/ | ||
DiffMatchPatch.prototype.diffCompute = function( text1, text2, checklines, deadline ) { | ||
var diffs, longtext, shorttext, i, hm, | ||
text1A, text2A, text1B, text2B, | ||
midCommon, diffsA, diffsB; | ||
if ( !text1 ) { | ||
// Just add some text (speedup). | ||
return [ | ||
[ DIFF_INSERT, text2 ] | ||
]; | ||
} | ||
if ( !text1 ) { | ||
// Just add some text (speedup). | ||
return [ | ||
[ DIFF_INSERT, text2 ] | ||
]; | ||
} | ||
if (!text2) { | ||
// Just delete some text (speedup). | ||
return [ | ||
[ DIFF_DELETE, text1 ] | ||
]; | ||
} | ||
if ( !text2 ) { | ||
// Just delete some text (speedup). | ||
return [ | ||
[ DIFF_DELETE, text1 ] | ||
]; | ||
} | ||
longtext = text1.length > text2.length ? text1 : text2; | ||
shorttext = text1.length > text2.length ? text2 : text1; | ||
i = longtext.indexOf( shorttext ); | ||
if ( i !== -1 ) { | ||
// Shorter text is inside the longer text (speedup). | ||
diffs = [ | ||
[ DIFF_INSERT, longtext.substring( 0, i ) ], | ||
[ DIFF_EQUAL, shorttext ], | ||
[ DIFF_INSERT, longtext.substring( i + shorttext.length ) ] | ||
]; | ||
// Swap insertions for deletions if diff is reversed. | ||
if ( text1.length > text2.length ) { | ||
diffs[0][0] = diffs[2][0] = DIFF_DELETE; | ||
} | ||
return diffs; | ||
} | ||
longtext = text1.length > text2.length ? text1 : text2; | ||
shorttext = text1.length > text2.length ? text2 : text1; | ||
i = longtext.indexOf( shorttext ); | ||
if ( i !== -1 ) { | ||
// Shorter text is inside the longer text (speedup). | ||
diffs = [ | ||
[ DIFF_INSERT, longtext.substring( 0, i ) ], | ||
[ DIFF_EQUAL, shorttext ], | ||
[ DIFF_INSERT, longtext.substring( i + shorttext.length ) ] | ||
]; | ||
// Swap insertions for deletions if diff is reversed. | ||
if ( text1.length > text2.length ) { | ||
diffs[ 0 ][ 0 ] = diffs[ 2 ][ 0 ] = DIFF_DELETE; | ||
} | ||
return diffs; | ||
} | ||
if ( shorttext.length === 1 ) { | ||
// Single character string. | ||
// After the previous speedup, the character can't be an equality. | ||
return [ | ||
[ DIFF_DELETE, text1 ], | ||
[ DIFF_INSERT, text2 ] | ||
]; | ||
} | ||
if ( shorttext.length === 1 ) { | ||
// Single character string. | ||
// After the previous speedup, the character can't be an equality. | ||
return [ | ||
[ DIFF_DELETE, text1 ], | ||
[ DIFF_INSERT, text2 ] | ||
]; | ||
} | ||
// Check to see if the problem can be split in two. | ||
hm = this.diffHalfMatch(text1, text2); | ||
if (hm) { | ||
// A half-match was found, sort out the return data. | ||
text1A = hm[0]; | ||
text1B = hm[1]; | ||
text2A = hm[2]; | ||
text2B = hm[3]; | ||
midCommon = hm[4]; | ||
// Send both pairs off for separate processing. | ||
diffsA = this.DiffMain(text1A, text2A, checklines, deadline); | ||
diffsB = this.DiffMain(text1B, text2B, checklines, deadline); | ||
// Merge the results. | ||
return diffsA.concat([ | ||
[ DIFF_EQUAL, midCommon ] | ||
], diffsB); | ||
} | ||
// Check to see if the problem can be split in two. | ||
hm = this.diffHalfMatch( text1, text2 ); | ||
if ( hm ) { | ||
// A half-match was found, sort out the return data. | ||
text1A = hm[ 0 ]; | ||
text1B = hm[ 1 ]; | ||
text2A = hm[ 2 ]; | ||
text2B = hm[ 3 ]; | ||
midCommon = hm[ 4 ]; | ||
// Send both pairs off for separate processing. | ||
diffsA = this.DiffMain( text1A, text2A, checklines, deadline ); | ||
diffsB = this.DiffMain( text1B, text2B, checklines, deadline ); | ||
// Merge the results. | ||
return diffsA.concat( [ | ||
[ DIFF_EQUAL, midCommon ] | ||
], diffsB ); | ||
} | ||
if (checklines && text1.length > 100 && text2.length > 100) { | ||
return this.diffLineMode(text1, text2, deadline); | ||
} | ||
if ( checklines && text1.length > 100 && text2.length > 100 ) { | ||
return this.diffLineMode( text1, text2, deadline ); | ||
} | ||
return this.diffBisect(text1, text2, deadline); | ||
}; | ||
return this.diffBisect( text1, text2, deadline ); | ||
}; | ||
/** | ||
* Do the two texts share a substring which is at least half the length of the | ||
* longer text? | ||
* This speedup can produce non-minimal diffs. | ||
* @param {string} text1 First string. | ||
* @param {string} text2 Second string. | ||
* @return {Array.<string>} Five element Array, containing the prefix of | ||
* text1, the suffix of text1, the prefix of text2, the suffix of | ||
* text2 and the common middle. Or null if there was no match. | ||
* @private | ||
*/ | ||
DiffMatchPatch.prototype.diffHalfMatch = function(text1, text2) { | ||
var longtext, shorttext, dmp, | ||
/** | ||
* Do the two texts share a substring which is at least half the length of the | ||
* longer text? | ||
* This speedup can produce non-minimal diffs. | ||
* @param {string} text1 First string. | ||
* @param {string} text2 Second string. | ||
* @return {Array.<string>} Five element Array, containing the prefix of | ||
* text1, the suffix of text1, the prefix of text2, the suffix of | ||
* text2 and the common middle. Or null if there was no match. | ||
* @private | ||
*/ | ||
DiffMatchPatch.prototype.diffHalfMatch = function( text1, text2 ) { | ||
var longtext, shorttext, dmp, | ||
text1A, text2B, text2A, text1B, midCommon, | ||
hm1, hm2, hm; | ||
if (this.DiffTimeout <= 0) { | ||
// Don't risk returning a non-optimal diff if we have unlimited time. | ||
return null; | ||
} | ||
longtext = text1.length > text2.length ? text1 : text2; | ||
shorttext = text1.length > text2.length ? text2 : text1; | ||
if (longtext.length < 4 || shorttext.length * 2 < longtext.length) { | ||
return null; // Pointless. | ||
} | ||
dmp = this; // 'this' becomes 'window' in a closure. | ||
/** | ||
* Does a substring of shorttext exist within longtext such that the substring | ||
* is at least half the length of longtext? | ||
* Closure, but does not reference any external variables. | ||
* @param {string} longtext Longer string. | ||
* @param {string} shorttext Shorter string. | ||
* @param {number} i Start index of quarter length substring within longtext. | ||
* @return {Array.<string>} Five element Array, containing the prefix of | ||
* longtext, the suffix of longtext, the prefix of shorttext, the suffix | ||
* of shorttext and the common middle. Or null if there was no match. | ||
* @private | ||
*/ | ||
function diffHalfMatchI(longtext, shorttext, i) { | ||
var seed, j, bestCommon, prefixLength, suffixLength, | ||
longtext = text1.length > text2.length ? text1 : text2; | ||
shorttext = text1.length > text2.length ? text2 : text1; | ||
if ( longtext.length < 4 || shorttext.length * 2 < longtext.length ) { | ||
return null; // Pointless. | ||
} | ||
dmp = this; // 'this' becomes 'window' in a closure. | ||
/** | ||
* Does a substring of shorttext exist within longtext such that the substring | ||
* is at least half the length of longtext? | ||
* Closure, but does not reference any external variables. | ||
* @param {string} longtext Longer string. | ||
* @param {string} shorttext Shorter string. | ||
* @param {number} i Start index of quarter length substring within longtext. | ||
* @return {Array.<string>} Five element Array, containing the prefix of | ||
* longtext, the suffix of longtext, the prefix of shorttext, the suffix | ||
* of shorttext and the common middle. Or null if there was no match. | ||
* @private | ||
*/ | ||
function diffHalfMatchI( longtext, shorttext, i ) { | ||
var seed, j, bestCommon, prefixLength, suffixLength, | ||
bestLongtextA, bestLongtextB, bestShorttextA, bestShorttextB; | ||
// Start with a 1/4 length substring at position i as a seed. | ||
seed = longtext.substring(i, i + Math.floor(longtext.length / 4)); | ||
j = -1; | ||
bestCommon = ""; | ||
while ((j = shorttext.indexOf(seed, j + 1)) !== -1) { | ||
prefixLength = dmp.diffCommonPrefix(longtext.substring(i), | ||
shorttext.substring(j)); | ||
suffixLength = dmp.diffCommonSuffix(longtext.substring(0, i), | ||
shorttext.substring(0, j)); | ||
if (bestCommon.length < suffixLength + prefixLength) { | ||
bestCommon = shorttext.substring(j - suffixLength, j) + | ||
shorttext.substring(j, j + prefixLength); | ||
bestLongtextA = longtext.substring(0, i - suffixLength); | ||
bestLongtextB = longtext.substring(i + prefixLength); | ||
bestShorttextA = shorttext.substring(0, j - suffixLength); | ||
bestShorttextB = shorttext.substring(j + prefixLength); | ||
} | ||
} | ||
if (bestCommon.length * 2 >= longtext.length) { | ||
return [ bestLongtextA, bestLongtextB, | ||
bestShorttextA, bestShorttextB, bestCommon | ||
]; | ||
} else { | ||
return null; | ||
} | ||
} | ||
// Start with a 1/4 length substring at position i as a seed. | ||
seed = longtext.substring( i, i + Math.floor( longtext.length / 4 ) ); | ||
j = -1; | ||
bestCommon = ""; | ||
while ( ( j = shorttext.indexOf( seed, j + 1 ) ) !== -1 ) { | ||
prefixLength = dmp.diffCommonPrefix( longtext.substring( i ), | ||
shorttext.substring( j ) ); | ||
suffixLength = dmp.diffCommonSuffix( longtext.substring( 0, i ), | ||
shorttext.substring( 0, j ) ); | ||
if ( bestCommon.length < suffixLength + prefixLength ) { | ||
bestCommon = shorttext.substring( j - suffixLength, j ) + | ||
shorttext.substring( j, j + prefixLength ); | ||
bestLongtextA = longtext.substring( 0, i - suffixLength ); | ||
bestLongtextB = longtext.substring( i + prefixLength ); | ||
bestShorttextA = shorttext.substring( 0, j - suffixLength ); | ||
bestShorttextB = shorttext.substring( j + prefixLength ); | ||
} | ||
} | ||
if ( bestCommon.length * 2 >= longtext.length ) { | ||
return [ bestLongtextA, bestLongtextB, | ||
bestShorttextA, bestShorttextB, bestCommon | ||
]; | ||
} else { | ||
return null; | ||
} | ||
} | ||
// First check if the second quarter is the seed for a half-match. | ||
hm1 = diffHalfMatchI(longtext, shorttext, | ||
Math.ceil(longtext.length / 4)); | ||
// Check again based on the third quarter. | ||
hm2 = diffHalfMatchI(longtext, shorttext, | ||
Math.ceil(longtext.length / 2)); | ||
if (!hm1 && !hm2) { | ||
return null; | ||
} else if (!hm2) { | ||
hm = hm1; | ||
} else if (!hm1) { | ||
hm = hm2; | ||
} else { | ||
// Both matched. Select the longest. | ||
hm = hm1[4].length > hm2[4].length ? hm1 : hm2; | ||
} | ||
// First check if the second quarter is the seed for a half-match. | ||
hm1 = diffHalfMatchI( longtext, shorttext, | ||
Math.ceil( longtext.length / 4 ) ); | ||
// Check again based on the third quarter. | ||
hm2 = diffHalfMatchI( longtext, shorttext, | ||
Math.ceil( longtext.length / 2 ) ); | ||
if ( !hm1 && !hm2 ) { | ||
return null; | ||
} else if ( !hm2 ) { | ||
hm = hm1; | ||
} else if ( !hm1 ) { | ||
hm = hm2; | ||
} else { | ||
// Both matched. Select the longest. | ||
hm = hm1[ 4 ].length > hm2[ 4 ].length ? hm1 : hm2; | ||
} | ||
// A half-match was found, sort out the return data. | ||
text1A, text1B, text2A, text2B; | ||
if (text1.length > text2.length) { | ||
text1A = hm[0]; | ||
text1B = hm[1]; | ||
text2A = hm[2]; | ||
text2B = hm[3]; | ||
} else { | ||
text2A = hm[0]; | ||
text2B = hm[1]; | ||
text1A = hm[2]; | ||
text1B = hm[3]; | ||
} | ||
midCommon = hm[4]; | ||
return [ text1A, text1B, text2A, text2B, midCommon ]; | ||
}; | ||
// A half-match was found, sort out the return data. | ||
text1A, text1B, text2A, text2B; | ||
if ( text1.length > text2.length ) { | ||
text1A = hm[ 0 ]; | ||
text1B = hm[ 1 ]; | ||
text2A = hm[ 2 ]; | ||
text2B = hm[ 3 ]; | ||
} else { | ||
text2A = hm[ 0 ]; | ||
text2B = hm[ 1 ]; | ||
text1A = hm[ 2 ]; | ||
text1B = hm[ 3 ]; | ||
} | ||
midCommon = hm[ 4 ]; | ||
return [ text1A, text1B, text2A, text2B, midCommon ]; | ||
}; | ||
/** | ||
* Do a quick line-level diff on both strings, then rediff the parts for | ||
* greater accuracy. | ||
* This speedup can produce non-minimal diffs. | ||
* @param {string} text1 Old string to be diffed. | ||
* @param {string} text2 New string to be diffed. | ||
* @param {number} deadline Time when the diff should be complete by. | ||
* @return {!Array.<!DiffMatchPatch.Diff>} Array of diff tuples. | ||
* @private | ||
*/ | ||
DiffMatchPatch.prototype.diffLineMode = function(text1, text2, deadline) { | ||
var a, diffs, linearray, pointer, countInsert, | ||
/** | ||
* Do a quick line-level diff on both strings, then rediff the parts for | ||
* greater accuracy. | ||
* This speedup can produce non-minimal diffs. | ||
* @param {string} text1 Old string to be diffed. | ||
* @param {string} text2 New string to be diffed. | ||
* @param {number} deadline Time when the diff should be complete by. | ||
* @return {!Array.<!DiffMatchPatch.Diff>} Array of diff tuples. | ||
* @private | ||
*/ | ||
DiffMatchPatch.prototype.diffLineMode = function( text1, text2, deadline ) { | ||
var a, diffs, linearray, pointer, countInsert, | ||
countDelete, textInsert, textDelete, j; | ||
// Scan the text on a line-by-line basis first. | ||
a = this.diffLinesToChars(text1, text2); | ||
text1 = a.chars1; | ||
text2 = a.chars2; | ||
linearray = a.lineArray; | ||
// Scan the text on a line-by-line basis first. | ||
a = this.diffLinesToChars( text1, text2 ); | ||
text1 = a.chars1; | ||
text2 = a.chars2; | ||
linearray = a.lineArray; | ||
diffs = this.DiffMain(text1, text2, false, deadline); | ||
diffs = this.DiffMain( text1, text2, false, deadline ); | ||
// Convert the diff back to original text. | ||
this.diffCharsToLines(diffs, linearray); | ||
// Eliminate freak matches (e.g. blank lines) | ||
this.diffCleanupSemantic(diffs); | ||
// Convert the diff back to original text. | ||
this.diffCharsToLines( diffs, linearray ); | ||
// Eliminate freak matches (e.g. blank lines) | ||
this.diffCleanupSemantic( diffs ); | ||
// Rediff any replacement blocks, this time character-by-character. | ||
// Add a dummy entry at the end. | ||
diffs.push( [ DIFF_EQUAL, "" ] ); | ||
pointer = 0; | ||
countDelete = 0; | ||
countInsert = 0; | ||
textDelete = ""; | ||
textInsert = ""; | ||
while (pointer < diffs.length) { | ||
switch ( diffs[pointer][0] ) { | ||
case DIFF_INSERT: | ||
countInsert++; | ||
textInsert += diffs[pointer][1]; | ||
break; | ||
case DIFF_DELETE: | ||
countDelete++; | ||
textDelete += diffs[pointer][1]; | ||
break; | ||
case DIFF_EQUAL: | ||
// Upon reaching an equality, check for prior redundancies. | ||
if (countDelete >= 1 && countInsert >= 1) { | ||
// Delete the offending records and add the merged ones. | ||
diffs.splice(pointer - countDelete - countInsert, | ||
countDelete + countInsert); | ||
pointer = pointer - countDelete - countInsert; | ||
a = this.DiffMain(textDelete, textInsert, false, deadline); | ||
for (j = a.length - 1; j >= 0; j--) { | ||
diffs.splice( pointer, 0, a[j] ); | ||
} | ||
pointer = pointer + a.length; | ||
} | ||
countInsert = 0; | ||
countDelete = 0; | ||
textDelete = ""; | ||
textInsert = ""; | ||
break; | ||
} | ||
pointer++; | ||
} | ||
diffs.pop(); // Remove the dummy entry at the end. | ||
// Rediff any replacement blocks, this time character-by-character. | ||
// Add a dummy entry at the end. | ||
diffs.push( [ DIFF_EQUAL, "" ] ); | ||
pointer = 0; | ||
countDelete = 0; | ||
countInsert = 0; | ||
textDelete = ""; | ||
textInsert = ""; | ||
while ( pointer < diffs.length ) { | ||
switch ( diffs[ pointer ][ 0 ] ) { | ||
case DIFF_INSERT: | ||
countInsert++; | ||
textInsert += diffs[ pointer ][ 1 ]; | ||
break; | ||
case DIFF_DELETE: | ||
countDelete++; | ||
textDelete += diffs[ pointer ][ 1 ]; | ||
break; | ||
case DIFF_EQUAL: | ||
// Upon reaching an equality, check for prior redundancies. | ||
if ( countDelete >= 1 && countInsert >= 1 ) { | ||
// Delete the offending records and add the merged ones. | ||
diffs.splice( pointer - countDelete - countInsert, | ||
countDelete + countInsert ); | ||
pointer = pointer - countDelete - countInsert; | ||
a = this.DiffMain( textDelete, textInsert, false, deadline ); | ||
for ( j = a.length - 1; j >= 0; j-- ) { | ||
diffs.splice( pointer, 0, a[ j ] ); | ||
} | ||
pointer = pointer + a.length; | ||
} | ||
countInsert = 0; | ||
countDelete = 0; | ||
textDelete = ""; | ||
textInsert = ""; | ||
break; | ||
} | ||
pointer++; | ||
} | ||
diffs.pop(); // Remove the dummy entry at the end. | ||
return diffs; | ||
}; | ||
return diffs; | ||
}; | ||
/** | ||
* Find the 'middle snake' of a diff, split the problem in two | ||
* and return the recursively constructed diff. | ||
* See Myers 1986 paper: An O(ND) Difference Algorithm and Its Variations. | ||
* @param {string} text1 Old string to be diffed. | ||
* @param {string} text2 New string to be diffed. | ||
* @param {number} deadline Time at which to bail if not yet complete. | ||
* @return {!Array.<!DiffMatchPatch.Diff>} Array of diff tuples. | ||
* @private | ||
*/ | ||
DiffMatchPatch.prototype.diffBisect = function(text1, text2, deadline) { | ||
var text1Length, text2Length, maxD, vOffset, vLength, | ||
/** | ||
* Find the 'middle snake' of a diff, split the problem in two | ||
* and return the recursively constructed diff. | ||
* See Myers 1986 paper: An O(ND) Difference Algorithm and Its Variations. | ||
* @param {string} text1 Old string to be diffed. | ||
* @param {string} text2 New string to be diffed. | ||
* @param {number} deadline Time at which to bail if not yet complete. | ||
* @return {!Array.<!DiffMatchPatch.Diff>} Array of diff tuples. | ||
* @private | ||
*/ | ||
DiffMatchPatch.prototype.diffBisect = function( text1, text2, deadline ) { | ||
var text1Length, text2Length, maxD, vOffset, vLength, | ||
v1, v2, x, delta, front, k1start, k1end, k2start, | ||
k2end, k2Offset, k1Offset, x1, x2, y1, y2, d, k1, k2; | ||
// Cache the text lengths to prevent multiple calls. | ||
text1Length = text1.length; | ||
text2Length = text2.length; | ||
maxD = Math.ceil((text1Length + text2Length) / 2); | ||
vOffset = maxD; | ||
vLength = 2 * maxD; | ||
v1 = new Array(vLength); | ||
v2 = new Array(vLength); | ||
// Setting all elements to -1 is faster in Chrome & Firefox than mixing | ||
// integers and undefined. | ||
for (x = 0; x < vLength; x++) { | ||
v1[x] = -1; | ||
v2[x] = -1; | ||
} | ||
v1[vOffset + 1] = 0; | ||
v2[vOffset + 1] = 0; | ||
delta = text1Length - text2Length; | ||
// If the total number of characters is odd, then the front path will collide | ||
// with the reverse path. | ||
front = (delta % 2 !== 0); | ||
// Offsets for start and end of k loop. | ||
// Prevents mapping of space beyond the grid. | ||
k1start = 0; | ||
k1end = 0; | ||
k2start = 0; | ||
k2end = 0; | ||
for (d = 0; d < maxD; d++) { | ||
// Bail out if deadline is reached. | ||
if ((new Date()).getTime() > deadline) { | ||
break; | ||
} | ||
// Cache the text lengths to prevent multiple calls. | ||
text1Length = text1.length; | ||
text2Length = text2.length; | ||
maxD = Math.ceil( ( text1Length + text2Length ) / 2 ); | ||
vOffset = maxD; | ||
vLength = 2 * maxD; | ||
v1 = new Array( vLength ); | ||
v2 = new Array( vLength ); | ||
// Setting all elements to -1 is faster in Chrome & Firefox than mixing | ||
// integers and undefined. | ||
for ( x = 0; x < vLength; x++ ) { | ||
v1[ x ] = -1; | ||
v2[ x ] = -1; | ||
} | ||
v1[ vOffset + 1 ] = 0; | ||
v2[ vOffset + 1 ] = 0; | ||
delta = text1Length - text2Length; | ||
// If the total number of characters is odd, then the front path will collide | ||
// with the reverse path. | ||
front = ( delta % 2 !== 0 ); | ||
// Offsets for start and end of k loop. | ||
// Prevents mapping of space beyond the grid. | ||
k1start = 0; | ||
k1end = 0; | ||
k2start = 0; | ||
k2end = 0; | ||
for ( d = 0; d < maxD; d++ ) { | ||
// Bail out if deadline is reached. | ||
if ( ( new Date() ).getTime() > deadline ) { | ||
break; | ||
} | ||
// Walk the front path one step. | ||
for (k1 = -d + k1start; k1 <= d - k1end; k1 += 2) { | ||
k1Offset = vOffset + k1; | ||
if ( k1 === -d || ( k1 !== d && v1[ k1Offset - 1 ] < v1[ k1Offset + 1 ] ) ) { | ||
x1 = v1[k1Offset + 1]; | ||
} else { | ||
x1 = v1[k1Offset - 1] + 1; | ||
} | ||
y1 = x1 - k1; | ||
while (x1 < text1Length && y1 < text2Length && | ||
text1.charAt(x1) === text2.charAt(y1)) { | ||
x1++; | ||
y1++; | ||
} | ||
v1[k1Offset] = x1; | ||
if (x1 > text1Length) { | ||
// Ran off the right of the graph. | ||
k1end += 2; | ||
} else if (y1 > text2Length) { | ||
// Ran off the bottom of the graph. | ||
k1start += 2; | ||
} else if (front) { | ||
k2Offset = vOffset + delta - k1; | ||
if (k2Offset >= 0 && k2Offset < vLength && v2[k2Offset] !== -1) { | ||
// Mirror x2 onto top-left coordinate system. | ||
x2 = text1Length - v2[k2Offset]; | ||
if (x1 >= x2) { | ||
// Overlap detected. | ||
return this.diffBisectSplit(text1, text2, x1, y1, deadline); | ||
} | ||
} | ||
} | ||
} | ||
// Walk the front path one step. | ||
for ( k1 = -d + k1start; k1 <= d - k1end; k1 += 2 ) { | ||
k1Offset = vOffset + k1; | ||
if ( k1 === -d || ( k1 !== d && v1[ k1Offset - 1 ] < v1[ k1Offset + 1 ] ) ) { | ||
x1 = v1[ k1Offset + 1 ]; | ||
} else { | ||
x1 = v1[ k1Offset - 1 ] + 1; | ||
} | ||
y1 = x1 - k1; | ||
while ( x1 < text1Length && y1 < text2Length && | ||
text1.charAt( x1 ) === text2.charAt( y1 ) ) { | ||
x1++; | ||
y1++; | ||
} | ||
v1[ k1Offset ] = x1; | ||
if ( x1 > text1Length ) { | ||
// Ran off the right of the graph. | ||
k1end += 2; | ||
} else if ( y1 > text2Length ) { | ||
// Ran off the bottom of the graph. | ||
k1start += 2; | ||
} else if ( front ) { | ||
k2Offset = vOffset + delta - k1; | ||
if ( k2Offset >= 0 && k2Offset < vLength && v2[ k2Offset ] !== -1 ) { | ||
// Mirror x2 onto top-left coordinate system. | ||
x2 = text1Length - v2[ k2Offset ]; | ||
if ( x1 >= x2 ) { | ||
// Overlap detected. | ||
return this.diffBisectSplit( text1, text2, x1, y1, deadline ); | ||
} | ||
} | ||
} | ||
} | ||
// Walk the reverse path one step. | ||
for (k2 = -d + k2start; k2 <= d - k2end; k2 += 2) { | ||
k2Offset = vOffset + k2; | ||
if ( k2 === -d || (k2 !== d && v2[ k2Offset - 1 ] < v2[ k2Offset + 1 ] ) ) { | ||
x2 = v2[k2Offset + 1]; | ||
} else { | ||
x2 = v2[k2Offset - 1] + 1; | ||
} | ||
y2 = x2 - k2; | ||
while (x2 < text1Length && y2 < text2Length && | ||
text1.charAt(text1Length - x2 - 1) === | ||
text2.charAt(text2Length - y2 - 1)) { | ||
x2++; | ||
y2++; | ||
} | ||
v2[k2Offset] = x2; | ||
if (x2 > text1Length) { | ||
// Ran off the left of the graph. | ||
k2end += 2; | ||
} else if (y2 > text2Length) { | ||
// Ran off the top of the graph. | ||
k2start += 2; | ||
} else if (!front) { | ||
k1Offset = vOffset + delta - k2; | ||
if (k1Offset >= 0 && k1Offset < vLength && v1[k1Offset] !== -1) { | ||
x1 = v1[k1Offset]; | ||
y1 = vOffset + x1 - k1Offset; | ||
// Mirror x2 onto top-left coordinate system. | ||
x2 = text1Length - x2; | ||
if (x1 >= x2) { | ||
// Overlap detected. | ||
return this.diffBisectSplit(text1, text2, x1, y1, deadline); | ||
} | ||
} | ||
} | ||
} | ||
} | ||
// Diff took too long and hit the deadline or | ||
// number of diffs equals number of characters, no commonality at all. | ||
return [ | ||
[ DIFF_DELETE, text1 ], | ||
[ DIFF_INSERT, text2 ] | ||
]; | ||
}; | ||
// Walk the reverse path one step. | ||
for ( k2 = -d + k2start; k2 <= d - k2end; k2 += 2 ) { | ||
k2Offset = vOffset + k2; | ||
if ( k2 === -d || ( k2 !== d && v2[ k2Offset - 1 ] < v2[ k2Offset + 1 ] ) ) { | ||
x2 = v2[ k2Offset + 1 ]; | ||
} else { | ||
x2 = v2[ k2Offset - 1 ] + 1; | ||
} | ||
y2 = x2 - k2; | ||
while ( x2 < text1Length && y2 < text2Length && | ||
text1.charAt( text1Length - x2 - 1 ) === | ||
text2.charAt( text2Length - y2 - 1 ) ) { | ||
x2++; | ||
y2++; | ||
} | ||
v2[ k2Offset ] = x2; | ||
if ( x2 > text1Length ) { | ||
// Ran off the left of the graph. | ||
k2end += 2; | ||
} else if ( y2 > text2Length ) { | ||
// Ran off the top of the graph. | ||
k2start += 2; | ||
} else if ( !front ) { | ||
k1Offset = vOffset + delta - k2; | ||
if ( k1Offset >= 0 && k1Offset < vLength && v1[ k1Offset ] !== -1 ) { | ||
x1 = v1[ k1Offset ]; | ||
y1 = vOffset + x1 - k1Offset; | ||
// Mirror x2 onto top-left coordinate system. | ||
x2 = text1Length - x2; | ||
if ( x1 >= x2 ) { | ||
// Overlap detected. | ||
return this.diffBisectSplit( text1, text2, x1, y1, deadline ); | ||
} | ||
} | ||
} | ||
} | ||
} | ||
// Diff took too long and hit the deadline or | ||
// number of diffs equals number of characters, no commonality at all. | ||
return [ | ||
[ DIFF_DELETE, text1 ], | ||
[ DIFF_INSERT, text2 ] | ||
]; | ||
}; | ||
/** | ||
* Given the location of the 'middle snake', split the diff in two parts | ||
* and recurse. | ||
* @param {string} text1 Old string to be diffed. | ||
* @param {string} text2 New string to be diffed. | ||
* @param {number} x Index of split point in text1. | ||
* @param {number} y Index of split point in text2. | ||
* @param {number} deadline Time at which to bail if not yet complete. | ||
* @return {!Array.<!DiffMatchPatch.Diff>} Array of diff tuples. | ||
* @private | ||
*/ | ||
DiffMatchPatch.prototype.diffBisectSplit = function( text1, text2, x, y, deadline ) { | ||
var text1a, text1b, text2a, text2b, diffs, diffsb; | ||
text1a = text1.substring(0, x); | ||
text2a = text2.substring(0, y); | ||
text1b = text1.substring(x); | ||
text2b = text2.substring(y); | ||
/** | ||
* Given the location of the 'middle snake', split the diff in two parts | ||
* and recurse. | ||
* @param {string} text1 Old string to be diffed. | ||
* @param {string} text2 New string to be diffed. | ||
* @param {number} x Index of split point in text1. | ||
* @param {number} y Index of split point in text2. | ||
* @param {number} deadline Time at which to bail if not yet complete. | ||
* @return {!Array.<!DiffMatchPatch.Diff>} Array of diff tuples. | ||
* @private | ||
*/ | ||
DiffMatchPatch.prototype.diffBisectSplit = function( text1, text2, x, y, deadline ) { | ||
var text1a, text1b, text2a, text2b, diffs, diffsb; | ||
text1a = text1.substring( 0, x ); | ||
text2a = text2.substring( 0, y ); | ||
text1b = text1.substring( x ); | ||
text2b = text2.substring( y ); | ||
// Compute both diffs serially. | ||
diffs = this.DiffMain(text1a, text2a, false, deadline); | ||
diffsb = this.DiffMain(text1b, text2b, false, deadline); | ||
// Compute both diffs serially. | ||
diffs = this.DiffMain( text1a, text2a, false, deadline ); | ||
diffsb = this.DiffMain( text1b, text2b, false, deadline ); | ||
return diffs.concat(diffsb); | ||
}; | ||
return diffs.concat( diffsb ); | ||
}; | ||
/** | ||
* Reduce the number of edits by eliminating semantically trivial equalities. | ||
* @param {!Array.<!DiffMatchPatch.Diff>} diffs Array of diff tuples. | ||
*/ | ||
DiffMatchPatch.prototype.diffCleanupSemantic = function(diffs) { | ||
var changes, equalities, equalitiesLength, lastequality, | ||
/** | ||
* Reduce the number of edits by eliminating semantically trivial equalities. | ||
* @param {!Array.<!DiffMatchPatch.Diff>} diffs Array of diff tuples. | ||
*/ | ||
DiffMatchPatch.prototype.diffCleanupSemantic = function( diffs ) { | ||
var changes, equalities, equalitiesLength, lastequality, | ||
pointer, lengthInsertions2, lengthDeletions2, lengthInsertions1, | ||
lengthDeletions1, deletion, insertion, overlapLength1, overlapLength2; | ||
changes = false; | ||
equalities = []; // Stack of indices where equalities are found. | ||
equalitiesLength = 0; // Keeping our own length var is faster in JS. | ||
/** @type {?string} */ | ||
lastequality = null; | ||
// Always equal to diffs[equalities[equalitiesLength - 1]][1] | ||
pointer = 0; // Index of current position. | ||
// Number of characters that changed prior to the equality. | ||
lengthInsertions1 = 0; | ||
lengthDeletions1 = 0; | ||
// Number of characters that changed after the equality. | ||
lengthInsertions2 = 0; | ||
lengthDeletions2 = 0; | ||
while (pointer < diffs.length) { | ||
if (diffs[pointer][0] === DIFF_EQUAL) { // Equality found. | ||
equalities[equalitiesLength++] = pointer; | ||
lengthInsertions1 = lengthInsertions2; | ||
lengthDeletions1 = lengthDeletions2; | ||
lengthInsertions2 = 0; | ||
lengthDeletions2 = 0; | ||
lastequality = diffs[pointer][1]; | ||
} else { // An insertion or deletion. | ||
if (diffs[pointer][0] === DIFF_INSERT) { | ||
lengthInsertions2 += diffs[pointer][1].length; | ||
} else { | ||
lengthDeletions2 += diffs[pointer][1].length; | ||
} | ||
// Eliminate an equality that is smaller or equal to the edits on both | ||
// sides of it. | ||
if (lastequality && (lastequality.length <= | ||
Math.max(lengthInsertions1, lengthDeletions1)) && | ||
(lastequality.length <= Math.max(lengthInsertions2, | ||
lengthDeletions2))) { | ||
// Duplicate record. | ||
diffs.splice( equalities[ equalitiesLength - 1 ], 0, [ DIFF_DELETE, lastequality ] ); | ||
// Change second copy to insert. | ||
diffs[equalities[equalitiesLength - 1] + 1][0] = DIFF_INSERT; | ||
// Throw away the equality we just deleted. | ||
equalitiesLength--; | ||
// Throw away the previous equality (it needs to be reevaluated). | ||
equalitiesLength--; | ||
pointer = equalitiesLength > 0 ? equalities[equalitiesLength - 1] : -1; | ||
lengthInsertions1 = 0; // Reset the counters. | ||
lengthDeletions1 = 0; | ||
lengthInsertions2 = 0; | ||
lengthDeletions2 = 0; | ||
lastequality = null; | ||
changes = true; | ||
} | ||
} | ||
pointer++; | ||
} | ||
changes = false; | ||
equalities = []; // Stack of indices where equalities are found. | ||
equalitiesLength = 0; // Keeping our own length var is faster in JS. | ||
/** @type {?string} */ | ||
lastequality = null; | ||
// Always equal to diffs[equalities[equalitiesLength - 1]][1] | ||
pointer = 0; // Index of current position. | ||
// Number of characters that changed prior to the equality. | ||
lengthInsertions1 = 0; | ||
lengthDeletions1 = 0; | ||
// Number of characters that changed after the equality. | ||
lengthInsertions2 = 0; | ||
lengthDeletions2 = 0; | ||
while ( pointer < diffs.length ) { | ||
if ( diffs[ pointer ][ 0 ] === DIFF_EQUAL ) { // Equality found. | ||
equalities[ equalitiesLength++ ] = pointer; | ||
lengthInsertions1 = lengthInsertions2; | ||
lengthDeletions1 = lengthDeletions2; | ||
lengthInsertions2 = 0; | ||
lengthDeletions2 = 0; | ||
lastequality = diffs[ pointer ][ 1 ]; | ||
} else { // An insertion or deletion. | ||
if ( diffs[ pointer ][ 0 ] === DIFF_INSERT ) { | ||
lengthInsertions2 += diffs[ pointer ][ 1 ].length; | ||
} else { | ||
lengthDeletions2 += diffs[ pointer ][ 1 ].length; | ||
} | ||
// Eliminate an equality that is smaller or equal to the edits on both | ||
// sides of it. | ||
if ( lastequality && ( lastequality.length <= | ||
Math.max( lengthInsertions1, lengthDeletions1 ) ) && | ||
( lastequality.length <= Math.max( lengthInsertions2, | ||
lengthDeletions2 ) ) ) { | ||
// Normalize the diff. | ||
if (changes) { | ||
this.diffCleanupMerge(diffs); | ||
} | ||
// Duplicate record. | ||
diffs.splice( | ||
equalities[ equalitiesLength - 1 ], | ||
0, | ||
[ DIFF_DELETE, lastequality ] | ||
); | ||
// Find any overlaps between deletions and insertions. | ||
// e.g: <del>abcxxx</del><ins>xxxdef</ins> | ||
// -> <del>abc</del>xxx<ins>def</ins> | ||
// e.g: <del>xxxabc</del><ins>defxxx</ins> | ||
// -> <ins>def</ins>xxx<del>abc</del> | ||
// Only extract an overlap if it is as big as the edit ahead or behind it. | ||
pointer = 1; | ||
while (pointer < diffs.length) { | ||
if (diffs[pointer - 1][0] === DIFF_DELETE && | ||
diffs[pointer][0] === DIFF_INSERT) { | ||
deletion = diffs[pointer - 1][1]; | ||
insertion = diffs[pointer][1]; | ||
overlapLength1 = this.diffCommonOverlap(deletion, insertion); | ||
overlapLength2 = this.diffCommonOverlap(insertion, deletion); | ||
if (overlapLength1 >= overlapLength2) { | ||
if (overlapLength1 >= deletion.length / 2 || | ||
overlapLength1 >= insertion.length / 2) { | ||
// Overlap found. Insert an equality and trim the surrounding edits. | ||
diffs.splice( pointer, 0, [ DIFF_EQUAL, insertion.substring( 0, overlapLength1 ) ] ); | ||
diffs[pointer - 1][1] = | ||
deletion.substring(0, deletion.length - overlapLength1); | ||
diffs[pointer + 1][1] = insertion.substring(overlapLength1); | ||
pointer++; | ||
} | ||
} else { | ||
if (overlapLength2 >= deletion.length / 2 || | ||
overlapLength2 >= insertion.length / 2) { | ||
// Reverse overlap found. | ||
// Insert an equality and swap and trim the surrounding edits. | ||
diffs.splice( pointer, 0, [ DIFF_EQUAL, deletion.substring( 0, overlapLength2 ) ] ); | ||
diffs[pointer - 1][0] = DIFF_INSERT; | ||
diffs[pointer - 1][1] = | ||
insertion.substring(0, insertion.length - overlapLength2); | ||
diffs[pointer + 1][0] = DIFF_DELETE; | ||
diffs[pointer + 1][1] = | ||
deletion.substring(overlapLength2); | ||
pointer++; | ||
} | ||
} | ||
pointer++; | ||
} | ||
pointer++; | ||
} | ||
}; | ||
// Change second copy to insert. | ||
diffs[ equalities[ equalitiesLength - 1 ] + 1 ][ 0 ] = DIFF_INSERT; | ||
/** | ||
* Determine if the suffix of one string is the prefix of another. | ||
* @param {string} text1 First string. | ||
* @param {string} text2 Second string. | ||
* @return {number} The number of characters common to the end of the first | ||
* string and the start of the second string. | ||
* @private | ||
*/ | ||
DiffMatchPatch.prototype.diffCommonOverlap = function(text1, text2) { | ||
var text1Length, text2Length, textLength, | ||
// Throw away the equality we just deleted. | ||
equalitiesLength--; | ||
// Throw away the previous equality (it needs to be reevaluated). | ||
equalitiesLength--; | ||
pointer = equalitiesLength > 0 ? equalities[ equalitiesLength - 1 ] : -1; | ||
// Reset the counters. | ||
lengthInsertions1 = 0; | ||
lengthDeletions1 = 0; | ||
lengthInsertions2 = 0; | ||
lengthDeletions2 = 0; | ||
lastequality = null; | ||
changes = true; | ||
} | ||
} | ||
pointer++; | ||
} | ||
// Normalize the diff. | ||
if ( changes ) { | ||
this.diffCleanupMerge( diffs ); | ||
} | ||
// Find any overlaps between deletions and insertions. | ||
// e.g: <del>abcxxx</del><ins>xxxdef</ins> | ||
// -> <del>abc</del>xxx<ins>def</ins> | ||
// e.g: <del>xxxabc</del><ins>defxxx</ins> | ||
// -> <ins>def</ins>xxx<del>abc</del> | ||
// Only extract an overlap if it is as big as the edit ahead or behind it. | ||
pointer = 1; | ||
while ( pointer < diffs.length ) { | ||
if ( diffs[ pointer - 1 ][ 0 ] === DIFF_DELETE && | ||
diffs[ pointer ][ 0 ] === DIFF_INSERT ) { | ||
deletion = diffs[ pointer - 1 ][ 1 ]; | ||
insertion = diffs[ pointer ][ 1 ]; | ||
overlapLength1 = this.diffCommonOverlap( deletion, insertion ); | ||
overlapLength2 = this.diffCommonOverlap( insertion, deletion ); | ||
if ( overlapLength1 >= overlapLength2 ) { | ||
if ( overlapLength1 >= deletion.length / 2 || | ||
overlapLength1 >= insertion.length / 2 ) { | ||
// Overlap found. Insert an equality and trim the surrounding edits. | ||
diffs.splice( | ||
pointer, | ||
0, | ||
[ DIFF_EQUAL, insertion.substring( 0, overlapLength1 ) ] | ||
); | ||
diffs[ pointer - 1 ][ 1 ] = | ||
deletion.substring( 0, deletion.length - overlapLength1 ); | ||
diffs[ pointer + 1 ][ 1 ] = insertion.substring( overlapLength1 ); | ||
pointer++; | ||
} | ||
} else { | ||
if ( overlapLength2 >= deletion.length / 2 || | ||
overlapLength2 >= insertion.length / 2 ) { | ||
// Reverse overlap found. | ||
// Insert an equality and swap and trim the surrounding edits. | ||
diffs.splice( | ||
pointer, | ||
0, | ||
[ DIFF_EQUAL, deletion.substring( 0, overlapLength2 ) ] | ||
); | ||
diffs[ pointer - 1 ][ 0 ] = DIFF_INSERT; | ||
diffs[ pointer - 1 ][ 1 ] = | ||
insertion.substring( 0, insertion.length - overlapLength2 ); | ||
diffs[ pointer + 1 ][ 0 ] = DIFF_DELETE; | ||
diffs[ pointer + 1 ][ 1 ] = | ||
deletion.substring( overlapLength2 ); | ||
pointer++; | ||
} | ||
} | ||
pointer++; | ||
} | ||
pointer++; | ||
} | ||
}; | ||
/** | ||
* Determine if the suffix of one string is the prefix of another. | ||
* @param {string} text1 First string. | ||
* @param {string} text2 Second string. | ||
* @return {number} The number of characters common to the end of the first | ||
* string and the start of the second string. | ||
* @private | ||
*/ | ||
DiffMatchPatch.prototype.diffCommonOverlap = function( text1, text2 ) { | ||
var text1Length, text2Length, textLength, | ||
best, length, pattern, found; | ||
// Cache the text lengths to prevent multiple calls. | ||
text1Length = text1.length; | ||
text2Length = text2.length; | ||
// Eliminate the null case. | ||
if (text1Length === 0 || text2Length === 0) { | ||
return 0; | ||
} | ||
// Truncate the longer string. | ||
if (text1Length > text2Length) { | ||
text1 = text1.substring(text1Length - text2Length); | ||
} else if (text1Length < text2Length) { | ||
text2 = text2.substring(0, text1Length); | ||
} | ||
textLength = Math.min(text1Length, text2Length); | ||
// Quick check for the worst case. | ||
if (text1 === text2) { | ||
return textLength; | ||
} | ||
// Cache the text lengths to prevent multiple calls. | ||
text1Length = text1.length; | ||
text2Length = text2.length; | ||
// Eliminate the null case. | ||
if ( text1Length === 0 || text2Length === 0 ) { | ||
return 0; | ||
} | ||
// Truncate the longer string. | ||
if ( text1Length > text2Length ) { | ||
text1 = text1.substring( text1Length - text2Length ); | ||
} else if ( text1Length < text2Length ) { | ||
text2 = text2.substring( 0, text1Length ); | ||
} | ||
textLength = Math.min( text1Length, text2Length ); | ||
// Quick check for the worst case. | ||
if ( text1 === text2 ) { | ||
return textLength; | ||
} | ||
// Start by looking for a single character match | ||
// and increase length until no match is found. | ||
// Performance analysis: http://neil.fraser.name/news/2010/11/04/ | ||
best = 0; | ||
length = 1; | ||
while (true) { | ||
pattern = text1.substring(textLength - length); | ||
found = text2.indexOf(pattern); | ||
if (found === -1) { | ||
return best; | ||
} | ||
length += found; | ||
if (found === 0 || text1.substring(textLength - length) === | ||
text2.substring(0, length)) { | ||
best = length; | ||
length++; | ||
} | ||
} | ||
}; | ||
// Start by looking for a single character match | ||
// and increase length until no match is found. | ||
// Performance analysis: http://neil.fraser.name/news/2010/11/04/ | ||
best = 0; | ||
length = 1; | ||
while ( true ) { | ||
pattern = text1.substring( textLength - length ); | ||
found = text2.indexOf( pattern ); | ||
if ( found === -1 ) { | ||
return best; | ||
} | ||
length += found; | ||
if ( found === 0 || text1.substring( textLength - length ) === | ||
text2.substring( 0, length ) ) { | ||
best = length; | ||
length++; | ||
} | ||
} | ||
}; | ||
/** | ||
* Split two texts into an array of strings. Reduce the texts to a string of | ||
* hashes where each Unicode character represents one line. | ||
* @param {string} text1 First string. | ||
* @param {string} text2 Second string. | ||
* @return {{chars1: string, chars2: string, lineArray: !Array.<string>}} | ||
* An object containing the encoded text1, the encoded text2 and | ||
* the array of unique strings. | ||
* The zeroth element of the array of unique strings is intentionally blank. | ||
* @private | ||
*/ | ||
DiffMatchPatch.prototype.diffLinesToChars = function(text1, text2) { | ||
var lineArray, lineHash, chars1, chars2; | ||
lineArray = []; // e.g. lineArray[4] === 'Hello\n' | ||
lineHash = {}; // e.g. lineHash['Hello\n'] === 4 | ||
/** | ||
* Split two texts into an array of strings. Reduce the texts to a string of | ||
* hashes where each Unicode character represents one line. | ||
* @param {string} text1 First string. | ||
* @param {string} text2 Second string. | ||
* @return {{chars1: string, chars2: string, lineArray: !Array.<string>}} | ||
* An object containing the encoded text1, the encoded text2 and | ||
* the array of unique strings. | ||
* The zeroth element of the array of unique strings is intentionally blank. | ||
* @private | ||
*/ | ||
DiffMatchPatch.prototype.diffLinesToChars = function( text1, text2 ) { | ||
var lineArray, lineHash, chars1, chars2; | ||
lineArray = []; // e.g. lineArray[4] === 'Hello\n' | ||
lineHash = {}; // e.g. lineHash['Hello\n'] === 4 | ||
// '\x00' is a valid character, but various debuggers don't like it. | ||
// So we'll insert a junk entry to avoid generating a null character. | ||
lineArray[0] = ""; | ||
// '\x00' is a valid character, but various debuggers don't like it. | ||
// So we'll insert a junk entry to avoid generating a null character. | ||
lineArray[ 0 ] = ""; | ||
/** | ||
* Split a text into an array of strings. Reduce the texts to a string of | ||
* hashes where each Unicode character represents one line. | ||
* Modifies linearray and linehash through being a closure. | ||
* @param {string} text String to encode. | ||
* @return {string} Encoded string. | ||
* @private | ||
*/ | ||
function diffLinesToCharsMunge(text) { | ||
var chars, lineStart, lineEnd, lineArrayLength, line; | ||
chars = ""; | ||
// Walk the text, pulling out a substring for each line. | ||
// text.split('\n') would would temporarily double our memory footprint. | ||
// Modifying text would create many large strings to garbage collect. | ||
lineStart = 0; | ||
lineEnd = -1; | ||
// Keeping our own length variable is faster than looking it up. | ||
lineArrayLength = lineArray.length; | ||
while (lineEnd < text.length - 1) { | ||
lineEnd = text.indexOf("\n", lineStart); | ||
if (lineEnd === -1) { | ||
lineEnd = text.length - 1; | ||
} | ||
line = text.substring(lineStart, lineEnd + 1); | ||
lineStart = lineEnd + 1; | ||
/** | ||
* Split a text into an array of strings. Reduce the texts to a string of | ||
* hashes where each Unicode character represents one line. | ||
* Modifies linearray and linehash through being a closure. | ||
* @param {string} text String to encode. | ||
* @return {string} Encoded string. | ||
* @private | ||
*/ | ||
function diffLinesToCharsMunge( text ) { | ||
var chars, lineStart, lineEnd, lineArrayLength, line; | ||
chars = ""; | ||
// Walk the text, pulling out a substring for each line. | ||
// text.split('\n') would would temporarily double our memory footprint. | ||
// Modifying text would create many large strings to garbage collect. | ||
lineStart = 0; | ||
lineEnd = -1; | ||
// Keeping our own length variable is faster than looking it up. | ||
lineArrayLength = lineArray.length; | ||
while ( lineEnd < text.length - 1 ) { | ||
lineEnd = text.indexOf( "\n", lineStart ); | ||
if ( lineEnd === -1 ) { | ||
lineEnd = text.length - 1; | ||
} | ||
line = text.substring( lineStart, lineEnd + 1 ); | ||
lineStart = lineEnd + 1; | ||
if (lineHash.hasOwnProperty ? lineHash.hasOwnProperty(line) : | ||
(lineHash[line] !== undefined)) { | ||
chars += String.fromCharCode( lineHash[ line ] ); | ||
} else { | ||
chars += String.fromCharCode(lineArrayLength); | ||
lineHash[line] = lineArrayLength; | ||
lineArray[lineArrayLength++] = line; | ||
} | ||
} | ||
return chars; | ||
} | ||
if ( lineHash.hasOwnProperty ? lineHash.hasOwnProperty( line ) : | ||
( lineHash[ line ] !== undefined ) ) { | ||
chars += String.fromCharCode( lineHash[ line ] ); | ||
} else { | ||
chars += String.fromCharCode( lineArrayLength ); | ||
lineHash[ line ] = lineArrayLength; | ||
lineArray[ lineArrayLength++ ] = line; | ||
} | ||
} | ||
return chars; | ||
} | ||
chars1 = diffLinesToCharsMunge(text1); | ||
chars2 = diffLinesToCharsMunge(text2); | ||
return { | ||
chars1: chars1, | ||
chars2: chars2, | ||
lineArray: lineArray | ||
}; | ||
}; | ||
chars1 = diffLinesToCharsMunge( text1 ); | ||
chars2 = diffLinesToCharsMunge( text2 ); | ||
return { | ||
chars1: chars1, | ||
chars2: chars2, | ||
lineArray: lineArray | ||
}; | ||
}; | ||
/** | ||
* Rehydrate the text in a diff from a string of line hashes to real lines of | ||
* text. | ||
* @param {!Array.<!DiffMatchPatch.Diff>} diffs Array of diff tuples. | ||
* @param {!Array.<string>} lineArray Array of unique strings. | ||
* @private | ||
*/ | ||
DiffMatchPatch.prototype.diffCharsToLines = function( diffs, lineArray ) { | ||
var x, chars, text, y; | ||
for ( x = 0; x < diffs.length; x++ ) { | ||
chars = diffs[x][1]; | ||
text = []; | ||
for ( y = 0; y < chars.length; y++ ) { | ||
text[y] = lineArray[chars.charCodeAt(y)]; | ||
} | ||
diffs[x][1] = text.join(""); | ||
} | ||
}; | ||
/** | ||
* Rehydrate the text in a diff from a string of line hashes to real lines of | ||
* text. | ||
* @param {!Array.<!DiffMatchPatch.Diff>} diffs Array of diff tuples. | ||
* @param {!Array.<string>} lineArray Array of unique strings. | ||
* @private | ||
*/ | ||
DiffMatchPatch.prototype.diffCharsToLines = function( diffs, lineArray ) { | ||
var x, chars, text, y; | ||
for ( x = 0; x < diffs.length; x++ ) { | ||
chars = diffs[ x ][ 1 ]; | ||
text = []; | ||
for ( y = 0; y < chars.length; y++ ) { | ||
text[ y ] = lineArray[ chars.charCodeAt( y ) ]; | ||
} | ||
diffs[ x ][ 1 ] = text.join( "" ); | ||
} | ||
}; | ||
/** | ||
* Reorder and merge like edit sections. Merge equalities. | ||
* Any edit section can move as long as it doesn't cross an equality. | ||
* @param {!Array.<!DiffMatchPatch.Diff>} diffs Array of diff tuples. | ||
*/ | ||
DiffMatchPatch.prototype.diffCleanupMerge = function(diffs) { | ||
var pointer, countDelete, countInsert, textInsert, textDelete, | ||
commonlength, changes; | ||
diffs.push( [ DIFF_EQUAL, "" ] ); // Add a dummy entry at the end. | ||
pointer = 0; | ||
countDelete = 0; | ||
countInsert = 0; | ||
textDelete = ""; | ||
textInsert = ""; | ||
commonlength; | ||
while (pointer < diffs.length) { | ||
switch ( diffs[ pointer ][ 0 ] ) { | ||
case DIFF_INSERT: | ||
countInsert++; | ||
textInsert += diffs[pointer][1]; | ||
pointer++; | ||
break; | ||
case DIFF_DELETE: | ||
countDelete++; | ||
textDelete += diffs[pointer][1]; | ||
pointer++; | ||
break; | ||
case DIFF_EQUAL: | ||
// Upon reaching an equality, check for prior redundancies. | ||
if (countDelete + countInsert > 1) { | ||
if (countDelete !== 0 && countInsert !== 0) { | ||
// Factor out any common prefixies. | ||
commonlength = this.diffCommonPrefix(textInsert, textDelete); | ||
if (commonlength !== 0) { | ||
if ((pointer - countDelete - countInsert) > 0 && | ||
diffs[pointer - countDelete - countInsert - 1][0] === | ||
DIFF_EQUAL) { | ||
diffs[pointer - countDelete - countInsert - 1][1] += | ||
textInsert.substring(0, commonlength); | ||
} else { | ||
diffs.splice( 0, 0, [ DIFF_EQUAL, | ||
textInsert.substring( 0, commonlength ) | ||
] ); | ||
pointer++; | ||
} | ||
textInsert = textInsert.substring(commonlength); | ||
textDelete = textDelete.substring(commonlength); | ||
} | ||
// Factor out any common suffixies. | ||
commonlength = this.diffCommonSuffix(textInsert, textDelete); | ||
if (commonlength !== 0) { | ||
diffs[pointer][1] = textInsert.substring(textInsert.length - | ||
commonlength) + diffs[pointer][1]; | ||
textInsert = textInsert.substring(0, textInsert.length - | ||
commonlength); | ||
textDelete = textDelete.substring(0, textDelete.length - | ||
commonlength); | ||
} | ||
} | ||
// Delete the offending records and add the merged ones. | ||
if (countDelete === 0) { | ||
diffs.splice( pointer - countInsert, | ||
countDelete + countInsert, [ DIFF_INSERT, textInsert ] ); | ||
} else if (countInsert === 0) { | ||
diffs.splice( pointer - countDelete, | ||
countDelete + countInsert, [ DIFF_DELETE, textDelete ] ); | ||
} else { | ||
diffs.splice( pointer - countDelete - countInsert, | ||
countDelete + countInsert, [ DIFF_DELETE, textDelete ], [ DIFF_INSERT, textInsert ] ); | ||
} | ||
pointer = pointer - countDelete - countInsert + | ||
(countDelete ? 1 : 0) + (countInsert ? 1 : 0) + 1; | ||
} else if (pointer !== 0 && diffs[pointer - 1][0] === DIFF_EQUAL) { | ||
// Merge this equality with the previous one. | ||
diffs[pointer - 1][1] += diffs[pointer][1]; | ||
diffs.splice(pointer, 1); | ||
} else { | ||
pointer++; | ||
} | ||
countInsert = 0; | ||
countDelete = 0; | ||
textDelete = ""; | ||
textInsert = ""; | ||
break; | ||
} | ||
} | ||
if (diffs[diffs.length - 1][1] === "") { | ||
diffs.pop(); // Remove the dummy entry at the end. | ||
} | ||
/** | ||
* Reorder and merge like edit sections. Merge equalities. | ||
* Any edit section can move as long as it doesn't cross an equality. | ||
* @param {!Array.<!DiffMatchPatch.Diff>} diffs Array of diff tuples. | ||
*/ | ||
DiffMatchPatch.prototype.diffCleanupMerge = function( diffs ) { | ||
var pointer, countDelete, countInsert, textInsert, textDelete, | ||
commonlength, changes, diffPointer, position; | ||
diffs.push( [ DIFF_EQUAL, "" ] ); // Add a dummy entry at the end. | ||
pointer = 0; | ||
countDelete = 0; | ||
countInsert = 0; | ||
textDelete = ""; | ||
textInsert = ""; | ||
commonlength; | ||
while ( pointer < diffs.length ) { | ||
switch ( diffs[ pointer ][ 0 ] ) { | ||
case DIFF_INSERT: | ||
countInsert++; | ||
textInsert += diffs[ pointer ][ 1 ]; | ||
pointer++; | ||
break; | ||
case DIFF_DELETE: | ||
countDelete++; | ||
textDelete += diffs[ pointer ][ 1 ]; | ||
pointer++; | ||
break; | ||
case DIFF_EQUAL: | ||
// Upon reaching an equality, check for prior redundancies. | ||
if ( countDelete + countInsert > 1 ) { | ||
if ( countDelete !== 0 && countInsert !== 0 ) { | ||
// Factor out any common prefixies. | ||
commonlength = this.diffCommonPrefix( textInsert, textDelete ); | ||
if ( commonlength !== 0 ) { | ||
if ( ( pointer - countDelete - countInsert ) > 0 && | ||
diffs[ pointer - countDelete - countInsert - 1 ][ 0 ] === | ||
DIFF_EQUAL ) { | ||
diffs[ pointer - countDelete - countInsert - 1 ][ 1 ] += | ||
textInsert.substring( 0, commonlength ); | ||
} else { | ||
diffs.splice( 0, 0, [ DIFF_EQUAL, | ||
textInsert.substring( 0, commonlength ) | ||
] ); | ||
pointer++; | ||
} | ||
textInsert = textInsert.substring( commonlength ); | ||
textDelete = textDelete.substring( commonlength ); | ||
} | ||
// Factor out any common suffixies. | ||
commonlength = this.diffCommonSuffix( textInsert, textDelete ); | ||
if ( commonlength !== 0 ) { | ||
diffs[ pointer ][ 1 ] = textInsert.substring( textInsert.length - | ||
commonlength ) + diffs[ pointer ][ 1 ]; | ||
textInsert = textInsert.substring( 0, textInsert.length - | ||
commonlength ); | ||
textDelete = textDelete.substring( 0, textDelete.length - | ||
commonlength ); | ||
} | ||
} | ||
// Delete the offending records and add the merged ones. | ||
if ( countDelete === 0 ) { | ||
diffs.splice( pointer - countInsert, | ||
countDelete + countInsert, [ DIFF_INSERT, textInsert ] ); | ||
} else if ( countInsert === 0 ) { | ||
diffs.splice( pointer - countDelete, | ||
countDelete + countInsert, [ DIFF_DELETE, textDelete ] ); | ||
} else { | ||
diffs.splice( | ||
pointer - countDelete - countInsert, | ||
countDelete + countInsert, | ||
[ DIFF_DELETE, textDelete ], [ DIFF_INSERT, textInsert ] | ||
); | ||
} | ||
pointer = pointer - countDelete - countInsert + | ||
( countDelete ? 1 : 0 ) + ( countInsert ? 1 : 0 ) + 1; | ||
} else if ( pointer !== 0 && diffs[ pointer - 1 ][ 0 ] === DIFF_EQUAL ) { | ||
// Second pass: look for single edits surrounded on both sides by equalities | ||
// which can be shifted sideways to eliminate an equality. | ||
// e.g: A<ins>BA</ins>C -> <ins>AB</ins>AC | ||
changes = false; | ||
pointer = 1; | ||
// Intentionally ignore the first and last element (don't need checking). | ||
while (pointer < diffs.length - 1) { | ||
if (diffs[pointer - 1][0] === DIFF_EQUAL && | ||
diffs[pointer + 1][0] === DIFF_EQUAL) { | ||
// This is a single edit surrounded by equalities. | ||
if ( diffs[ pointer ][ 1 ].substring( diffs[ pointer ][ 1 ].length - | ||
diffs[ pointer - 1 ][ 1 ].length ) === diffs[ pointer - 1 ][ 1 ] ) { | ||
// Shift the edit over the previous equality. | ||
diffs[pointer][1] = diffs[pointer - 1][1] + | ||
diffs[pointer][1].substring(0, diffs[pointer][1].length - | ||
diffs[pointer - 1][1].length); | ||
diffs[pointer + 1][1] = diffs[pointer - 1][1] + diffs[pointer + 1][1]; | ||
diffs.splice(pointer - 1, 1); | ||
changes = true; | ||
} else if ( diffs[ pointer ][ 1 ].substring( 0, diffs[ pointer + 1 ][ 1 ].length ) === | ||
diffs[ pointer + 1 ][ 1 ] ) { | ||
// Shift the edit over the next equality. | ||
diffs[pointer - 1][1] += diffs[pointer + 1][1]; | ||
diffs[pointer][1] = | ||
diffs[pointer][1].substring(diffs[pointer + 1][1].length) + | ||
diffs[pointer + 1][1]; | ||
diffs.splice(pointer + 1, 1); | ||
changes = true; | ||
} | ||
} | ||
pointer++; | ||
} | ||
// If shifts were made, the diff needs reordering and another shift sweep. | ||
if (changes) { | ||
this.diffCleanupMerge(diffs); | ||
} | ||
}; | ||
// Merge this equality with the previous one. | ||
diffs[ pointer - 1 ][ 1 ] += diffs[ pointer ][ 1 ]; | ||
diffs.splice( pointer, 1 ); | ||
} else { | ||
pointer++; | ||
} | ||
countInsert = 0; | ||
countDelete = 0; | ||
textDelete = ""; | ||
textInsert = ""; | ||
break; | ||
} | ||
} | ||
if ( diffs[ diffs.length - 1 ][ 1 ] === "" ) { | ||
diffs.pop(); // Remove the dummy entry at the end. | ||
} | ||
return function(o, n) { | ||
// Second pass: look for single edits surrounded on both sides by equalities | ||
// which can be shifted sideways to eliminate an equality. | ||
// e.g: A<ins>BA</ins>C -> <ins>AB</ins>AC | ||
changes = false; | ||
pointer = 1; | ||
// Intentionally ignore the first and last element (don't need checking). | ||
while ( pointer < diffs.length - 1 ) { | ||
if ( diffs[ pointer - 1 ][ 0 ] === DIFF_EQUAL && | ||
diffs[ pointer + 1 ][ 0 ] === DIFF_EQUAL ) { | ||
diffPointer = diffs[ pointer ][ 1 ]; | ||
position = diffPointer.substring( | ||
diffPointer.length - diffs[ pointer - 1 ][ 1 ].length | ||
); | ||
// This is a single edit surrounded by equalities. | ||
if ( position === diffs[ pointer - 1 ][ 1 ] ) { | ||
// Shift the edit over the previous equality. | ||
diffs[ pointer ][ 1 ] = diffs[ pointer - 1 ][ 1 ] + | ||
diffs[ pointer ][ 1 ].substring( 0, diffs[ pointer ][ 1 ].length - | ||
diffs[ pointer - 1 ][ 1 ].length ); | ||
diffs[ pointer + 1 ][ 1 ] = | ||
diffs[ pointer - 1 ][ 1 ] + diffs[ pointer + 1 ][ 1 ]; | ||
diffs.splice( pointer - 1, 1 ); | ||
changes = true; | ||
} else if ( diffPointer.substring( 0, diffs[ pointer + 1 ][ 1 ].length ) === | ||
diffs[ pointer + 1 ][ 1 ] ) { | ||
// Shift the edit over the next equality. | ||
diffs[ pointer - 1 ][ 1 ] += diffs[ pointer + 1 ][ 1 ]; | ||
diffs[ pointer ][ 1 ] = | ||
diffs[ pointer ][ 1 ].substring( diffs[ pointer + 1 ][ 1 ].length ) + | ||
diffs[ pointer + 1 ][ 1 ]; | ||
diffs.splice( pointer + 1, 1 ); | ||
changes = true; | ||
} | ||
} | ||
pointer++; | ||
} | ||
// If shifts were made, the diff needs reordering and another shift sweep. | ||
if ( changes ) { | ||
this.diffCleanupMerge( diffs ); | ||
} | ||
}; | ||
return function( o, n ) { | ||
var diff, output, text; | ||
diff = new DiffMatchPatch(); | ||
output = diff.DiffMain(o, n); | ||
//console.log(output); | ||
diff.diffCleanupEfficiency(output); | ||
text = diff.diffPrettyHtml(output); | ||
diff = new DiffMatchPatch(); | ||
output = diff.DiffMain( o, n ); | ||
diff.diffCleanupEfficiency( output ); | ||
text = diff.diffPrettyHtml( output ); | ||
return text; | ||
}; | ||
}()); | ||
// jscs:enable | ||
return text; | ||
}; | ||
}() ); |
@@ -5,3 +5,3 @@ // Based on jsDump by Ariel Flesler | ||
function quote( str ) { | ||
return "\"" + str.toString().replace( /"/g, "\\\"" ) + "\""; | ||
return "\"" + str.toString().replace( /\\/g, "\\\\" ).replace( /"/g, "\\\"" ) + "\""; | ||
} | ||
@@ -8,0 +8,0 @@ function literal( o ) { |
@@ -130,2 +130,42 @@ // Test for equality any JavaScript type. | ||
"set": function( b, a ) { | ||
var aArray, bArray; | ||
// b could be any object here | ||
if ( QUnit.objectType( b ) !== "set" ) { | ||
return false; | ||
} | ||
aArray = []; | ||
a.forEach( function( v ) { | ||
aArray.push( v ); | ||
}); | ||
bArray = []; | ||
b.forEach( function( v ) { | ||
bArray.push( v ); | ||
}); | ||
return innerEquiv( bArray, aArray ); | ||
}, | ||
"map": function( b, a ) { | ||
var aArray, bArray; | ||
// b could be any object here | ||
if ( QUnit.objectType( b ) !== "map" ) { | ||
return false; | ||
} | ||
aArray = []; | ||
a.forEach( function( v, k ) { | ||
aArray.push( [ k, v ] ); | ||
}); | ||
bArray = []; | ||
b.forEach( function( v, k ) { | ||
bArray.push( [ k, v ] ); | ||
}); | ||
return innerEquiv( bArray, aArray ); | ||
}, | ||
"object": function( b, a ) { | ||
@@ -132,0 +172,0 @@ |
// For browser, export only select globals | ||
if ( typeof window !== "undefined" ) { | ||
if ( defined.document ) { | ||
@@ -4,0 +4,0 @@ // Deprecated |
@@ -12,2 +12,2 @@ /*! | ||
(function( window ) { | ||
(function( global ) { |
@@ -73,5 +73,7 @@ function Test( settings ) { | ||
if ( this.module.testEnvironment ) { | ||
delete this.module.testEnvironment.beforeEach; | ||
delete this.module.testEnvironment.afterEach; | ||
} | ||
this.testEnvironment = extend( {}, this.module.testEnvironment ); | ||
delete this.testEnvironment.beforeEach; | ||
delete this.testEnvironment.afterEach; | ||
@@ -206,2 +208,5 @@ this.started = now(); | ||
// Source of Test | ||
source: this.stack, | ||
// DEPRECATED: this property will be removed in 2.0.0, use runtime instead | ||
@@ -264,3 +269,3 @@ duration: this.runtime | ||
push: function( result, actual, expected, message ) { | ||
push: function( result, actual, expected, message, negative ) { | ||
var source, | ||
@@ -275,2 +280,3 @@ details = { | ||
testId: this.testId, | ||
negative: negative || false, | ||
runtime: now() - this.started | ||
@@ -296,3 +302,3 @@ }; | ||
pushFailure: function( message, source, actual ) { | ||
if ( !this instanceof Test ) { | ||
if ( !( this instanceof Test ) ) { | ||
throw new Error( "pushFailure() assertion outside test context, was " + | ||
@@ -333,3 +339,3 @@ sourceFromStacktrace( 2 ) ); | ||
promise, | ||
QUnit.start, | ||
function() { QUnit.start(); }, | ||
function( error ) { | ||
@@ -401,3 +407,3 @@ message = "Promise rejected " + | ||
// This is necessary to not break on node tests | ||
if ( typeof window === "undefined" ) { | ||
if ( !defined.document ) { | ||
return; | ||
@@ -449,1 +455,89 @@ } | ||
} | ||
function synchronize( callback, last ) { | ||
if ( QUnit.objectType( callback ) === "array" ) { | ||
while ( callback.length ) { | ||
synchronize( callback.shift() ); | ||
} | ||
return; | ||
} | ||
config.queue.push( callback ); | ||
if ( config.autorun && !config.blocking ) { | ||
process( last ); | ||
} | ||
} | ||
function saveGlobal() { | ||
config.pollution = []; | ||
if ( config.noglobals ) { | ||
for ( var key in global ) { | ||
if ( hasOwn.call( global, key ) ) { | ||
// in Opera sometimes DOM element ids show up here, ignore them | ||
if ( /^qunit-test-output/.test( key ) ) { | ||
continue; | ||
} | ||
config.pollution.push( key ); | ||
} | ||
} | ||
} | ||
} | ||
function checkPollution() { | ||
var newGlobals, | ||
deletedGlobals, | ||
old = config.pollution; | ||
saveGlobal(); | ||
newGlobals = diff( config.pollution, old ); | ||
if ( newGlobals.length > 0 ) { | ||
QUnit.pushFailure( "Introduced global variable(s): " + newGlobals.join( ", " ) ); | ||
} | ||
deletedGlobals = diff( old, config.pollution ); | ||
if ( deletedGlobals.length > 0 ) { | ||
QUnit.pushFailure( "Deleted global variable(s): " + deletedGlobals.join( ", " ) ); | ||
} | ||
} | ||
// Will be exposed as QUnit.asyncTest | ||
function asyncTest( testName, expected, callback ) { | ||
if ( arguments.length === 2 ) { | ||
callback = expected; | ||
expected = null; | ||
} | ||
QUnit.test( testName, expected, callback, true ); | ||
} | ||
// Will be exposed as QUnit.test | ||
function test( testName, expected, callback, async ) { | ||
var newTest; | ||
if ( arguments.length === 2 ) { | ||
callback = expected; | ||
expected = null; | ||
} | ||
newTest = new Test({ | ||
testName: testName, | ||
expected: expected, | ||
async: async, | ||
callback: callback | ||
}); | ||
newTest.queue(); | ||
} | ||
// Will be exposed as QUnit.skip | ||
function skip( testName ) { | ||
var test = new Test({ | ||
testName: testName, | ||
skip: true | ||
}); | ||
test.queue(); | ||
} |
@@ -19,4 +19,4 @@ { | ||
"_source": "git://github.com/components/zepto.git", | ||
"_target": "~1.1.6", | ||
"_target": "^1.1.6", | ||
"_originalSource": "zepto" | ||
} |
{ | ||
"name": "remodal", | ||
"version": "1.0.3", | ||
"version": "1.0.4", | ||
"description": "Responsive, lightweight, fast, synchronized with CSS animations, fully customizable modal window plugin with declarative configuration and hash tracking.", | ||
@@ -41,3 +41,3 @@ "keywords": [ | ||
"devDependencies": { | ||
"bower": "^1.4.1", | ||
"bower": "^1.5.3", | ||
"grunt": "^0.4.5", | ||
@@ -48,15 +48,16 @@ "grunt-autoprefixer": "^3.0.3", | ||
"grunt-contrib-concat": "^0.5.1", | ||
"grunt-contrib-connect": "^0.10.1", | ||
"grunt-contrib-jshint": "^0.11.2", | ||
"grunt-contrib-connect": "^0.11.2", | ||
"grunt-contrib-jshint": "^0.11.3", | ||
"grunt-contrib-qunit": "^0.7.0", | ||
"grunt-contrib-uglify": "^0.9.1", | ||
"grunt-contrib-uglify": "^0.9.2", | ||
"grunt-contrib-watch": "^0.6.1", | ||
"grunt-csscomb": "3.0.0", | ||
"grunt-githooks": "^0.3.1", | ||
"grunt-jscs": "^1.8.0" | ||
"grunt-jscs": "^2.1.0" | ||
}, | ||
"scripts": { | ||
"start": "npm install && ./node_modules/.bin/bower install && ./node_modules/.bin/grunt githooks", | ||
"test": "./node_modules/.bin/grunt test" | ||
"test": "./node_modules/.bin/grunt test", | ||
"dist": "./node_modules/.bin/grunt" | ||
} | ||
} |
@@ -117,2 +117,10 @@ !(function(root, factory) { | ||
/** | ||
* Is iOS? | ||
* @private | ||
* @const | ||
* @type {Boolean} | ||
*/ | ||
var IS_IOS = /iPad|iPhone|iPod/.test(navigator.platform); | ||
/** | ||
* Current modal | ||
@@ -232,2 +240,6 @@ * @private | ||
function lockScreen() { | ||
if (IS_IOS) { | ||
return; | ||
} | ||
var $html = $('html'); | ||
@@ -254,2 +266,6 @@ var lockedClass = namespacify('is-locked'); | ||
function unlockScreen() { | ||
if (IS_IOS) { | ||
return; | ||
} | ||
var $html = $('html'); | ||
@@ -256,0 +272,0 @@ var lockedClass = namespacify('is-locked'); |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
241
46234
4863478