container/doc/Creating containers - Part .../wombat.js

20 lines
113 KiB
JavaScript
Raw Normal View History

2020-07-19 21:55:41 +00:00
/*
Copyright(c) 2013-2018 Rhizome and Contributors. Released under the GNU General Public License.
This file is part of pywb, https://github.com/webrecorder/pywb
pywb is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
pywb is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with pywb. If not, see <http://www.gnu.org/licenses/>.
*/
(function(){function FuncMap(){this._map=[]}function ensureNumber(maybeNumber){try{switch(typeof maybeNumber){case"number":case"bigint":return maybeNumber;}var converted=Number(maybeNumber);return isNaN(converted)?null:converted}catch(e){}return null}function addToStringTagToClass(clazz,tag){typeof self.Symbol!=="undefined"&&typeof self.Symbol.toStringTag!=="undefined"&&Object.defineProperty(clazz.prototype,self.Symbol.toStringTag,{value:tag,enumerable:false})}function autobind(clazz){for(var prop,propValue,proto=clazz.__proto__||clazz.constructor.prototype||clazz.prototype,clazzProps=Object.getOwnPropertyNames(proto),len=clazzProps.length,i=0;i<len;i++)prop=clazzProps[i],propValue=clazz[prop],prop!=="constructor"&&typeof propValue==="function"&&(clazz[prop]=propValue.bind(clazz))}function Storage(wombat,proxying){if(ThrowExceptions.yes)throw new TypeError("Illegal constructor");Object.defineProperties(this,{data:{enumerable:false,value:{}},wombat:{enumerable:false,value:wombat},proxying:{enumerable:false,value:proxying},_deleteItem:{enumerable:false,value:function(item){delete this.data[item]}}})}function WombatLocation(orig_loc,wombat){for(var prop in Object.defineProperties(this,{_orig_loc:{configurable:true,enumerable:false,value:orig_loc},wombat:{configurable:true,enumerable:false,value:wombat},orig_getter:{enumerable:false,value:function(prop){return this._orig_loc[prop]}},orig_setter:{enumerable:false,value:function(prop,value){this._orig_loc[prop]=value}}}),wombat.initLocOverride(this,this.orig_setter,this.orig_getter),wombat.setLoc(this,orig_loc.href),orig_loc)this.hasOwnProperty(prop)||typeof orig_loc[prop]==="function"||(this[prop]=orig_loc[prop])}function AutoFetcher(wombat,config){return this instanceof AutoFetcher?void(this.elemSelector="img[srcset], img[data-srcset], img[data-src], video[srcset], video[data-srcset], video[data-src], audio[srcset], audio[data-srcset], audio[data-src], picture > source[srcset], picture > source[data-srcset], picture > source[data-src], video > source[srcset], video > source[data-srcset], video > source[data-src], audio > source[srcset], audio > source[data-srcset], audio > source[data-src]",this.wombat=wombat,this.$wbwindow=wombat.$wbwindow,this.worker=null,autobind(this),this._initWorker(config)):new AutoFetcher(wombat,config)}function wrapSameOriginEventListener(origListener,win){return function wrappedSameOriginEventListener(event){return window==win?origListener(event):void 0}}function wrapEventListener(origListener,obj,wombat){var origListenerFunc;return origListenerFunc=typeof origListener==="function"?origListener:typeof origListener==="object"?origListener.handleEvent.bind(origListener):function(){},function wrappedEventListener(event){var ne;if(event.data&&event.data.from&&event.data.message){if(event.data.to_origin!=="*"&&obj.WB_wombat_location&&!wombat.startsWith(event.data.to_origin,obj.WB_wombat_location.origin))return void console.warn("Skipping message event to "+event.data.to_origin+" doesn't start with origin "+obj.WB_wombat_location.origin);var source=event.source;event.data.from_top?source=obj.__WB_top_frame:event.data.src_id&&obj.__WB_win_id&&obj.__WB_win_id[event.data.src_id]&&(source=obj.__WB_win_id[event.data.src_id]),ne=new MessageEvent("message",{bubbles:event.bubbles,cancelable:event.cancelable,data:event.data.message,origin:event.data.from,lastEventId:event.lastEventId,source:wombat.proxyToObj(source),ports:event.ports}),ne._target=event.target,ne._srcElement=event.srcElement,ne._currentTarget=event.currentTarget,ne._eventPhase=event.eventPhase,ne._path=event.path}else ne=event;return origListenerFunc(ne)}}function Wombat($wbwindow,wbinfo){if(!(this instanceof Wombat))return new Wombat($wbwindow,wbinfo);this.actual=false,this.debug_rw=false,this.$wbwindow=$wbwindow,this.HTTP_PREFIX="http://",this.HTTPS_PREFIX="https://",this.REL_PREFIX="//",this.VALID_PREFIXES=[this.HTTP_PREFIX,this.HTTPS_PREFIX,this.REL_PREFIX],this.IGNORE_PREFIXES=["#","about:","data:","blob:","mailto:","javascript:","{","*"],"ignore_prefixes"in wbinfo&&(this.IGNORE_PREFIXES=thi