vendor: 4,923 bytes, lines 1-137
1(function(f){if(typeof exports==="object"&&typeof module!=="undefined"){module.exports=f()}else if(typeof define==="function"&&define.amd){define([],f)}else{var g;if(typeof window!=="undefined"){g=window}else if(typeof global!=="undefined"){g=global}else if(typeof self!=="undefined"){g=self}else{g=this}g.Pjax = f()}})(function(){var define,module,exports;return (function(){function r(e,n,t){function o(i,f){if(!n[i]){if(!e[i]){var c="function"==typeof require&&require;if(!f&&c)return c(i,!0);if(u)return u(i,!0);var a=new Error("Cannot find module '"+i+"'");throw a.code="MODULE_NOT_FOUND",a}var p=n[i]={exports:{}};e[i][0].call(p.exports,function(r){var n=e[i][1][r];return o(n||r)},p,p.exports,r,e,n,t)}return n[i].exports}for(var u="function"==typeof require&&require,i=0;i<t.length;i++)o(t[i]);return o}return r})()({1:[function(require,module,exports){ 2 var executeScripts = require("./lib/execute-scripts"); 3 var forEachEls = require("./lib/foreach-els"); 4 var parseOptions = require("./lib/parse-options"); 5 var switches = require("./lib/switches"); 6 var newUid = require("./lib/uniqueid"); 7 8 var on = require("./lib/events/on"); 9 var trigger = require("./lib/events/trigger"); 10 11 var clone = require("./lib/util/clone"); 12 var contains = require("./lib/util/contains"); 13 var extend = require("./lib/util/extend"); 14 var noop = require("./lib/util/noop"); 15 16 var Pjax = function(options) { 17 this.state = { 18 numPendingSwitches: 0, 19 href: null, 20 options: null 21 }; 22 23 this.options = parseOptions(options); 24 this.log("Pjax options", this.options); 25 26 if (this.options.scrollRestoration && "scrollRestoration" in history) { 27 history.scrollRestoration = "manual"; 28 } 29 30 this.maxUid = this.lastUid = newUid(); 31 32 this.parseDOM(document); 33 34 on( 35 window, 36 "popstate", 37 function(st) { 38 if (st.state) { 39 var opt = clone(this.options); 40 opt.url = st.state.url; 41 opt.title = st.state.title; 42 // Since state already exists, prevent it from being pushed again 43 opt.history = false; 44 opt.scrollPos = st.state.scrollPos; 45 if (st.state.uid < this.lastUid) { 46 opt.backward = true; 47 } else { 48 opt.forward = true; 49 } 50 this.lastUid = st.state.uid; 51 52 // @todo implement history cache here, based on uid 53 this.loadUrl(st.state.url, opt); 54 } 55 }.bind(this) 56 ); 57 }; 58 59 Pjax.switches = switches; 60 61 Pjax.prototype = { 62 log: require("./lib/proto/log"), 63 64 getElements: function(el) { 65 return el.querySelectorAll(this.options.elements); 66 }, 67 68 parseDOM: function(el) { 69 var parseElement = require("./lib/proto/parse-element"); 70 forEachEls(this.getElements(el), parseElement, this); 71 }, 72 73 refresh: function(el) { 74 this.parseDOM(el || document); 75 }, 76 77 reload: function() { 78 window.location.reload(); 79 }, 80 81 attachLink: require("./lib/proto/attach-link"), 82 83 attachForm: require("./lib/proto/attach-form"), 84 85 forEachSelectors: function(cb, context, DOMcontext) { 86 return require("./lib/foreach-selectors").bind(this)( 87 this.options.selectors, 88 cb, 89 context, 90 DOMcontext 91 ); 92 }, 93 94 switchSelectors: function(selectors, fromEl, toEl, options) { 95 return require("./lib/switches-selectors").bind(this)( 96 this.options.switches, 97 this.options.switchesOptions, 98 selectors, 99 fromEl, 100 toEl, 101 options 102 ); 103 }, 104 105 latestChance: function(href) { 106 window.location = href; 107 }, 108 109 onSwitch: function() { 110 trigger(window, "resize scroll"); 111 112 this.state.numPendingSwitches--; 113 114 // debounce calls, so we only run this once after all switches are finished. 115 if (this.state.numPendingSwitches === 0) { 116 this.afterAllSwitches(); 117 } 118 }, 119 120 loadContent: function(html, options) { 121 if (typeof html !== "string") { 122 trigger(document, "pjax:complete pjax:error", options); 123 124 return; 125 } 126 127 var tmpEl = document.implementation.createHTMLDocument("pjax"); 128 129 // parse HTML attributes to copy them 130 // since we are forced to use documentElement.innerHTML (outerHTML can't be used for <html>) 131 var htmlRegex = /<html[^>]+>/gi; 132 var htmlAttribsRegex = /\s?[a-z:]+(?:=['"][^'">]+['"])*/gi; 133 var matches = html.match(htmlRegex); 134 if (matches && matches.length) { 135 matches = matches[0].match(htmlAttribsRegex); 136 if (matches.length) { 137 matches.shift();
vendor: 4,693 bytes, lines 138-282
138 matches.forEach(function(htmlAttrib) { 139 var attr = htmlAttrib.trim().split("="); 140 if (attr.length === 1) { 141 tmpEl.documentElement.setAttribute(attr[0], true); 142 } else { 143 tmpEl.documentElement.setAttribute(attr[0], attr[1].slice(1, -1)); 144 } 145 }); 146 } 147 } 148 149 tmpEl.documentElement.innerHTML = html; 150 this.log( 151 "load content", 152 tmpEl.documentElement.attributes, 153 tmpEl.documentElement.innerHTML.length 154 ); 155 156 // Clear out any focused controls before inserting new page contents. 157 if ( 158 document.activeElement && 159 contains(document, this.options.selectors, document.activeElement) 160 ) { 161 try { 162 document.activeElement.blur(); 163 } catch (e) {} // eslint-disable-line no-empty 164 } 165 166 this.switchSelectors(this.options.selectors, tmpEl, document, options); 167 }, 168 169 abortRequest: require("./lib/abort-request"), 170 171 doRequest: require("./lib/send-request"), 172 173 handleResponse: require("./lib/proto/handle-response"), 174 175 loadUrl: function(href, options) { 176 options = 177 typeof options === "object" 178 ? extend({}, this.options, options) 179 : clone(this.options); 180 181 this.log("load href", href, options); 182 183 // Abort any previous request 184 this.abortRequest(this.request); 185 186 trigger(document, "pjax:send", options); 187 188 // Do the request 189 this.request = this.doRequest( 190 href, 191 options, 192 this.handleResponse.bind(this) 193 ); 194 }, 195 196 afterAllSwitches: function() { 197 // FF bug: Wonât autofocus fields that are inserted via JS. 198 // This behavior is incorrect. So if theres no current focus, autofocus 199 // the last field. 200 // 201 // http://www.w3.org/html/wg/drafts/html/master/forms.html 202 var autofocusEl = Array.prototype.slice 203 .call(document.querySelectorAll("[autofocus]")) 204 .pop(); 205 if (autofocusEl && document.activeElement !== autofocusEl) { 206 autofocusEl.focus(); 207 } 208 209 // execute scripts when DOM have been completely updated 210 this.options.selectors.forEach(function(selector) { 211 forEachEls(document.querySelectorAll(selector), function(el) { 212 executeScripts(el); 213 }); 214 }); 215 216 var state = this.state; 217 218 if (state.options.history) { 219 if (!window.history.state) { 220 this.lastUid = this.maxUid = newUid(); 221 window.history.replaceState( 222 { 223 url: window.location.href, 224 title: document.title, 225 uid: this.maxUid, 226 scrollPos: [0, 0] 227 }, 228 document.title 229 ); 230 } 231 232 // Update browser history 233 this.lastUid = this.maxUid = newUid(); 234 235 window.history.pushState( 236 { 237 url: state.href, 238 title: state.options.title, 239 uid: this.maxUid, 240 scrollPos: [0, 0] 241 }, 242 state.options.title, 243 state.href 244 ); 245 } 246 247 this.forEachSelectors(function(el) { 248 this.parseDOM(el); 249 }, this); 250 251 // Fire Events 252 trigger(document, "pjax:complete pjax:success", state.options); 253 254 if (typeof state.options.analytics === "function") { 255 state.options.analytics(); 256 } 257 258 if (state.options.history) { 259 // First parse url and check for hash to override scroll 260 var a = document.createElement("a"); 261 a.href = this.state.href; 262 if (a.hash) { 263 var name = a.hash.slice(1); 264 name = decodeURIComponent(name); 265 266 var curtop = 0; 267 var target = 268 document.getElementById(name) || document.getElementsByName(name)[0]; 269 if (target) { 270 // http://stackoverflow.com/questions/8111094/cross-browser-javascript-function-to-find-actual-position-of-an-element-in-page 271 if (target.offsetParent) { 272 do { 273 curtop += target.offsetTop; 274 275 target = target.offsetParent; 276 } while (target); 277 } 278 } 279 window.scrollTo(0, curtop); 280 } else if (state.options.scrollTo !== false) { 281 // Scroll page to top on new page load 282 if (state.options.scrollTo.length > 1) {
vendor: 30,843 bytes, lines 283-1261
283 window.scrollTo(state.options.scrollTo[0], state.options.scrollTo[1]); 284 } else { 285 window.scrollTo(0, state.options.scrollTo); 286 } 287 } 288 } else if (state.options.scrollRestoration && state.options.scrollPos) { 289 window.scrollTo(state.options.scrollPos[0], state.options.scrollPos[1]); 290 } 291 292 this.state = { 293 numPendingSwitches: 0, 294 href: null, 295 options: null 296 }; 297 } 298 }; 299 300 Pjax.isSupported = require("./lib/is-supported"); 301 302 // arguably could do `if( require("./lib/is-supported")()) {` but that might be a little to simple 303 if (Pjax.isSupported()) { 304 module.exports = Pjax; 305 } 306 // if there isnât required browser functions, returning stupid api 307 else { 308 var stupidPjax = noop; 309 for (var key in Pjax.prototype) { 310 if ( 311 Pjax.prototype.hasOwnProperty(key) && 312 typeof Pjax.prototype[key] === "function" 313 ) { 314 stupidPjax[key] = noop; 315 } 316 } 317 318 module.exports = stupidPjax; 319 } 320 321 },{"./lib/abort-request":2,"./lib/events/on":4,"./lib/events/trigger":5,"./lib/execute-scripts":6,"./lib/foreach-els":7,"./lib/foreach-selectors":8,"./lib/is-supported":9,"./lib/parse-options":10,"./lib/proto/attach-form":11,"./lib/proto/attach-link":12,"./lib/proto/handle-response":13,"./lib/proto/log":14,"./lib/proto/parse-element":15,"./lib/send-request":16,"./lib/switches":18,"./lib/switches-selectors":17,"./lib/uniqueid":19,"./lib/util/clone":20,"./lib/util/contains":21,"./lib/util/extend":22,"./lib/util/noop":23}],2:[function(require,module,exports){ 322 var noop = require("./util/noop"); 323 324 module.exports = function(request) { 325 if (request && request.readyState < 4) { 326 request.onreadystatechange = noop; 327 request.abort(); 328 } 329 }; 330 331 },{"./util/noop":23}],3:[function(require,module,exports){ 332 module.exports = function(el) { 333 var code = el.text || el.textContent || el.innerHTML || ""; 334 var src = el.src || ""; 335 var parent = 336 el.parentNode || document.querySelector("head") || document.documentElement; 337 var script = document.createElement("script"); 338 339 if (code.match("document.write")) { 340 if (console && console.log) { 341 console.log( 342 "Script contains document.write. Canât be executed correctly. Code skipped ", 343 el 344 ); 345 } 346 return false; 347 } 348 349 script.type = "text/javascript"; 350 script.id = el.id; 351 352 /* istanbul ignore if */ 353 if (src !== "") { 354 script.src = src; 355 script.async = false; // force synchronous loading of peripheral JS 356 } 357 358 if (code !== "") { 359 try { 360 script.appendChild(document.createTextNode(code)); 361 } catch (e) { 362 /* istanbul ignore next */ 363 // old IEs have funky script nodes 364 script.text = code; 365 } 366 } 367 368 // execute 369 parent.appendChild(script); 370 // avoid pollution only in head or body tags 371 if ( 372 (parent instanceof HTMLHeadElement || parent instanceof HTMLBodyElement) && 373 parent.contains(script) 374 ) { 375 parent.removeChild(script); 376 } 377 378 return true; 379 }; 380 381 },{}],4:[function(require,module,exports){ 382 var forEachEls = require("../foreach-els"); 383 384 module.exports = function(els, events, listener, useCapture) { 385 events = typeof events === "string" ? events.split(" ") : events; 386 387 events.forEach(function(e) { 388 forEachEls(els, function(el) { 389 el.addEventListener(e, listener, useCapture); 390 }); 391 }); 392 }; 393 394 },{"../foreach-els":7}],5:[function(require,module,exports){ 395 var forEachEls = require("../foreach-els"); 396 397 module.exports = function(els, events, opts) { 398 events = typeof events === "string" ? events.split(" ") : events; 399 400 events.forEach(function(e) { 401 var event; 402 event = document.createEvent("HTMLEvents"); 403 event.initEvent(e, true, true); 404 event.eventName = e; 405 if (opts) { 406 Object.keys(opts).forEach(function(key) { 407 event[key] = opts[key]; 408 }); 409 } 410 411 forEachEls(els, function(el) { 412 var domFix = false; 413 if (!el.parentNode && el !== document && el !== window) { 414 // THANK YOU IE (9/10/11) 415 // dispatchEvent doesn't work if the element is not in the DOM 416 domFix = true; 417 document.body.appendChild(el); 418 } 419 el.dispatchEvent(event); 420 if (domFix) { 421 el.parentNode.removeChild(el); 422 } 423 }); 424 }); 425 }; 426 427 },{"../foreach-els":7}],6:[function(require,module,exports){ 428 var forEachEls = require("./foreach-els"); 429 var evalScript = require("./eval-script"); 430 // Finds and executes scripts (used for newly added elements) 431 // Needed since innerHTML does not run scripts 432 module.exports = function(el) { 433 if (el.tagName.toLowerCase() === "script") { 434 evalScript(el); 435 } 436 437 forEachEls(el.querySelectorAll("script"), function(script) { 438 if (!script.type || script.type.toLowerCase() === "text/javascript") { 439 if (script.parentNode) { 440 script.parentNode.removeChild(script); 441 } 442 evalScript(script); 443 } 444 }); 445 }; 446 447 },{"./eval-script":3,"./foreach-els":7}],7:[function(require,module,exports){ 448 /* global HTMLCollection: true */ 449 450 module.exports = function(els, fn, context) { 451 if ( 452 els instanceof HTMLCollection || 453 els instanceof NodeList || 454 els instanceof Array 455 ) { 456 return Array.prototype.forEach.call(els, fn, context); 457 } 458 // assume simple DOM element 459 return fn.call(context, els); 460 }; 461 462 },{}],8:[function(require,module,exports){ 463 var forEachEls = require("./foreach-els"); 464 465 module.exports = function(selectors, cb, context, DOMcontext) { 466 DOMcontext = DOMcontext || document; 467 selectors.forEach(function(selector) { 468 forEachEls(DOMcontext.querySelectorAll(selector), cb, context); 469 }); 470 }; 471 472 },{"./foreach-els":7}],9:[function(require,module,exports){ 473 module.exports = function() { 474 // Borrowed wholesale from https://github.com/defunkt/jquery-pjax 475 return ( 476 window.history && 477 window.history.pushState && 478 window.history.replaceState && 479 // pushState isnât reliable on iOS until 5. 480 !navigator.userAgent.match( 481 /((iPod|iPhone|iPad).+\bOS\s+[1-4]\D|WebApps\/.+CFNetwork)/ 482 ) 483 ); 484 }; 485 486 },{}],10:[function(require,module,exports){ 487 /* global _gaq: true, ga: true */ 488 489 var defaultSwitches = require("./switches"); 490 491 module.exports = function(options) { 492 options = options || {}; 493 options.elements = options.elements || "a[href], form[action]"; 494 options.selectors = options.selectors || ["title", ".js-Pjax"]; 495 options.switches = options.switches || {}; 496 options.switchesOptions = options.switchesOptions || {}; 497 options.history = 498 typeof options.history === "undefined" ? true : options.history; 499 options.analytics = 500 typeof options.analytics === "function" || options.analytics === false 501 ? options.analytics 502 : defaultAnalytics; 503 options.scrollTo = 504 typeof options.scrollTo === "undefined" ? 0 : options.scrollTo; 505 options.scrollRestoration = 506 typeof options.scrollRestoration !== "undefined" 507 ? options.scrollRestoration 508 : true; 509 options.cacheBust = 510 typeof options.cacheBust === "undefined" ? true : options.cacheBust; 511 options.debug = options.debug || false; 512 options.timeout = options.timeout || 0; 513 options.currentUrlFullReload = 514 typeof options.currentUrlFullReload === "undefined" 515 ? false 516 : options.currentUrlFullReload; 517 518 // We canât replace body.outerHTML or head.outerHTML. 519 // It creates a bug where a new body or head are created in the DOM. 520 // If you set head.outerHTML, a new body tag is appended, so the DOM has 2 body nodes, and vice versa 521 if (!options.switches.head) { 522 options.switches.head = defaultSwitches.switchElementsAlt; 523 } 524 if (!options.switches.body) { 525 options.switches.body = defaultSwitches.switchElementsAlt; 526 } 527 528 return options; 529 }; 530 531 /* istanbul ignore next */ 532 function defaultAnalytics() { 533 if (window._gaq) { 534 _gaq.push(["_trackPageview"]); 535 } 536 if (window.ga) { 537 ga("send", "pageview", { page: location.pathname, title: document.title }); 538 } 539 } 540 541 },{"./switches":18}],11:[function(require,module,exports){ 542 var on = require("../events/on"); 543 var clone = require("../util/clone"); 544 545 var attrState = "data-pjax-state"; 546 547 var formAction = function(el, event) { 548 if (isDefaultPrevented(event)) { 549 return; 550 } 551 552 // Since loadUrl modifies options and we may add our own modifications below, 553 // clone it so the changes don't persist 554 var options = clone(this.options); 555 556 // Initialize requestOptions 557 options.requestOptions = { 558 requestUrl: el.getAttribute("action") || window.location.href, 559 requestMethod: el.getAttribute("method") || "GET" 560 }; 561 562 // create a testable virtual link of the form action 563 var virtLinkElement = document.createElement("a"); 564 virtLinkElement.setAttribute("href", options.requestOptions.requestUrl); 565 566 var attrValue = checkIfShouldAbort(virtLinkElement, options); 567 if (attrValue) { 568 el.setAttribute(attrState, attrValue); 569 return; 570 } 571 572 event.preventDefault(); 573 574 if (el.enctype === "multipart/form-data") { 575 options.requestOptions.formData = new FormData(el); 576 } else { 577 options.requestOptions.requestParams = parseFormElements(el); 578 } 579 580 el.setAttribute(attrState, "submit"); 581 582 options.triggerElement = el; 583 this.loadUrl(virtLinkElement.href, options); 584 }; 585 586 function parseFormElements(el) { 587 var requestParams = []; 588 var formElements = el.elements; 589 590 for (var i = 0; i < formElements.length; i++) { 591 var element = formElements[i]; 592 var tagName = element.tagName.toLowerCase(); 593 // jscs:disable disallowImplicitTypeConversion 594 if ( 595 !!element.name && 596 element.attributes !== undefined && 597 tagName !== "button" 598 ) { 599 // jscs:enable disallowImplicitTypeConversion 600 var type = element.attributes.type; 601 602 if ( 603 !type || 604 (type.value !== "checkbox" && type.value !== "radio") || 605 element.checked 606 ) { 607 // Build array of values to submit 608 var values = []; 609 610 if (tagName === "select") { 611 var opt; 612 613 for (var j = 0; j < element.options.length; j++) { 614 opt = element.options[j]; 615 if (opt.selected && !opt.disabled) { 616 values.push(opt.hasAttribute("value") ? opt.value : opt.text); 617 } 618 } 619 } else { 620 values.push(element.value); 621 } 622 623 for (var k = 0; k < values.length; k++) { 624 requestParams.push({ 625 name: encodeURIComponent(element.name), 626 value: encodeURIComponent(values[k]) 627 }); 628 } 629 } 630 } 631 } 632 633 return requestParams; 634 } 635 636 function checkIfShouldAbort(virtLinkElement, options) { 637 // Ignore external links. 638 if ( 639 virtLinkElement.protocol !== window.location.protocol || 640 virtLinkElement.host !== window.location.host 641 ) { 642 return "external"; 643 } 644 645 // Ignore click if we are on an anchor on the same page 646 if ( 647 virtLinkElement.hash && 648 virtLinkElement.href.replace(virtLinkElement.hash, "") === 649 window.location.href.replace(location.hash, "") 650 ) { 651 return "anchor"; 652 } 653 654 // Ignore empty anchor "foo.html#" 655 if (virtLinkElement.href === window.location.href.split("#")[0] + "#") { 656 return "anchor-empty"; 657 } 658 659 // if declared as a full reload, just normally submit the form 660 if ( 661 options.currentUrlFullReload && 662 virtLinkElement.href === window.location.href.split("#")[0] 663 ) { 664 return "reload"; 665 } 666 } 667 668 var isDefaultPrevented = function(event) { 669 return event.defaultPrevented || event.returnValue === false; 670 }; 671 672 module.exports = function(el) { 673 var that = this; 674 675 el.setAttribute(attrState, ""); 676 677 on(el, "submit", function(event) { 678 formAction.call(that, el, event); 679 }); 680 }; 681 682 },{"../events/on":4,"../util/clone":20}],12:[function(require,module,exports){ 683 var on = require("../events/on"); 684 var clone = require("../util/clone"); 685 686 var attrState = "data-pjax-state"; 687 688 var linkAction = function(el, event) { 689 if (isDefaultPrevented(event)) { 690 return; 691 } 692 693 // Since loadUrl modifies options and we may add our own modifications below, 694 // clone it so the changes don't persist 695 var options = clone(this.options); 696 697 var attrValue = checkIfShouldAbort(el, event); 698 if (attrValue) { 699 el.setAttribute(attrState, attrValue); 700 return; 701 } 702 703 event.preventDefault(); 704 705 // donât do "nothing" if user try to reload the page by clicking the same link twice 706 if ( 707 this.options.currentUrlFullReload && 708 el.href === window.location.href.split("#")[0] 709 ) { 710 el.setAttribute(attrState, "reload"); 711 this.reload(); 712 return; 713 } 714 715 el.setAttribute(attrState, "load"); 716 717 options.triggerElement = el; 718 this.loadUrl(el.href, options); 719 }; 720 721 function checkIfShouldAbort(el, event) { 722 // Donât break browser special behavior on links (like page in new window) 723 if ( 724 event.which > 1 || 725 event.metaKey || 726 event.ctrlKey || 727 event.shiftKey || 728 event.altKey 729 ) { 730 return "modifier"; 731 } 732 733 // we do test on href now to prevent unexpected behavior if for some reason 734 // user have href that can be dynamically updated 735 736 // Ignore external links. 737 if ( 738 el.protocol !== window.location.protocol || 739 el.host !== window.location.host 740 ) { 741 return "external"; 742 } 743 744 // Ignore anchors on the same page (keep native behavior) 745 if ( 746 el.hash && 747 el.href.replace(el.hash, "") === 748 window.location.href.replace(location.hash, "") 749 ) { 750 return "anchor"; 751 } 752 753 // Ignore empty anchor "foo.html#" 754 if (el.href === window.location.href.split("#")[0] + "#") { 755 return "anchor-empty"; 756 } 757 } 758 759 var isDefaultPrevented = function(event) { 760 return event.defaultPrevented || event.returnValue === false; 761 }; 762 763 module.exports = function(el) { 764 var that = this; 765 766 el.setAttribute(attrState, ""); 767 768 on(el, "click", function(event) { 769 linkAction.call(that, el, event); 770 }); 771 772 on( 773 el, 774 "keyup", 775 function(event) { 776 if (event.keyCode === 13) { 777 linkAction.call(that, el, event); 778 } 779 }.bind(this) 780 ); 781 }; 782 783 },{"../events/on":4,"../util/clone":20}],13:[function(require,module,exports){ 784 var clone = require("../util/clone"); 785 var newUid = require("../uniqueid"); 786 var trigger = require("../events/trigger"); 787 788 module.exports = function(responseText, request, href, options) { 789 options = clone(options || this.options); 790 options.request = request; 791 792 // Fail if unable to load HTML via AJAX 793 if (responseText === false) { 794 trigger(document, "pjax:complete pjax:error", options); 795 796 return; 797 } 798 799 // push scroll position to history 800 var currentState = window.history.state || {}; 801 window.history.replaceState( 802 { 803 url: currentState.url || window.location.href, 804 title: currentState.title || document.title, 805 uid: currentState.uid || newUid(), 806 scrollPos: [ 807 document.documentElement.scrollLeft || document.body.scrollLeft, 808 document.documentElement.scrollTop || document.body.scrollTop 809 ] 810 }, 811 document.title, 812 window.location.href 813 ); 814 815 // Check for redirects 816 var oldHref = href; 817 if (request.responseURL) { 818 if (href !== request.responseURL) { 819 href = request.responseURL; 820 } 821 } else if (request.getResponseHeader("X-PJAX-URL")) { 822 href = request.getResponseHeader("X-PJAX-URL"); 823 } else if (request.getResponseHeader("X-XHR-Redirected-To")) { 824 href = request.getResponseHeader("X-XHR-Redirected-To"); 825 } 826 827 // Add back the hash if it was removed 828 var a = document.createElement("a"); 829 a.href = oldHref; 830 var oldHash = a.hash; 831 a.href = href; 832 if (oldHash && !a.hash) { 833 a.hash = oldHash; 834 href = a.href; 835 } 836 837 this.state.href = href; 838 this.state.options = options; 839 840 try { 841 this.loadContent(responseText, options); 842 } catch (e) { 843 trigger(document, "pjax:error", options); 844 845 if (!this.options.debug) { 846 if (console && console.error) { 847 console.error("Pjax switch fail: ", e); 848 } 849 return this.latestChance(href); 850 } else { 851 throw e; 852 } 853 } 854 }; 855 856 },{"../events/trigger":5,"../uniqueid":19,"../util/clone":20}],14:[function(require,module,exports){ 857 module.exports = function() { 858 if (this.options.debug && console) { 859 if (typeof console.log === "function") { 860 console.log.apply(console, arguments); 861 } 862 // IE is weird 863 else if (console.log) { 864 console.log(arguments); 865 } 866 } 867 }; 868 869 },{}],15:[function(require,module,exports){ 870 var attrState = "data-pjax-state"; 871 872 module.exports = function(el) { 873 switch (el.tagName.toLowerCase()) { 874 case "a": 875 // only attach link if el does not already have link attached 876 if (!el.hasAttribute(attrState)) { 877 this.attachLink(el); 878 } 879 break; 880 881 case "form": 882 // only attach link if el does not already have link attached 883 if (!el.hasAttribute(attrState)) { 884 this.attachForm(el); 885 } 886 break; 887 888 default: 889 throw "Pjax can only be applied on <a> or <form> submit"; 890 } 891 }; 892 893 },{}],16:[function(require,module,exports){ 894 var updateQueryString = require("./util/update-query-string"); 895 896 module.exports = function(location, options, callback) { 897 options = options || {}; 898 var queryString; 899 var requestOptions = options.requestOptions || {}; 900 var requestMethod = (requestOptions.requestMethod || "GET").toUpperCase(); 901 var requestParams = requestOptions.requestParams || null; 902 var formData = requestOptions.formData || null; 903 var requestPayload = null; 904 var request = new XMLHttpRequest(); 905 var timeout = options.timeout || 0; 906 907 request.onreadystatechange = function() { 908 if (request.readyState === 4) { 909 if (request.status === 200) { 910 callback(request.responseText, request, location, options); 911 } else if (request.status !== 0) { 912 callback(null, request, location, options); 913 } 914 } 915 }; 916 917 request.onerror = function(e) { 918 console.log(e); 919 callback(null, request, location, options); 920 }; 921 922 request.ontimeout = function() { 923 callback(null, request, location, options); 924 }; 925 926 // Prepare the request payload for forms, if available 927 if (requestParams && requestParams.length) { 928 // Build query string 929 queryString = requestParams 930 .map(function(param) { 931 return param.name + "=" + param.value; 932 }) 933 .join("&"); 934 935 switch (requestMethod) { 936 case "GET": 937 // Reset query string to avoid an issue with repeat submissions where checkboxes that were 938 // previously checked are incorrectly preserved 939 location = location.split("?")[0]; 940 941 // Append new query string 942 location += "?" + queryString; 943 break; 944 945 case "POST": 946 // Send query string as request payload 947 requestPayload = queryString; 948 break; 949 } 950 } else if (formData) { 951 requestPayload = formData; 952 } 953 954 // Add a timestamp as part of the query string if cache busting is enabled 955 if (options.cacheBust) { 956 location = updateQueryString(location, "t", Date.now()); 957 } 958 959 request.open(requestMethod, location, true); 960 request.timeout = timeout; 961 request.setRequestHeader("X-Requested-With", "XMLHttpRequest"); 962 request.setRequestHeader("X-PJAX", "true"); 963 request.setRequestHeader( 964 "X-PJAX-Selectors", 965 JSON.stringify(options.selectors) 966 ); 967 968 // Send the proper header information for POST forms 969 if (requestPayload && requestMethod === "POST" && !formData) { 970 request.setRequestHeader( 971 "Content-Type", 972 "application/x-www-form-urlencoded" 973 ); 974 } 975 976 request.send(requestPayload); 977 978 return request; 979 }; 980 981 },{"./util/update-query-string":24}],17:[function(require,module,exports){ 982 var forEachEls = require("./foreach-els"); 983 984 var defaultSwitches = require("./switches"); 985 986 module.exports = function( 987 switches, 988 switchesOptions, 989 selectors, 990 fromEl, 991 toEl, 992 options 993 ) { 994 var switchesQueue = []; 995 996 selectors.forEach(function(selector) { 997 var newEls = fromEl.querySelectorAll(selector); 998 var oldEls = toEl.querySelectorAll(selector); 999 if (this.log) { 1000 this.log("Pjax switch", selector, newEls, oldEls); 1001 } 1002 if (newEls.length !== oldEls.length) { 1003 throw "DOM doesnât look the same on new loaded page: â" + 1004 selector + 1005 "â - new " + 1006 newEls.length + 1007 ", old " + 1008 oldEls.length; 1009 } 1010 1011 forEachEls( 1012 newEls, 1013 function(newEl, i) { 1014 var oldEl = oldEls[i]; 1015 if (this.log) { 1016 this.log("newEl", newEl, "oldEl", oldEl); 1017 } 1018 1019 var callback = switches[selector] 1020 ? switches[selector].bind( 1021 this, 1022 oldEl, 1023 newEl, 1024 options, 1025 switchesOptions[selector] 1026 ) 1027 : defaultSwitches.outerHTML.bind(this, oldEl, newEl, options); 1028 1029 switchesQueue.push(callback); 1030 }, 1031 this 1032 ); 1033 }, this); 1034 1035 this.state.numPendingSwitches = switchesQueue.length; 1036 1037 switchesQueue.forEach(function(queuedSwitch) { 1038 queuedSwitch(); 1039 }); 1040 }; 1041 1042 },{"./foreach-els":7,"./switches":18}],18:[function(require,module,exports){ 1043 var on = require("./events/on"); 1044 1045 module.exports = { 1046 outerHTML: function(oldEl, newEl) { 1047 oldEl.outerHTML = newEl.outerHTML; 1048 this.onSwitch(); 1049 }, 1050 1051 innerHTML: function(oldEl, newEl) { 1052 oldEl.innerHTML = newEl.innerHTML; 1053 1054 if (newEl.className === "") { 1055 oldEl.removeAttribute("class"); 1056 } else { 1057 oldEl.className = newEl.className; 1058 } 1059 1060 this.onSwitch(); 1061 }, 1062 1063 switchElementsAlt: function(oldEl, newEl) { 1064 oldEl.innerHTML = newEl.innerHTML; 1065 1066 // Copy attributes from the new element to the old one 1067 if (newEl.hasAttributes()) { 1068 var attrs = newEl.attributes; 1069 for (var i = 0; i < attrs.length; i++) { 1070 oldEl.attributes.setNamedItem(attrs[i].cloneNode()); 1071 } 1072 } 1073 1074 this.onSwitch(); 1075 }, 1076 1077 // Equivalent to outerHTML(), but doesn't require switchElementsAlt() for <head> and <body> 1078 replaceNode: function(oldEl, newEl) { 1079 oldEl.parentNode.replaceChild(newEl, oldEl); 1080 this.onSwitch(); 1081 }, 1082 1083 sideBySide: function(oldEl, newEl, options, switchOptions) { 1084 var forEach = Array.prototype.forEach; 1085 var elsToRemove = []; 1086 var elsToAdd = []; 1087 var fragToAppend = document.createDocumentFragment(); 1088 var animationEventNames = 1089 "animationend webkitAnimationEnd MSAnimationEnd oanimationend"; 1090 var animatedElsNumber = 0; 1091 var sexyAnimationEnd = function(e) { 1092 if (e.target !== e.currentTarget) { 1093 // end triggered by an animation on a child 1094 return; 1095 } 1096 1097 animatedElsNumber--; 1098 if (animatedElsNumber <= 0 && elsToRemove) { 1099 elsToRemove.forEach(function(el) { 1100 // browsing quickly can make the el 1101 // already removed by last page update ? 1102 if (el.parentNode) { 1103 el.parentNode.removeChild(el); 1104 } 1105 }); 1106 1107 elsToAdd.forEach(function(el) { 1108 el.className = el.className.replace( 1109 el.getAttribute("data-pjax-classes"), 1110 "" 1111 ); 1112 el.removeAttribute("data-pjax-classes"); 1113 }); 1114 1115 elsToAdd = null; // free memory 1116 elsToRemove = null; // free memory 1117 1118 // this is to trigger some repaint (example: picturefill) 1119 this.onSwitch(); 1120 } 1121 }.bind(this); 1122 1123 switchOptions = switchOptions || {}; 1124 1125 forEach.call(oldEl.childNodes, function(el) { 1126 elsToRemove.push(el); 1127 if (el.classList && !el.classList.contains("js-Pjax-remove")) { 1128 // for fast switch, clean element that just have been added, & not cleaned yet. 1129 if (el.hasAttribute("data-pjax-classes")) { 1130 el.className = el.className.replace( 1131 el.getAttribute("data-pjax-classes"), 1132 "" 1133 ); 1134 el.removeAttribute("data-pjax-classes"); 1135 } 1136 el.classList.add("js-Pjax-remove"); 1137 if (switchOptions.callbacks && switchOptions.callbacks.removeElement) { 1138 switchOptions.callbacks.removeElement(el); 1139 } 1140 if (switchOptions.classNames) { 1141 el.className += 1142 " " + 1143 switchOptions.classNames.remove + 1144 " " + 1145 (options.backward 1146 ? switchOptions.classNames.backward 1147 : switchOptions.classNames.forward); 1148 } 1149 animatedElsNumber++; 1150 on(el, animationEventNames, sexyAnimationEnd, true); 1151 } 1152 }); 1153 1154 forEach.call(newEl.childNodes, function(el) { 1155 if (el.classList) { 1156 var addClasses = ""; 1157 if (switchOptions.classNames) { 1158 addClasses = 1159 " js-Pjax-add " + 1160 switchOptions.classNames.add + 1161 " " + 1162 (options.backward 1163 ? switchOptions.classNames.forward 1164 : switchOptions.classNames.backward); 1165 } 1166 if (switchOptions.callbacks && switchOptions.callbacks.addElement) { 1167 switchOptions.callbacks.addElement(el); 1168 } 1169 el.className += addClasses; 1170 el.setAttribute("data-pjax-classes", addClasses); 1171 elsToAdd.push(el); 1172 fragToAppend.appendChild(el); 1173 animatedElsNumber++; 1174 on(el, animationEventNames, sexyAnimationEnd, true); 1175 } 1176 }); 1177 1178 // pass all className of the parent 1179 oldEl.className = newEl.className; 1180 oldEl.appendChild(fragToAppend); 1181 } 1182 }; 1183 1184 },{"./events/on":4}],19:[function(require,module,exports){ 1185 module.exports = (function() { 1186 var counter = 0; 1187 return function() { 1188 var id = "pjax" + new Date().getTime() + "_" + counter; 1189 counter++; 1190 return id; 1191 }; 1192 })(); 1193 1194 },{}],20:[function(require,module,exports){ 1195 module.exports = function(obj) { 1196 /* istanbul ignore if */ 1197 if (null === obj || "object" !== typeof obj) { 1198 return obj; 1199 } 1200 var copy = obj.constructor(); 1201 for (var attr in obj) { 1202 if (obj.hasOwnProperty(attr)) { 1203 copy[attr] = obj[attr]; 1204 } 1205 } 1206 return copy; 1207 }; 1208 1209 },{}],21:[function(require,module,exports){ 1210 module.exports = function contains(doc, selectors, el) { 1211 for (var i = 0; i < selectors.length; i++) { 1212 var selectedEls = doc.querySelectorAll(selectors[i]); 1213 for (var j = 0; j < selectedEls.length; j++) { 1214 if (selectedEls[j].contains(el)) { 1215 return true; 1216 } 1217 } 1218 } 1219 1220 return false; 1221 }; 1222 1223 },{}],22:[function(require,module,exports){ 1224 module.exports = function(target) { 1225 if (target == null) { 1226 return null; 1227 } 1228 1229 var to = Object(target); 1230 1231 for (var i = 1; i < arguments.length; i++) { 1232 var source = arguments[i]; 1233 1234 if (source != null) { 1235 for (var key in source) { 1236 // Avoid bugs when hasOwnProperty is shadowed 1237 if (Object.prototype.hasOwnProperty.call(source, key)) { 1238 to[key] = source[key]; 1239 } 1240 } 1241 } 1242 } 1243 return to; 1244 }; 1245 1246 },{}],23:[function(require,module,exports){ 1247 module.exports = function() {}; 1248 1249 },{}],24:[function(require,module,exports){ 1250 module.exports = function(uri, key, value) { 1251 var re = new RegExp("([?&])" + key + "=.*?(&|$)", "i"); 1252 var separator = uri.indexOf("?") !== -1 ? "&" : "?"; 1253 if (uri.match(re)) { 1254 return uri.replace(re, "$1" + key + "=" + value + "$2"); 1255 } else { 1256 return uri + separator + key + "=" + value; 1257 } 1258 }; 1259 1260 },{}]},{},[1])(1) 1261 });
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.