國家文化記憶庫 --> --> --> --> --> --> --> --> (function(w,d,s,l,i){w[l]=w[l]||[];w[l].push({'gtm.start': new Date().getTime(),event:'gtm.js'});var f=d.getElementsByTagName(s)[0], j=d.createElement(s),dl=l!='dataLayer'?'&l='+l:'';j.async=true;j.src= 'https://www.googletagmanager.com/gtm.js?id='+i+dl;f.parentNode.insertBefore(j,f); })(window,document,'script','dataLayer','GTM-TFRLGPH'); var prebootInitFn = (function() { function start(prebootData, win) { const theWindow = (win || window); const _document = (theWindow.document || {}); // Remove the current script from the DOM so that child indexes match // between the client & the server. The script is already running so it // doesn't affect it. const currentScript = _document.currentScript || // Support: IE 9-11 only // IE doesn't support document.currentScript. Since the script is invoked // synchronously, though, the current running script is just the last one // currently in the document. [].slice.call(_document.getElementsByTagName('script'), -1)[0]; if (!currentScript) { console.error('Preboot initialization failed, no currentScript has been detected.'); return; } let serverNode = currentScript.parentNode; if (!serverNode) { console.error('Preboot initialization failed, the script is detached'); return; } serverNode.removeChild(currentScript); const opts = prebootData.opts || {}; let eventSelectors = opts.eventSelectors || []; // get the root info const appRoot = prebootData.opts ? getAppRoot(_document, prebootData.opts, serverNode) : null; // we track all events for each app in the prebootData object which is on // the global scope; each `start` invocation adds data for one app only. const appData = { root: appRoot, events: [] }; if (prebootData.apps) { prebootData.apps.push(appData); } eventSelectors = eventSelectors.map(eventSelector => { if (!eventSelector.hasOwnProperty('replay')) { eventSelector.replay = true; } return eventSelector; }); // loop through all the eventSelectors and create event handlers eventSelectors.forEach(eventSelector => handleEvents(_document, prebootData, appData, eventSelector)); } function createOverlay(_document) { let overlay = _document.createElement('div'); overlay.setAttribute('id', 'prebootOverlay'); overlay.setAttribute('style', 'display:none;position:absolute;left:0;' + 'top:0;width:100%;height:100%;z-index:999999;background:black;opacity:.3'); _document.documentElement.appendChild(overlay); return overlay; } function getAppRoot(_document, opts, serverNode) { const root = { serverNode }; // if we are doing buffering, we need to create the buffer for the client // else the client root is the same as the server root.clientNode = opts.buffer ? createBuffer(root) : root.serverNode; // create an overlay if not disabled ,that can be used later if a freeze event occurs if (!opts.disableOverlay) { root.overlay = createOverlay(_document); } return root; } function handleEvents(_document, prebootData, appData, eventSelector) { const serverRoot = appData.root.serverNode; // don't do anything if no server root if (!serverRoot) { return; } // Attach delegated event listeners for each event selector. // We need to use delegated events as only the top level server node // exists at this point. eventSelector.events.forEach((eventName) => { // get the appropriate handler and add it as an event listener const handler = createListenHandler(_document, prebootData, eventSelector, appData); // attach the handler in the capture phase so that it fires even if // one of the handlers below calls stopPropagation() serverRoot.addEventListener(eventName, handler, true); // need to keep track of listeners so we can do node.removeEventListener() // when preboot done if (prebootData.listeners) { prebootData.listeners.push({ node: serverRoot, eventName, handler }); } }); } function createListenHandler(_document, prebootData, eventSelector, appData) { const CARET_EVENTS = ['keyup', 'keydown', 'focusin', 'mouseup', 'mousedown']; const CARET_NODES = ['INPUT', 'TEXTAREA']; // Support: IE 9-11 only // IE uses a prefixed `matches` version const matches = _document.documentElement.matches || _document.documentElement.msMatchesSelector; const opts = prebootData.opts; return function (event) { const node = event.target; // a delegated handlers on document is used so we need to check if // event target matches a desired selector if (!matches.call(node, eventSelector.selector)) { return; } const root = appData.root; const eventName = event.type; // if no node or no event name, just return if (!node || !eventName) { return; } // if key codes set for eventSelector, then don't do anything if event // doesn't include key const keyCodes = eventSelector.keyCodes; if (keyCodes && keyCodes.length) { const matchingKeyCodes = keyCodes.filter(keyCode => event.which === keyCode); // if there are not matches (i.e. key entered NOT one of the key codes) // then don't do anything if (!matchingKeyCodes.length) { return; } } // if for a given set of events we are preventing default,
FACT BOX ・ 要点整理
- 出典:PR Times
- 分類:ニュース