diff --git a/src/theme/book.css b/src/theme/book.css index 7a2a2922..a2c4fbda 100644 --- a/src/theme/book.css +++ b/src/theme/book.css @@ -141,7 +141,8 @@ table thead td { max-width: 750px; padding-bottom: 50px; } -.content a { +.content a, +#searchresults a { text-decoration: none; } .content a:hover { @@ -153,6 +154,7 @@ table thead td { .menu-bar { height: 50px; display: flex; + position: relative; justify-content: space-between; align-items: baseline; } @@ -175,31 +177,52 @@ table thead td { .menu-bar .right-buttons { float: right; } -#searchbar { - border: 1px solid #BBB; - border-radius: 3px; - padding: 3px 5px; - width: 50px; - transition: width 0.5s ease-in-out; +.searchbar-outer { + display: none; + margin-left: auto; + margin-right: auto; + max-width: 750px; } -#searchbar:focus, #searchbar:hover, #searchbar.active { - width: 150px; +#searchbar { + display: block; + width: 98%; + border: 1px solid #CCC; + border-radius: 3px; + margin: 5px auto 0px auto; + padding: 10px 16px; + transition: box-shadow 300ms ease-in-out; +} +#searchbar:focus, #searchbar.active { + box-shadow: 0 0 3px #AAA; } .searchresults-header { + color: #CCC; font-weight: bold; font-size: 1em; + padding: 18px 0 0 5px; } .searchresults-outer { border-bottom: 1px dashed #CCC; display: none; } +ul#searchresults { + list-style: none; + padding-left: 20px; +} +ul#searchresults li { + margin: 10px 0px; +} .menu-title { - display: inline; + position: absolute; + display: block; + left: 0; + right: 0; font-weight: 200; font-size: 20px; line-height: 50px; text-align: center; margin: 0; + z-index: -1; opacity: 0; -ms-filter: "progid:DXImageTransform.Microsoft.Alpha(Opacity=0)"; filter: alpha(opacity=0); @@ -381,11 +404,15 @@ table thead td { .light .mobile-nav-chapters { background-color: #fafafa; } +.light #searchresults a, .light .content a:link, .light a:visited, .light a > .hljs { color: #4183c4; } +.light mark { + background-color: #a2cff5; +} .light .theme-popup { color: #333; background: #fafafa; @@ -502,11 +529,15 @@ table thead td { .coal .mobile-nav-chapters { background-color: #292c2f; } +.coal #searchresults a, .coal .content a:link, .coal a:visited, .coal a > .hljs { color: #2b79a2; } +.coal mark { + background-color: #355c7d; +} .coal .theme-popup { color: #98a3ad; background: #141617; @@ -623,11 +654,15 @@ table thead td { .navy .mobile-nav-chapters { background-color: #282d3f; } +.navy #searchresults a, .navy .content a:link, .navy a:visited, .navy a > .hljs { color: #2b79a2; } +.navy mark { + background-color: #a2cff5; +} .navy .theme-popup { color: #bcbdd0; background: #161923; @@ -744,11 +779,15 @@ table thead td { .rust .mobile-nav-chapters { background-color: #3b2e2a; } +.rust #searchresults a, .rust .content a:link, .rust a:visited, .rust a > .hljs { color: #2b79a2; } +.rust mark { + background-color: #e69f67; +} .rust .theme-popup { color: #262625; background: #e1e1db; @@ -865,11 +904,15 @@ table thead td { .ayu .mobile-nav-chapters { background-color: #14191f; } +.ayu #searchresults a, .ayu .content a:link, .ayu a:visited, .ayu a > .hljs { color: #0096cf; } +.ayu mark { + background-color: #e3b171; +} .ayu .theme-popup { color: #c5c5c5; background: #14191f; diff --git a/src/theme/book.js b/src/theme/book.js index 28c39879..8443cd68 100644 --- a/src/theme/book.js +++ b/src/theme/book.js @@ -1,5 +1,180 @@ $( document ).ready(function() { + // Helpers for searching + function create_test_searchindex() { + var searchindex = elasticlunr(function () { + this.addField('body'); + this.addField('title'); + this.setRef('id'); + }); + var content = $("#content"); + var paragraphs = content.children(); + var curr_title = ""; + var curr_body = ""; + var curr_ref = ""; + var push = function(ref) { + if ((curr_title.length > 0 || curr_body.length > 0) && curr_ref.length > 0) { + var doc = { + "id": curr_ref, + "body": curr_body, + "title": curr_title + } + searchindex.addDoc(doc); + } + curr_body = ""; + curr_title = ""; + curr_ref = ""; + }; + paragraphs.each(function(index, element) { + // todo uppercase + var el = $(element); + if (el.prop('nodeName').toUpperCase() == "A") { + // new header, push old paragraph to index + push(index); + curr_title = el.text(); + curr_ref = el.attr('href'); + } else { + curr_body += " \n " + el.text(); + } + // last paragraph + if (index == paragraphs.length - 1) { + push(index); + } + }); + return searchindex; + } + + function parseURL(url) { + var a = document.createElement('a'); + a.href = url; + return { + source: url, + protocol: a.protocol.replace(':',''), + host: a.hostname, + port: a.port, + params: (function(){ + var ret = {}; + var seg = a.search.replace(/^\?/,'').split('&'); + var len = seg.length, i = 0, s; + for (;i 0) { + searchheader = results.length + " search results for '" + searchterm + "':"; + } else if (results.length == 1) { + searchheader = results.length + " search result for '" + searchterm + "':"; + } else { + searchheader = "No search results for '" + searchterm + "'."; + } + $('#searchresults-header').text(searchheader); + + // Clear and insert results + var firstterm = searchterm.split(' ')[0]; + display.empty(); + for(var i = 0, size = results.length; i < size ; i++){ + var result = results[i]; + var firstoccurence = result.doc.body.search(firstterm); + var teaser = ""; + if (firstoccurence != -1) { + var teaserstartindex = firstoccurence - teaser_size_half; + var nextwordindex = result.doc.body.indexOf(" ", teaserstartindex); + if (nextwordindex != -1) { + teaserstartindex = nextwordindex; + } + var teaserendindex = firstoccurence + teaser_size_half; + nextwordindex = result.doc.body.indexOf(" ", teaserendindex); + if (nextwordindex != -1) { + teaserendindex = nextwordindex; + } + teaser = (teaserstartindex > 0) ? "..." : ""; + teaser += result.doc.body.substring(teaserstartindex, teaserendindex) + "..."; + } else { + teaser = result.doc.body.substr(0, 80) + "..."; + } + + var url = result.ref.split("#"); + if (url.length == 1) { + url.push(""); + } + + display.append('
  • ' + + result.doc.title + ': ' + teaser + "
  • "); + } + + // Display and scroll to results + $("#menu-bar").scrollTop(0); + $("#searchresults-outer").slideDown(); + } + + function doSearchOrHighlightFromUrl() { + // Check current URL for search request + var url = parseURL(window.location.href); + if (url.params.hasOwnProperty('search')) { + $("#searchbar-outer").slideDown(); + $("#searchbar")[0].value = url.params['search']; + $("#searchbar").trigger('keyup'); + } else { + $("#searchbar-outer").slideUp(); + } + + if (url.params.hasOwnProperty('highlight')) { + var words = url.params['highlight'].split(' '); + var header = $('#' + url.hash); + $('.content').mark(words, { + // exclude : ['.hljs'] + }); + } + } + + // url var url = window.location.pathname; @@ -60,6 +235,7 @@ $( document ).ready(function() { break; case KEY_CODES.SEARCH_KEY: e.preventDefault(); + $("#searchbar-outer").slideDown() $('#searchbar').focus(); break; } @@ -89,9 +265,14 @@ $( document ).ready(function() { } // For testing purposes: Index current page - var searchindex = create_text_searchindex(); - var current_searchterm = ""; - var teaser_size_half = 80; + var searchindex = create_test_searchindex(); + + $("#search-icon").click(function(e) { + var outer = $("#searchbar-outer"); + outer.slideToggle(); + // TODO: + // If invisible, clear URL search parameter + }); // Searchbar $("#searchbar").on('keyup', function (e) { @@ -100,70 +281,36 @@ $( document ).ready(function() { var searchterm = e.target.value.trim(); if (searchterm != "") { - // keep searchbar expanded $(e.target).addClass("active"); - // Don't search twice the same - if (current_searchterm == searchterm) { return; } - else { current_searchterm = searchterm; } - - // Do the actual search - var results = searchindex.search(searchterm, { - bool: "AND", - expand: true - }); - - // Display search metrics - var searchheader = ""; - if (results.length > 0) { - searchheader = results.length + " search results for '" + searchterm + "':"; - } else if (results.length == 1) { - searchheader = results.length + " search result for '" + searchterm + "':"; - } else { - searchheader = "No search results for '" + searchterm + "'."; - } - $('#searchresults-header').text(searchheader); - - // Clear and insert results - var firstterm = searchterm.split(' ')[0]; - display.empty(); - for(var i = 0, size = results.length; i < size ; i++){ - var result = results[i]; - document.lsd = result.doc; - var firstoccurence = result.doc.body.search(firstterm); - var teaser = ""; - if (firstoccurence != -1) { - var teaserstartindex = firstoccurence - teaser_size_half; - var nextwordindex = result.doc.body.indexOf(" ", teaserstartindex); - if (nextwordindex != -1) { - teaserstartindex = nextwordindex; - } - var teaserendindex = firstoccurence + teaser_size_half; - nextwordindex = result.doc.body.indexOf(" ", teaserendindex); - if (nextwordindex != -1) { - teaserendindex = nextwordindex; - } - teaser = (teaserstartindex > 0) ? "..." : ""; - teaser += result.doc.body.substring(teaserstartindex, teaserendindex) + "..."; - } else { - teaser = result.doc.body.substr(0, 80) + "..."; - } - - display.append('
  • ' + result.doc.title + ': ' - + teaser + "
  • "); - } - - // Display and scroll to results - sidebar.scrollTop(0); - outer.slideDown(); + doSearch(searchindex, searchterm); } else { - // searchbar can shrink $(e.target).removeClass("active"); outer.slideUp(); display.empty(); } + + var url = parseURL(window.location.href); + var first_search = ! url.params.hasOwnProperty("search"); + url.params["search"] = searchterm; + delete url.params["highlight"]; + url.hash = ""; + if (first_search) { + history.pushState({}, document.title, renderURL(url)); + } else { + history.replaceState({}, document.title, renderURL(url)); + } + $('.content').unmark(); }); + window.onpopstate = function(e) { + doSearchOrHighlightFromUrl(); + }; + + doSearchOrHighlightFromUrl(); + + + // Theme button $("#theme-toggle").click(function(){ if($('.theme-popup').length) { @@ -474,45 +621,3 @@ function run_rust_code(code_block) { }); } -function create_text_searchindex() { - var searchindex = elasticlunr(function () { - this.addField('body'); - this.addField('title'); - this.setRef('id'); - }); - var content = $("#content"); - var paragraphs = content.children(); - var curr_title = ""; - var curr_body = ""; - var curr_ref = ""; - var push = function(ref) { - if ((curr_title.length > 0 || curr_body.length > 0) && curr_ref.length > 0) { - var doc = { - "id": curr_ref, - "body": curr_body, - "title": curr_title - } - searchindex.addDoc(doc); - } - curr_body = ""; - curr_title = ""; - curr_ref = ""; - }; - paragraphs.each(function(index, element) { - // todo uppercase - var el = $(element); - if (el.prop('nodeName').toUpperCase() == "A") { - // new header, push old paragraph to index - push(index); - curr_title = el.text(); - curr_ref = el.attr('href'); - } else { - curr_body += " \n " + el.text(); - } - // last paragraph - if (index == paragraphs.length - 1) { - push(index); - } - }); - return searchindex; -} \ No newline at end of file diff --git a/src/theme/index.hbs b/src/theme/index.hbs index a72ff599..99204f88 100644 --- a/src/theme/index.hbs +++ b/src/theme/index.hbs @@ -56,6 +56,16 @@ } + + + + + + @@ -76,11 +86,6 @@ @@ -91,8 +96,7 @@
    - - +

    {{ book_title }}

    @@ -104,6 +108,17 @@ +
    + + +
    +
    +
      +
    +
    +
    + +
    {{{ content }}}
    diff --git a/src/theme/jquery.mark.min.js b/src/theme/jquery.mark.min.js new file mode 100644 index 00000000..b8710fe9 --- /dev/null +++ b/src/theme/jquery.mark.min.js @@ -0,0 +1,7 @@ +/*!*************************************************** + * mark.js v8.11.0 + * https://github.com/julmot/mark.js + * Copyright (c) 2014–2017, Julian Motz + * Released under the MIT license https://git.io/vwTVl + *****************************************************/ +"use strict";function _classCallCheck(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}var _extends=Object.assign||function(e){for(var t=1;t-1||r.indexOf("Trident")>-1)&&(this.ie=!0)}return _createClass(n,[{key:"log",value:function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:"debug",n=this.opt.log;this.opt.debug&&"object"===(void 0===n?"undefined":_typeof(n))&&"function"==typeof n[t]&&n[t]("mark.js: "+e)}},{key:"escapeStr",value:function(e){return e.replace(/[\-\[\]\/\{\}\(\)\*\+\?\.\\\^\$\|]/g,"\\$&")}},{key:"createRegExp",value:function(e){return"disabled"!==this.opt.wildcards&&(e=this.setupWildcardsRegExp(e)),e=this.escapeStr(e),Object.keys(this.opt.synonyms).length&&(e=this.createSynonymsRegExp(e)),(this.opt.ignoreJoiners||this.opt.ignorePunctuation.length)&&(e=this.setupIgnoreJoinersRegExp(e)),this.opt.diacritics&&(e=this.createDiacriticsRegExp(e)),e=this.createMergedBlanksRegExp(e),(this.opt.ignoreJoiners||this.opt.ignorePunctuation.length)&&(e=this.createJoinersRegExp(e)),"disabled"!==this.opt.wildcards&&(e=this.createWildcardsRegExp(e)),e=this.createAccuracyRegExp(e)}},{key:"createSynonymsRegExp",value:function(e){var t=this.opt.synonyms,n=this.opt.caseSensitive?"":"i",r=this.opt.ignoreJoiners||this.opt.ignorePunctuation.length?"\0":"";for(var i in t)if(t.hasOwnProperty(i)){var o=t[i],a="disabled"!==this.opt.wildcards?this.setupWildcardsRegExp(i):this.escapeStr(i),s="disabled"!==this.opt.wildcards?this.setupWildcardsRegExp(o):this.escapeStr(o);""!==a&&""!==s&&(e=e.replace(new RegExp("("+a+"|"+s+")","gm"+n),r+"("+this.processSynomyms(a)+"|"+this.processSynomyms(s)+")"+r))}return e}},{key:"processSynomyms",value:function(e){return(this.opt.ignoreJoiners||this.opt.ignorePunctuation.length)&&(e=this.setupIgnoreJoinersRegExp(e)),e}},{key:"setupWildcardsRegExp",value:function(e){return(e=e.replace(/(?:\\)*\?/g,function(e){return"\\"===e.charAt(0)?"?":""})).replace(/(?:\\)*\*/g,function(e){return"\\"===e.charAt(0)?"*":""})}},{key:"createWildcardsRegExp",value:function(e){var t="withSpaces"===this.opt.wildcards;return e.replace(/\u0001/g,t?"[\\S\\s]?":"\\S?").replace(/\u0002/g,t?"[\\S\\s]*?":"\\S*")}},{key:"setupIgnoreJoinersRegExp",value:function(e){return e.replace(/[^(|)\\]/g,function(e,t,n){var r=n.charAt(t+1);return/[(|)\\]/.test(r)||""===r?e:e+"\0"})}},{key:"createJoinersRegExp",value:function(e){var t=[],n=this.opt.ignorePunctuation;return Array.isArray(n)&&n.length&&t.push(this.escapeStr(n.join(""))),this.opt.ignoreJoiners&&t.push("\\u00ad\\u200b\\u200c\\u200d"),t.length?e.split(/\u0000+/).join("["+t.join("")+"]*"):e}},{key:"createDiacriticsRegExp",value:function(e){var t=this.opt.caseSensitive?"":"i",n=this.opt.caseSensitive?["aàáảãạăằắẳẵặâầấẩẫậäåāą","AÀÁẢÃẠĂẰẮẲẴẶÂẦẤẨẪẬÄÅĀĄ","cçćč","CÇĆČ","dđď","DĐĎ","eèéẻẽẹêềếểễệëěēę","EÈÉẺẼẸÊỀẾỂỄỆËĚĒĘ","iìíỉĩịîïī","IÌÍỈĨỊÎÏĪ","lł","LŁ","nñňń","NÑŇŃ","oòóỏõọôồốổỗộơởỡớờợöøō","OÒÓỎÕỌÔỒỐỔỖỘƠỞỠỚỜỢÖØŌ","rř","RŘ","sšśșş","SŠŚȘŞ","tťțţ","TŤȚŢ","uùúủũụưừứửữựûüůū","UÙÚỦŨỤƯỪỨỬỮỰÛÜŮŪ","yýỳỷỹỵÿ","YÝỲỶỸỴŸ","zžżź","ZŽŻŹ"]:["aàáảãạăằắẳẵặâầấẩẫậäåāąAÀÁẢÃẠĂẰẮẲẴẶÂẦẤẨẪẬÄÅĀĄ","cçćčCÇĆČ","dđďDĐĎ","eèéẻẽẹêềếểễệëěēęEÈÉẺẼẸÊỀẾỂỄỆËĚĒĘ","iìíỉĩịîïīIÌÍỈĨỊÎÏĪ","lłLŁ","nñňńNÑŇŃ","oòóỏõọôồốổỗộơởỡớờợöøōOÒÓỎÕỌÔỒỐỔỖỘƠỞỠỚỜỢÖØŌ","rřRŘ","sšśșşSŠŚȘŞ","tťțţTŤȚŢ","uùúủũụưừứửữựûüůūUÙÚỦŨỤƯỪỨỬỮỰÛÜŮŪ","yýỳỷỹỵÿYÝỲỶỸỴŸ","zžżźZŽŻŹ"],r=[];return e.split("").forEach(function(i){n.every(function(n){if(-1!==n.indexOf(i)){if(r.indexOf(n)>-1)return!1;e=e.replace(new RegExp("["+n+"]","gm"+t),"["+n+"]"),r.push(n)}return!0})}),e}},{key:"createMergedBlanksRegExp",value:function(e){return e.replace(/[\s]+/gim,"[\\s]+")}},{key:"createAccuracyRegExp",value:function(e){var t=this,n=this.opt.accuracy,r="string"==typeof n?n:n.value,i="";switch(("string"==typeof n?[]:n.limiters).forEach(function(e){i+="|"+t.escapeStr(e)}),r){case"partially":default:return"()("+e+")";case"complementary":return"()([^"+(i="\\s"+(i||this.escapeStr("!\"#$%&'()*+,-./:;<=>?@[\\]^_`{|}~¡¿")))+"]*"+e+"[^"+i+"]*)";case"exactly":return"(^|\\s"+i+")("+e+")(?=$|\\s"+i+")"}}},{key:"getSeparatedKeywords",value:function(e){var t=this,n=[];return e.forEach(function(e){t.opt.separateWordSearch?e.split(" ").forEach(function(e){e.trim()&&-1===n.indexOf(e)&&n.push(e)}):e.trim()&&-1===n.indexOf(e)&&n.push(e)}),{keywords:n.sort(function(e,t){return t.length-e.length}),length:n.length}}},{key:"isNumeric",value:function(e){return Number(parseFloat(e))==e}},{key:"checkRanges",value:function(e){var t=this;if(!Array.isArray(e)||"[object Object]"!==Object.prototype.toString.call(e[0]))return this.log("markRanges() will only accept an array of objects"),this.opt.noMatch(e),[];var n=[],r=0;return e.sort(function(e,t){return e.start-t.start}).forEach(function(e){var i=t.callNoMatchOnInvalidRanges(e,r),o=i.start,a=i.end;i.valid&&(e.start=o,e.length=a-o,n.push(e),r=a)}),n}},{key:"callNoMatchOnInvalidRanges",value:function(e,t){var n=void 0,r=void 0,i=!1;return e&&void 0!==e.start?(r=(n=parseInt(e.start,10))+parseInt(e.length,10),this.isNumeric(e.start)&&this.isNumeric(e.length)&&r-t>0&&r-n>0?i=!0:(this.log("Ignoring invalid or overlapping range: "+JSON.stringify(e)),this.opt.noMatch(e))):(this.log("Ignoring invalid range: "+JSON.stringify(e)),this.opt.noMatch(e)),{start:n,end:r,valid:i}}},{key:"checkWhitespaceRanges",value:function(e,t,n){var r=void 0,i=!0,o=n.length,a=t-o,s=parseInt(e.start,10)-a;return s=s>o?o:s,(r=s+parseInt(e.length,10))>o&&(r=o,this.log("End range automatically set to the max value of "+o)),s<0||r-s<0||s>o||r>o?(i=!1,this.log("Invalid range: "+JSON.stringify(e)),this.opt.noMatch(e)):""===n.substring(s,r).replace(/\s+/g,"")&&(i=!1,this.log("Skipping whitespace only range: "+JSON.stringify(e)),this.opt.noMatch(e)),{start:s,end:r,valid:i}}},{key:"getTextNodes",value:function(e){var t=this,n="",r=[];this.iterator.forEachNode(NodeFilter.SHOW_TEXT,function(e){r.push({start:n.length,end:(n+=e.textContent).length,node:e})},function(e){return t.matchesExclude(e.parentNode)?NodeFilter.FILTER_REJECT:NodeFilter.FILTER_ACCEPT},function(){e({value:n,nodes:r})})}},{key:"matchesExclude",value:function(e){return i.matches(e,this.opt.exclude.concat(["script","style","title","head","html"]))}},{key:"wrapRangeInTextNode",value:function(e,n,r){var i=this.opt.element?this.opt.element:"mark",o=e.splitText(n),a=o.splitText(r-n),s=t.createElement(i);return s.setAttribute("data-markjs","true"),this.opt.className&&s.setAttribute("class",this.opt.className),s.textContent=o.textContent,o.parentNode.replaceChild(s,o),a}},{key:"wrapRangeInMappedTextNode",value:function(e,t,n,r,i){var o=this;e.nodes.every(function(a,s){var c=e.nodes[s+1];if(void 0===c||c.start>t){if(!r(a.node))return!1;var u=t-a.start,l=(n>a.end?a.end:n)-a.start,h=e.value.substr(0,a.start),f=e.value.substr(l+a.start);if(a.node=o.wrapRangeInTextNode(a.node,u,l),e.value=h+f,e.nodes.forEach(function(t,n){n>=s&&(e.nodes[n].start>0&&n!==s&&(e.nodes[n].start-=l),e.nodes[n].end-=l)}),n-=l,i(a.node.previousSibling,a.start),!(n>a.end))return!1;t=a.end}return!0})}},{key:"wrapMatches",value:function(e,t,n,r,i){var o=this,a=0===t?0:t+1;this.getTextNodes(function(t){t.nodes.forEach(function(t){t=t.node;for(var i=void 0;null!==(i=e.exec(t.textContent))&&""!==i[a];)if(n(i[a],t)){var s=i.index;if(0!==a)for(var c=1;c1&&void 0!==arguments[1])||arguments[1],r=arguments.length>2&&void 0!==arguments[2]?arguments[2]:[],i=arguments.length>3&&void 0!==arguments[3]?arguments[3]:5e3;_classCallCheck(this,e),this.ctx=t,this.iframes=n,this.exclude=r,this.iframesTimeout=i}return _createClass(e,[{key:"getContexts",value:function(){var e=[];return(void 0!==this.ctx&&this.ctx?NodeList.prototype.isPrototypeOf(this.ctx)?Array.prototype.slice.call(this.ctx):Array.isArray(this.ctx)?this.ctx:"string"==typeof this.ctx?Array.prototype.slice.call(t.querySelectorAll(this.ctx)):[this.ctx]:[]).forEach(function(t){var n=e.filter(function(e){return e.contains(t)}).length>0;-1!==e.indexOf(t)||n||e.push(t)}),e}},{key:"getIframeContents",value:function(e,t){var n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:function(){},r=void 0;try{var i=e.contentWindow;if(r=i.document,!i||!r)throw new Error("iframe inaccessible")}catch(e){n()}r&&t(r)}},{key:"isIframeBlank",value:function(e){var t="about:blank",n=e.getAttribute("src").trim();return e.contentWindow.location.href===t&&n!==t&&n}},{key:"observeIframeLoad",value:function(e,t,n){var r=this,i=!1,o=null,a=function a(){if(!i){i=!0,clearTimeout(o);try{r.isIframeBlank(e)||(e.removeEventListener("load",a),r.getIframeContents(e,t,n))}catch(e){n()}}};e.addEventListener("load",a),o=setTimeout(a,this.iframesTimeout)}},{key:"onIframeReady",value:function(e,t,n){try{"complete"===e.contentWindow.document.readyState?this.isIframeBlank(e)?this.observeIframeLoad(e,t,n):this.getIframeContents(e,t,n):this.observeIframeLoad(e,t,n)}catch(e){n()}}},{key:"waitForIframes",value:function(e,t){var n=this,r=0;this.forEachIframe(e,function(){return!0},function(e){r++,n.waitForIframes(e.querySelector("html"),function(){--r||t()})},function(e){e||t()})}},{key:"forEachIframe",value:function(t,n,r){var i=this,o=arguments.length>3&&void 0!==arguments[3]?arguments[3]:function(){},a=t.querySelectorAll("iframe"),s=a.length,c=0;a=Array.prototype.slice.call(a);var u=function(){--s<=0&&o(c)};s||u(),a.forEach(function(t){e.matches(t,i.exclude)?u():i.onIframeReady(t,function(e){n(t)&&(c++,r(e)),u()},u)})}},{key:"createIterator",value:function(e,n,r){return t.createNodeIterator(e,n,r,!1)}},{key:"createInstanceOnIframe",value:function(t){return new e(t.querySelector("html"),this.iframes)}},{key:"compareNodeIframe",value:function(e,t,n){if(e.compareDocumentPosition(n)&Node.DOCUMENT_POSITION_PRECEDING){if(null===t)return!0;if(t.compareDocumentPosition(n)&Node.DOCUMENT_POSITION_FOLLOWING)return!0}return!1}},{key:"getIteratorNode",value:function(e){var t=e.previousNode(),n=void 0;return n=null===t?e.nextNode():e.nextNode()&&e.nextNode(),{prevNode:t,node:n}}},{key:"checkIframeFilter",value:function(e,t,n,r){var i=!1,o=!1;return r.forEach(function(e,t){e.val===n&&(i=t,o=e.handled)}),this.compareNodeIframe(e,t,n)?(!1!==i||o?!1===i||o||(r[i].handled=!0):r.push({val:n,handled:!0}),!0):(!1===i&&r.push({val:n,handled:!1}),!1)}},{key:"handleOpenIframes",value:function(e,t,n,r){var i=this;e.forEach(function(e){e.handled||i.getIframeContents(e.val,function(e){i.createInstanceOnIframe(e).forEachNode(t,n,r)})})}},{key:"iterateThroughNodes",value:function(e,t,n,r,i){for(var o=this,a=this.createIterator(t,e,r),s=[],c=[],u=void 0,l=void 0;function(){var e=o.getIteratorNode(a);return l=e.prevNode,u=e.node}();)this.iframes&&this.forEachIframe(t,function(e){return o.checkIframeFilter(u,l,e,s)},function(t){o.createInstanceOnIframe(t).forEachNode(e,function(e){return c.push(e)},r)}),c.push(u);c.forEach(function(e){n(e)}),this.iframes&&this.handleOpenIframes(s,e,n,r),i()}},{key:"forEachNode",value:function(e,t,n){var r=this,i=arguments.length>3&&void 0!==arguments[3]?arguments[3]:function(){},o=this.getContexts(),a=o.length;a||i(),o.forEach(function(o){var s=function(){r.iterateThroughNodes(e,o,t,n,function(){--a<=0&&i()})};r.iframes?r.waitForIframes(o,s):s()})}}],[{key:"matches",value:function(e,t){var n="string"==typeof t?[t]:t,r=e.matches||e.matchesSelector||e.msMatchesSelector||e.mozMatchesSelector||e.oMatchesSelector||e.webkitMatchesSelector;if(r){var i=!1;return n.every(function(t){return!r.call(e,t)||(i=!0,!1)}),i}return!1}}]),e}();return n.fn.mark=function(e,t){return new r(this.get()).mark(e,t),this},n.fn.markRegExp=function(e,t){return new r(this.get()).markRegExp(e,t),this},n.fn.markRanges=function(e,t){return new r(this.get()).markRanges(e,t),this},n.fn.unmark=function(e){return new r(this.get()).unmark(e),this},n},window,document); \ No newline at end of file