0
Fork 0
mirror of https://github.com/fastmail/Squire.git synced 2025-01-09 00:10:05 -05:00
Squire/build/ie8.js
2012-07-24 15:54:05 +10:00

1 line
No EOL
7.4 KiB
JavaScript

/* Copyright © 2011-2012 by Neil Jenkins. Licensed under the MIT license. */(function(e){Array.prototype.indexOf=function(e,t){var n=this.length;for(var r=t<0?Math.max(0,n+t):t||0;r<n;r+=1)if(this[r]===e)return r;return-1},Array.prototype.forEach=function(e,t){var n=this.length>>>0;if(typeof e!="function")throw new TypeError;for(var r=0;r<n;r+=1)e.call(t,this[r],r,this)},Array.prototype.filter=function(e,t){var n=[];for(var r=0,i=this.length;r<i;r+=1){var s=this[r];e.call(t,s,r,this)&&n.push(s)}return n},Object.keyOf=function(e,t){for(var n in e)if(e[n]===t)return n},Date.now=function(){return+(new Date)},String.prototype.trim=function(){var e=this.replace(/^\s\s*/,""),t=/\s/,n=e.length;while(t.test(e.charAt(n-=1)));return e.slice(0,n+1)}})(),function(){var e=document;window.ie=8,e.defaultView=window;var t={focus:"focusin",blur:"focusout"},n=function(){return!0},r=function(){return!1},i="altKey ctrlKey metaKey shiftKey clientX clientY charCode keyCode".split(" "),s=function(e){var n=e.type,r=document,s=e.srcElement||r,o=(s.ownerDocument||r).documentElement,u=i.length,a;while(u--)a=i[u],this[a]=e[a];n==="propertychange"&&(n=s.nodeName==="INPUT"&&s.type!=="text"&&s.type!=="password"?"change":"input"),this.type=Object.keyOf(t,n)||n,this.target=s,this.pageX=e.clientX+o.scrollLeft,this.pageY=e.clientY+o.scrollTop,e.button&&(this.button=e.button&4?1:e.button&2?2:0,this.which=this.button+1),this.relatedTarget=e.fromElement===s?e.toElement:e.fromElement,this._event=e};s.prototype={constructor:s,isEvent:!0,preventDefault:function(){this.isDefaultPrevented=n,this._event.returnValue=!1},stopPropagation:function(){this.isPropagationStopped=n,this._event.cancelBubble=!0},isDefaultPrevented:r,isPropagationStopped:r},[e,Element.prototype].forEach(function(e){e.addEventListener=function(e,n,r){var i=n._ie_handleEvent||(n._ie_handleEvent=function(){var e=new s(window.event);typeof n=="object"?n.handleEvent(e):n.call(this,e)}),o=/paste|cut/.test(e)?this.body||this:this;n._ie_registeredCount=(n._ie_registeredCount||0)+1,o.attachEvent("on"+(t[e]||e),i)},e.addEventListener.isFake=!0,e.removeEventListener=function(e,n,r){var i=n._ie_handleEvent,s=/paste|cut/.test(e)?this.body||this:this;(n._ie_registeredCount-=1)||delete n._ie_handleEvent,i&&s.detachEvent("on"+(t[e]||e),i)},e.removeEventListener.isFake=!0}),e.defaultView.addEventListener=function(t,n,r){return e.addEventListener(t,n,r)},Object.defineProperty(Element.prototype,"textContent",{get:function(){return this.innerText},set:function(e){this.innerText=e}}),Element.prototype.compareDocumentPosition=function(e){e.nodeType!==1&&(e=e.parentNode);var t=this,n=t!==e,r=t.sourceIndex,i=e.sourceIndex;return(n&&t.contains(e)?16:0)+(n&&e.contains(t)?8:0)+(r<i?4:0)+(i<r?2:0)},HTMLDocument.prototype.normalize=function(){var e=this.childNodes,t=e.length,n;while(t--)n=e[t],n.nodeType===1&&n.normalize()}}();var Range;(function(){var e=Array.prototype.indexOf,t=0,n=1,r=3,i=function(e,t){while(t=t.parentNode)if(e===t)return!0;return!1},s=function(e,t){var n,r,s,o,u;if(e===t||i(e,t))n=e;else if(i(t,e))n=t;else{r=[],s=[];while(e=e.parentNode)r.push(e);while(t=t.parentNode)s.push(t);o=r.length,u=s.length;while(o--&&u--)if(r[o]!==s[u]){n=r[o+1];break}n||(n=o===-1?r[0]:s[0])}return n};Range=function(e,t,n,r){e=e||document,t=t||0,this.startContainer=e,this.startOffset=t,this.endContainer=n||e,this.endOffset=r!==undefined?r:t,this._updateCollapsedAndAncestor()},Range.prototype={constructor:Range,_updateCollapsedAndAncestor:function(){this.collapsed=this.startContainer===this.endContainer&&this.startOffset===this.endOffset,this.commonAncestorContainer=s(this.startContainer,this.endContainer)},setStart:function(e,t){this.startContainer=e,this.startOffset=t,this._updateCollapsedAndAncestor()},setEnd:function(e,t){this.endContainer=e,this.endOffset=t,this._updateCollapsedAndAncestor()},setStartAfter:function(t){var n=t.parentNode;this.setStart(n,e.call(n.childNodes,t)+1)},setEndBefore:function(t){var n=t.parentNode;this.setEnd(n,e.call(n.childNodes,t))},selectNode:function(t){var n=t.parentNode,r=e.call(n.childNodes,t);this.setStart(n,r),this.setEnd(n,r+1)},selectNodeContents:function(e){this.setStart(e,0),this.setEnd(e,e.childNodes.length)},cloneRange:function(){return new Range(this.startContainer,this.startOffset,this.endContainer,this.endOffset)},collapse:function(e){e?this.setEnd(this.startContainer,this.startOffset):this.setStart(this.endContainer,this.endOffset)},compareBoundaryPoints:function(i,s){var o,u,a,f,l,c;i===t||i===r?(o=this.startContainer,u=this.startOffset):(o=this.endContainer,u=this.endOffset),i===t||i===n?(a=s.startContainer,f=s.startOffset):(a=s.endContainer,f=s.endOffset);if(o===a)return u<f?-1:u>f?1:0;l=o;while(c=l.parentNode){if(c===a)return e.call(c.childNodes,l)<f?-1:1;l=c}l=a;while(c=l.parentNode){if(c===o)return e.call(c.childNodes,l)<u?1:-1;l=c}return o.nodeType!==1&&(o=o.parentNode),a.nodeType!==1&&(a=a.parentNode),o.sourceIndex<a.sourceIndex?-1:o.sourceIndex>a.sourceIndex?1:0}},document.createRange=function(){return new Range};var o=function(e,t){return e===t||i(e,t)},u=function(e){var t=e.nodeType;return t===3||t===4||t===8},a=function(e,t){this.node=e,this.offset=t},f=function(e){var t=e.parentElement(),n,r,i,o;return n=e.duplicate(),n.collapse(!0),r=n.parentElement(),n=e.duplicate(),n.collapse(!1),i=n.parentElement(),o=r===i?r:s(r,i),o===t?o:s(t,o)},l=function(t,n,r,i){var s=t.duplicate();s.collapse(r);var f=s.parentElement();o(n,f)||(f=n);if(!f.canHaveHTML)return new a(f.parentNode,e.call(f.parentNode.childNodes,f));var l=document.createElement("span"),c=r?"StartToStart":"StartToEnd",h,p,d,v,m;do f.insertBefore(l,l.previousSibling),s.moveToElementText(l),h=s.compareEndPoints(c,t);while(h>0&&l.previousSibling);m=l.nextSibling;if(h===-1&&m&&u(m)){s.setEndPoint(r?"EndToStart":"EndToEnd",t);var g;if(/[\r\n]/.test(m.data)||/[\r\n]/.test(s.text)){var y=s.duplicate(),b=y.text.replace(/\r\n/g,"\r").length;g=y.moveStart("character",b);while((h=y.compareEndPoints("StartToEnd",y))===-1)g+=1,y.moveStart("character",1)}else g=s.text.length;v=new a(m,g)}else p=(i||!r)&&l.previousSibling,d=(i||r)&&l.nextSibling,d&&u(d)?v=new a(d,0):p&&u(p)?v=new a(p,p.data.length):v=new a(f,e.call(f.childNodes,l));return l.parentNode.removeChild(l),v},c=function(e,t){var n,r,i=e.offset,s=document,o,a,f=s.body.createTextRange(),l=u(e.node);return l?(n=e.node,r=n.parentNode):(a=e.node.childNodes,n=i<a.length?a[i]:null,r=e.node),o=s.createElement("span"),o.innerHTML="&#xfeff;",n?r.insertBefore(o,n):r.appendChild(o),f.moveToElementText(o),f.collapse(!t),r.removeChild(o),l&&f[t?"moveStart":"moveEnd"]("character",i),f},h=function(e){var t=f(e),n,r;return e.compareEndPoints("StartToEnd",e)===0?n=r=l(e,t,!0,!0):(n=l(e,t,!0,!1),r=l(e,t,!1,!1)),new Range(n.node,n.offset,r.node,r.offset)},p=function(e){var t,n,r;return e.collapsed?t=c(new a(e.startContainer,e.startOffset),!0):(n=c(new a(e.startContainer,e.startOffset),!0),r=c(new a(e.endContainer,e.endOffset),!1),t=document.body.createTextRange(),t.setEndPoint("StartToStart",n),t.setEndPoint("EndToEnd",r)),t},d={rangeCount:1,getRangeAt:function(e){if(e!==0)return undefined;var t=document.selection.createRange();if(t.add){var n=document.createRange();n.moveToElementText(t.item(0)),n.collapse(!1),n.select(),t=n}return h(t)},removeAllRanges:function(){},addRange:function(e){p(e).select()}};document.attachEvent("onbeforeactivate",function(){d.rangeCount=1}),document.attachEvent("ondeactivate",function(){d.rangeCount=0}),window.getSelection=function(){return d}})();