1/** 2 * Contains utility functions 3 */ 4var utils = new function() { 5 6 /** 7 * Retrieves an array of URL query string parameters in order 8 * @param url 9 * @returns params 10 */ 11 this.getUrlParams = function(url) { 12 13 // ignore hash # in URL when retrieving params 14 var hashIndex = url.indexOf('#'); 15 if (hashIndex > 0) { 16 url = url.substring(0, hashIndex); 17 } 18 19 var params = [], hash; 20 if (url.indexOf("?") !== -1) { 21 var hashes = url.slice(url.indexOf('?') + 1).split('&'); 22 for ( var i = 0; i < hashes.length; i++) { 23 hash = hashes[i].split('='); 24 params.push(hash[0]); 25 params[hash[0]] = hash[1]; 26 } 27 } 28 return params; 29 }; 30 31 /** 32 * Gets a URL query string parameter by name 33 * 34 * @param url 35 * @param name 36 * @returns url query string parameter 37 */ 38 this.getUrlParamByName = function(url, name) { 39 return this.getUrlParams(url)[name]; 40 }; 41 42 43 /** 44 * Returns the x and y coordinates of the event 45 * @param event 46 * @returns x and y coordinates 47 */ 48 this.getEventXYCoords = function(event) { 49 var xCoord = ''; 50 var yCoord = ''; 51 if ((event.clientX || event.clientY) && document.body 52 && document.body.scrollLeft != null) { 53 xCoord = event.clientX + document.body.scrollLeft; 54 yCoord = event.clientY + document.body.scrollTop; 55 } 56 if ((event.clientX || event.clientY) && document.compatMode == 'CSS1Compat' 57 && document.documentElement 58 && document.documentElement.scrollLeft != null) { 59 xCoord = event.clientX + document.documentElement.scrollLeft; 60 yCoord = event.clientY + document.documentElement.scrollTop; 61 } 62 if (event.pageX || event.pageY) { 63 xCoord = event.pageX; 64 yCoord = event.pageY; 65 } 66 67 if (yCoord != '') { 68 if (jQuery('#wpadminbar').length > 0) { 69 yCoord -= jQuery('#wpadminbar').height(); 70 } 71 } 72 return { xCoord : xCoord, yCoord : yCoord }; 73 }; 74 75 76 /** 77 * Returns the remaining horizontal scroll width available. It does not include 78 * the actual scrollbar. 79 * 80 * @returns remaining scrolling width 81 */ 82 this.getRemainingScrollWidth = function() { 83 if ('scrollMaxX' in window) { // only supported by Firefox 84 return window.scrollMaxX; 85 } else { 86 return (document.documentElement.scrollWidth - document.documentElement.clientWidth); 87 } 88 }; 89 90 91 /** 92 * Calculates the vertical scrollbar width 93 * 94 * @returns scrollbar width 95 */ 96 this.getVerticalScrollbarWidth = function() { 97 98 var scrollDiv = document.createElement("div"); 99 scrollDiv.className = "scrollbar-measure"; 100 scrollDiv.style.width = "100px"; 101 scrollDiv.style.height = "100px"; 102 scrollDiv.style.overflow = "scroll"; 103 scrollDiv.style.position = "absolute"; 104 scrollDiv.style.top = "-9999px"; 105 document.body.appendChild(scrollDiv); 106 107 // Get the scrollbar width 108 var scrollbarWidth = scrollDiv.offsetWidth - scrollDiv.clientWidth; 109 110 // Delete the DIV 111 document.body.removeChild(scrollDiv); 112 113 return scrollbarWidth; 114 }; 115 116 117 /** 118 * Returns the inner width of the window, then subtracts vertical 119 * scrollbar width and adds any remaining horizontal scroll. 120 * 121 * @returns width of the page 122 */ 123 this.getPageWidth = function() { 124 var pageWidth = 0; 125 //if ("ontouchstart" in window) { // Mobiles 126 // // FIXME iOS does not flip dimensions when orientation is changed 127 if (window.innerWidth) { 128 if (typeof window.chrome === "object") { // hack for Chrome browser 129 pageWidth = self.outerWidth; 130 } else { 131 pageWidth = window.innerWidth; 132 } 133 } else if (document.documentElement 134 && document.documentElement.clientWidth != 0) { 135 pageWidth = document.documentElement.clientWidth; 136 } else if (document.body) { 137 pageWidth = document.body.clientWidth; 138 } 139 140 // Exclude vertical scrollbar width and add any remaining horizontal scroll 141 if (pageWidth > 0) { 142 pageWidth += this.getRemainingScrollWidth(); 143 // do not add vertical scrollbar width for Firefox??????/ 144 if (this.hasVerticalScrollbar()) { // && !jQuery.browser.mozilla) { 145 pageWidth -= this.getVerticalScrollbarWidth(); 146 } 147 } 148 return pageWidth; 149 }; 150 151 /** 152 * Checks if a vertical scrollbar exists 153 * 154 * @returns true if a vertical scrollbar exists, otherwise, false 155 */ 156 this.hasVerticalScrollbar = function() { 157 // Check if body height is higher than window height 158 if (jQuery(document).height() > jQuery(window).height()) { 159 return true; 160 } 161 return false; 162 }; 163 164 /** 165 * Shows the loading dialog 166 * 167 * @param create the DIV element 168 */ 169 this.showLoadingDialog = function(createDiv) { 170 if (createDiv) { 171 jQuery("<div id='loadingDialog' title=\"Loading...\">" + 172 "<p>Loading heat map...</p>" + 173 "</div>").appendTo("body"); 174 } 175 jQuery("#loadingDialog").dialog( { autoOpen: false }); 176 177 }; 178 179 /** 180 * Closes the loading dialog 181 */ 182 this.closeLoadingDialog = function() { 183 jQuery("#loadingDialog").dialog('close'); 184 }; 185 186};
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.