123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101 |
- /**
- * WARNING!!!
- *
- * The below code is tricky and hacky. It is meant as a temporary solution
- * to block outgoing links within HTML5 games. It is strongly adviced to not
- * use this script, unless you know exactly what you are doing.
- */
- (function (w, d) {
- 'use strict';
- var blockList = [508], // site IDs for which you'd like to block the outgoing links
- addEventListener = (function () {
- var overwrite;
- if (w.addEventListener) {
- overwrite = function (type, listener, element) {
- element.addEventListener(type, listener, false);
- };
- } else if (w.attachEvent) {
- overwrite = function (type, listener, element) {
- element.attachEvent('on' + type, listener);
- };
- }
- return overwrite;
- }()),
- preventDefault = function (e) {
- if (e.preventDefault) {
- e.preventDefault();
- }
- if (e.stopImmediatePropagation) {
- e.stopImmediatePropagation();
- }
- if (e.stopPropagation) {
- e.stopPropagation();
- }
- if (e.stop) {
- e.stop();
- }
- e.returnValue = false;
- return false;
- },
- blockOutgoingLinks = function () {
- var nativeFunctions = {
- 'createElement': d.createElement,
- 'open': w.open
- };
- /**
- * Overwrite the native functions so we can intercept the calls to them
- */
- // func signature: window.open(strUrl, strWindowName[, strWindowFeatures]);
- d.createElement = function (tagName) {
- var elementFromMemory = nativeFunctions.createElement.apply(this, arguments);
- if (tagName && 'a' === tagName) {
- addEventListener('click', function (e) {
- preventDefault(e);
- }, elementFromMemory);
- }
- return elementFromMemory;
- };
- // func signature: window.open(strUrl, strWindowName[, strWindowFeatures]);
- w.open = function () {
- // just don't do anything
- };
- },
- getUrlParam = function(paramName) {
- var keyvaluePairs = w.location.href.slice(w.location.href.indexOf('?') + 1).split('&'),
- pairsCount = keyvaluePairs.length,
- keyvalueArray,
- value,
- key,
- i;
- for (i = 0; i < pairsCount; i += 1) {
- keyvalueArray = keyvaluePairs[i].split('=');
- key = keyvalueArray[0];
- value = keyvalueArray[1];
- if (key === paramName) {
- return decodeURIComponent(value);
- }
- }
- return null;
- },
- indexOf = [].indexOf||(function(a,b,c){for(c=this.length,b=(c+~~b)%c;b<c&&(!(b in this)||this[b]!==a);b++);return b^c?b:-1;}), //polyfill
- siteId = parseInt(getUrlParam('siteid'), 10);
- // check if we should block the outgoing links based on the site ID query string parameter
- if (siteId && indexOf.call(blockList, siteId) > -1) {
- blockOutgoingLinks();
- }
- }(window, window.document));
|