addEventListener after change event - javascript

I have a page with one dropdown list and one table. The users choose from the dropdown and dynamically I populate the table from my db.
Example:
<div class="col-xs-12 col-sm-6 col-md-6 col-lg-4">
<label asp-for="CCDescr" class="control-label">Cost Center</label>
<select asp-for="CCCode" class="form-control"
asp-items="#(new SelectList(ViewBag.CostCenterList, "CCCode", "CCDescr"))"></select>
</div>
<div class="tg-wrap" id="table" hidden>
<table class="tg">
<tr>..Headers..</tr>
<tr>..Data..</tr>
<tr>..Data..</tr>
<tr>..Data..</tr>
</table>
</div>
I have written a js script to read my data from the db using the controller. And then I populate my table like
$("#table").empty();
items +=
"<table class='tg'>" +
"<tr>....</tr>" +
"</table>"
$("#table").html(items);
$("#table").show();
I have found a js to short my table and it work for the fist time I load the page, but after the user change the dropdown list and my js run the sort isn't working any more.
The sort function adds a n.addEventListener("DOMContentLoaded", function () { for (var t = n.getElementsByClassName("tg"), e = 0; e < r(t); ++e)try { v(t[e]) } catch (n) { } })
}(document) but I can't make it work after my dropdownlist and table changes.
Thanks in advance for your help.
Regards.
---
For reference I post the hole js for sorting the table (as I said already not my code, something I found online):
<script charset="utf-8">
var TGSort = window.TGSort || function (n) {
"use strict";
function r(n) { return n ? n.length : 0 }
function t(n, t, e, o = 0) { for (e = r(n); o < e; ++o)t(n[o], o) }
function e(n) { return n.split("").reverse().join("") }
function o(n) {
var e = n[0]; return t(n, function (n) {
for (; !n.startsWith(e);)e = e.substring(0, r(e) - 1)
}), r(e)
} function u(n, r, e = []) {
return t(n, function (n) { r(n) && e.push(n) }), e
} var a = parseFloat; function i(n, r) {
return function (t) {
var e = ""; return t.replace(n, function (n, t, o) { return e = t.replace(r, "") + "." + (o || "").substring(1) }), a(e)
}
} var s = i(/^(?:\s*)([+-]?(?:\d+)(?:,\d{3})*)(\.\d*)?$/g, /,/g), c = i(/^(?:\s*)([+-]?(?:\d+)(?:\.\d{3})*)(,\d*)?$/g, /\./g);
function f(n) { var t = a(n); return !isNaN(t) && r("" + t) + 1 >= r(n) ? t : NaN }
function d(n) {
var e = [], o = n; return t([f, s, c], function (u) { var a = [], i = []; t(n, function (n, r) { r = u(n), a.push(r), r || i.push(n) }), r(i) < r(o) && (o = i, e = a) }), r(u(o, function (n) { return n == o[0] })) == r(o) ? e : []
} function v(n) {
if ("TABLE" == n.nodeName) {
for (var a = function (r) {
var e, o, u = [], a = []; return function n(r, e) {
e(r), t(r.childNodes, function (r) { n(r, e) })
}(n, function (n) { "TR" == (o = n.nodeName) ? (e = [], u.push(e), a.push(n)) : "TD" != o && "TH" != o || e.push(n) }), [u, a]
}(), i = a[0], s = a[1], c = r(i), f = c > 1 && r(i[0]) < r(i[1]) ? 1 : 0, v = f + 1, p = i[f], h = r(p), l = [], g = [], N = [], m = v; m < c; ++m) {
for (var T = 0; T < h; ++T) {
r(g) < h && g.push([]); var C = i[m][T], L = C.textContent || C.innerText || ""; g[T].push(L.trim())
} N.push(m - v)
} t(p, function (n, t) {
l[t] = 0; var a = n.classList; a.add("tg-sort-header"), n.addEventListener("click", function () {
var n = l[t]; !function () {
for (var n = 0; n < h; ++n) {
var r = p[n].classList; r.remove("tg-sort-asc"), r.remove("tg-sort-desc"), l[n] = 0
}
}(), (n = 1 == n ? -1 : +!n) && a.add(n > 0 ? "tg-sort-asc" : "tg-sort-desc"), l[t] = n; var i, f = g[t], m = function (r, t) {
return n * f[r].localeCompare(f[t]) || n * (r - t)
}, T = function (n) {
var t = d(n); if (!r(t)) {
var u = o(n), a = o(n.map(e)); t = d(n.map(function (n) { return n.substring(u, r(n) - a) }))
} return t
}(f); (r(T) || r(T = r(u(i = f.map(Date.parse), isNaN)) ? [] : i)) && (m = function (r, t) {
var e = T[r], o = T[t], u = isNaN(e), a = isNaN(o); return u && a ? 0 : u ? -n : a ? n : e > o ? n : e < o ? -n : n * (r - t)
}); var C, L = N.slice(); L.sort(m); for (var E = v; E < c; ++E)(C = s[E].parentNode).removeChild(s[E]); for (E = v; E < c; ++E)C.appendChild(s[v + L[E - v]])
})
})
}
} n.addEventListener("DOMContentLoaded", function () { for (var t = n.getElementsByClassName("tg"), e = 0; e < r(t); ++e)try { v(t[e]) } catch (n) { } })
}(document)
</script>

1) Set a id to the select tag
<label asp-for="CCDescr" class="control-label">Cost Center</label>
<select id="cost" asp-for="CCCode" class="form-control">
<option value="test">Test</option>
</select>
2) Create a new function in TGSort:
function sort() {
for (var t = n.getElementsByClassName("tg"), e = 0; e < r(t); ++e) try {
v(t[e])
} catch (n) {}
}
3) Replace n.addEventListener("DOMContentLoaded",.... ) with:
n.addEventListener("DOMContentLoaded",sort )
document.getElementById("cost").addEventListener('change', sort);

Related

What is nio.js?

I am seeing an unknown script being displayed on all pages hosted on my site. This was not added by me to any of the pages, so i am assuming the hosting company is adding it on the fly when a page is requested.
This is what is added to the the page
<script>
! function(n, e, i, o, t) {
'use strict';
if (!n.nio) {
n.nio = function() {
n.nio.execAction ? n.nio.execAction.apply(window.nio, arguments) : n.nio.queue.push(arguments)
}, n.nio.push = n.nio, n.nio.loaded = !0, n.nio.version = '1.0', n.nio.queue = [];
var s = e.createElement(i);
s.async = !0, s.src = o;
var r = e.getElementsByTagName(i)[0];
r.parentNode.insertBefore(s, r)
}
}(window, document, 'script', '//cdn.narrative.io/js/nio-js/v1.1/nio.js');
nio('init', 9);
</script>
<noscript><img height='1' width='1' style='display:none' src='https://io.narrative.io?noscript=1&id=9'/></noscript>
This is what the nio.js file contains.
! function(t, e, n, r, i) {
"use strict";
var o, a, u = "__nio";
if (!t.nio || 1 !== t.nio.libLoaded) {
var s = function() {
return "//" + r
},
c = function(t) {
var e = typeof t;
return "object" === e && "function" !== e && null !== t
};
o = "undefined" != typeof JSON && null !== JSON && JSON.stringify ? JSON.stringify : function() {
var t = Object.prototype.toString,
e = Array.isArray || function(e) {
return "[object Array]" === t.call(e)
},
n = {
'"': '\\"',
"\\": "\\\\",
"\b": "\\b",
"\f": "\\f",
"\n": "\\n",
"\r": "\\r",
" ": "\\t"
},
r = function(t) {
return n[t] || "\\u" + (t.charCodeAt(0) + 65536).toString(16).substr(1)
},
i = /[\\"\u0000-\u001F\u2028\u2029]/g;
return function o(n) {
if (null == n) return "null";
if ("number" == typeof n) return isFinite(n) ? n.toString() : "null";
if ("boolean" == typeof n) return n.toString();
if ("object" == typeof n) {
if ("function" == typeof n.toJSON) return o(n.toJSON());
if (e(n)) {
for (var a = "[", u = 0; u < n.length; u++) a += (u ? ", " : "") + o(n[u]);
return a + "]"
}
if ("[object Object]" === t.call(n)) {
var s = [];
for (var c in n) n.hasOwnProperty(c) && s.push(o(c) + ": " + o(n[c]));
return "{" + s.join(", ") + "}"
}
}
return '"' + n.toString().replace(i, r) + '"'
}
}();
var f = Object.assign || function(t) {
if (t === i || null === t) throw new TypeError("Cannot convert undefined or null to object");
for (var e = Object(t), n = 1; n < arguments.length; n++) {
var r = arguments[n];
if (r !== i && null !== r)
for (var o in r) r.hasOwnProperty(o) && (e[o] = r[o])
}
return e
},
l = function(t) {
var e, n = [];
for (var r in t) t.hasOwnProperty(r) && (e = c(t[r]) ? o(t[r]) : t[r], n.push(encodeURIComponent(r) + "=" + encodeURIComponent(e)));
return n.join("&")
},
p = "addEventListener" in e,
h = p ? "addEventListener" : "attachEvent",
d = p ? "removeEventListener" : "detachEvent",
m = function(t, e, n) {
e = p ? e : "on" + e;
var r = function(i) {
t[d](e, r, !1), n(i)
};
t[h](e, r, !1)
},
v = {
_isFiring: !1,
numOfRequests: 0,
addQueue: function(t) {
this.queue = this.queue.concat(t)
},
queue: [],
isEmpty: function() {
return 0 === this.queue.length
},
complete: function(t) {
return t || this.queue.shift(), this._isFiring = !1, this._fire()
},
_fire: function() {
if (0 !== this.queue.length) {
var t = this.queue[0],
e = t[0] + "?" + l(t[1]);
return this._isFiring = !0, this.numOfRequests++, e.length > 2048 ? this.fireForm(t[0], t[1]) : this.fireImage(e)
}
},
request: function() {
return this.queue.push(Array.prototype.slice.call(arguments)), this._isFiring ? this._isFiring : this._fire()
},
fireForm: function(t, n) {
var r = this,
i = "nio" + Math.random().toString().replace("0.", ""),
a = e.createElement("form"),
u = e.attachEvent && !e.addEventListener,
s = u ? '<iframe name="' + i + '">' : "iframe",
f = e.createElement(s);
a.method = "post", a.action = t, a.target = i, a.acceptCharset = "utf-8", a.style.display = "none", f.src = "javascript:false", f.id = i, f.name = i, a.appendChild(f), m(f, "load", function() {
var t, i = function(t) {
var e = c(t) ? t.type : null;
return a.parentNode.removeChild(a), r.complete("load" !== e)
};
for (var u in n) n.hasOwnProperty(u) && (t = e.createElement("input"), t.name = u, t.value = c(n[u]) ? o(n[u]) : n[u], a.appendChild(t));
m(f, "load", i), m(f, "error", i), a.submit()
}), e.body.appendChild(a)
},
fireImage: function(t) {
var e = new Image,
n = this,
r = function() {
n.complete()
};
return e.onload = r, e.onerror = r, e.src = t, t
}
},
g = {
companyId: null,
options: {
forceSSL: !1,
forcePost: !1
},
getStandardVars: function() {
return {
companyId: this.companyId,
ret: "img",
ts: (new Date).valueOf()
}
},
errors: [],
error: function(t) {
this.errors.push(t)
},
init: function(t, e) {
this.companyId = t, this.config(e)
},
config: function(t) {
for (var e in t) t.hasOwnProperty(e) && (this.options[e] === i && g.error("Narrative.io: " + e + " is not a valid config option"), this.options[e] = t[e])
},
data: function(t) {
return this.submit(t)
},
submit: function(t) {
var e = s();
e = (this.options.forceSSL ? "https:" : n.protocol) + e;
var r = f({}, this.getStandardVars(), t);
return v.request(e, r)
}
};
t.nio._debug = function() {
return [g, v, a]
}, t.nio.execAction = function(t) {
var e = Array.prototype.slice.call(arguments).slice(1);
switch (t) {
case "init":
return g.init.apply(g, e);
case "data":
return g.data.apply(g, e);
default:
return g.error("Narrative.io: " + t + " is not a valid action")
}
}, t.nio.libLoaded = !0, t.nio.libVersion = "1.0", t.nio.isValid = function() {
return 0 === g.errors.length
};
for (var y = t.nio.queue.slice(), S = 0; S < y.length; S++) t.nio.execAction.apply(t.nio, y[S]);
if (y.length = 0, a = null, t.sessionStorage) {
a = function() {
!v.isEmpty() && c(JSON) && "function" == typeof JSON.parse && t.sessionStorage.setItem(u, o(v.queue))
}, m(t, "beforeunload", a, !1);
var b = t.sessionStorage.getItem(u);
if (null !== b) try {
b = JSON.parse(b), v.addQueue(b)
} catch (O) {
g.error("Narrative.io: " + O.message)
} finally {
t.sessionStorage.removeItem(u)
}
}
setTimeout(function(t, e) {
return function() {
0 === e.numOfRequests && t.execAction("data")
}
}(t.nio, v), 250)
}
}(window, document, location, "io.narrative.io");
I am trying to understand what this script intends to do. Google search did not yield any useful information, and the company hosting the js file does not have much information on it. Hoping to get some javascript expert make sense of this.
This was resolved. The hosting company did some more digging and found out from their development team that this was part of a pilot program to collect some analytics data.

Using Firebug to watch a code

So I'm new to programming and are trying to learn javascript, html and css right now. I'm using Firebug to see code and trying to understand it. Found someones
"Hangman Game" that looks pretty cool to be able to do.
However when I try to see how it's done via Firebug I see "strange characters" which make it difficult to really understand everything. Looks like some things have the same variable even though they are different.
So wondering if it's possible to do anything about this?
The code looks like this
window.Hangman = function () {
'use strict';
var e = {
partAsElement: {
hill: document.getElementById('hang_hill'),
gallow: document.getElementById('hang_construction'),
body: document.getElementById('hang_body'),
rightarm: document.getElementById('hang_rightarm'),
leftarm: document.getElementById('hang_leftarm'),
rightleg: document.getElementById('hang_rightleg'),
leftleg: document.getElementById('hang_leftleg'),
rope: document.getElementById('hang_rope'),
head: document.getElementById('hang_head')
},
validParts: [
'hill',
'gallow',
'rope',
'head',
'body',
'rightarm',
'leftarm',
'rightleg',
'leftleg'
],
ordlista: [
'FANTASY',
'NOTHING',
'INDIGO',
'NATIVE',
'FOREARM',
'NODE',
'EYESOCKET'
],
strecklista: [
],
usedlista: [
],
k: 0,
isValid: function (e) {
return - 1 === this.validParts.indexOf(e) ? (console.log('The part is not valid: ' + e), !1) : (console.log('The part is valid: ' + e), !0)
},
hide: function (e) {
this.isValid(e) && (console.log('Hiding part: ' + e), this.partAsElement[e].style.display = 'none')
},
show: function (e) {
this.isValid(e) && (console.log('Showing part: ' + e), this.partAsElement[e].style.display = 'inline')
},
shuffle: function (e) {
var t,
n,
l;
for (l = e.length; l; l -= 1) t = Math.floor(Math.random() * l),
n = e[l - 1],
e[l - 1] = e[t],
e[t] = n
},
pickWord: function () {
var e;
return this.shuffle(this.ordlista),
e = this.ordlista[0],
console.log(e),
e
},
drawUnderscore: function (e) {
var t,
n,
l;
for (console.log(e), t = document.getElementById('streck'), n = 0; n < e.length; n++) this.strecklista.push('_');
return l = this.strecklista.join(' '),
t.innerHTML = l,
l
},
'klickaVälj': function (n) {
var l,
o,
s,
a,
i,
r;
l = document.getElementsByClassName('bokstav'),
s = document.getElementById('streck'),
a = document.getElementById('used'),
l[n].addEventListener('click', function () {
for (l[n].classList.add('selected'), o = this.innerHTML, i = 0, r = 0, n = 0; n < t.length; n++) t[n] === o ? (console.log(t[n]), e.strecklista[n] = o) : (console.log('bokstaven finns inte på plats ' + n), i++);
for (console.log('j = ' + i), console.log(e.strecklista), n = 0; n < e.strecklista.length; n++) '_' === e.strecklista[n] && (r++, console.log(r));
s.innerHTML = e.strecklista.join(' '),
0 === r && window.alert('You won!'),
console.log(e.k),
i === t.length && (console.log('utför andra if-satsen'), e.usedlista.push(o), console.log('usedlista' + e.usedlista), e.show(e.validParts[e.k]), e.k++, e.k === e.validParts.length && window.alert('You lost!')),
a.innerHTML = e.usedlista
})
},
addClick: function () {
var e;
e = document.getElementsByClassName('bokstav');
for (var t = 0; t < e.length; t++) this.klickaVälj(t)
}
},
t = e.pickWord();
return e.drawUnderscore(t),
console.log(t),
console.log('You can now use the hangman object as a part of the window-object. Try\n\nwindow.Hangman.hide(\'gallow\')\nwindow.Hangman.show(\'gallow\')\n\nHere are all the parts you can work on.'),
console.log(e.validParts),
e
}();
EDIT: https://jsfiddle.net/8c34noqf/ (from what I can see they use 2 js-files and I can only paste one of them). So here's the other one
!function () {
'use strict';
function n() {
for (a = 0; a < i.length; a++) window.Hangman.hide(i[a])
}
var a,
i;
i = window.Hangman.validParts,
n(),
window.Hangman.addClick()
}();

How to add delay to _onFormSubmitCompleted function inside MicrosoftAjaxWebForms

I am trying to modify MicrosoftAjaxWebForms.js file which is default ajax file of asp.net 4.5 and ASP.NET AJAX Control Toolkit version is 16.1.0.0
Here an example project to test out : https://github.com/FurkanGozukara/tempSite/
Open project and go to trialpage.aspx and click that button. You will see the error
Here the full MicrosoftAjaxWebForms.js : http://pastebin.com/pU3rBLKW
It also uses functions from MicrosoftAjax.js if you need that : http://pastebin.com/CPCm9BZy
What I want is, delaying the event _onFormSubmitCompleted
I have tried like below but it doesn't work.
MicrosoftAjaxWebForms.js:914 Uncaught TypeError: this._tempCompleted is not a function
It gives the error above
_onFormSubmitCompleted: function (c) {
console.log("_onFormSubmitCompleted");
setTimeout(function () {
this._tempCompleted(c);
}, 1111);
}, _tempCompleted: function (c) {
console.log("testcompleted");
this._processingRequest = true;
if (c.get_timedOut()) {
this._endPostBack(this._createPageRequestManagerTimeoutError(), c, null);
return
}
if (c.get_aborted()) {
this._endPostBack(null, c, null);
return
}
if (!this._request || c.get_webRequest() !== this._request) return;
if (c.get_statusCode() !== 200) {
this._endPostBack(this._createPageRequestManagerServerError(c.get_statusCode()), c, null);
return
}
var a = this._parseDelta(c);
if (!a) return;
var b, e;
if (a.asyncPostBackControlIDsNode && a.postBackControlIDsNode && a.updatePanelIDsNode && a.panelsToRefreshNode && a.childUpdatePanelIDsNode) {
var r = this._updatePanelIDs,
n = this._updatePanelClientIDs,
i = a.childUpdatePanelIDsNode.content,
p = i.length ? i.split(",") : [],
m = this._splitNodeIntoArray(a.asyncPostBackControlIDsNode),
o = this._splitNodeIntoArray(a.postBackControlIDsNode),
q = this._splitNodeIntoArray(a.updatePanelIDsNode),
g = this._splitNodeIntoArray(a.panelsToRefreshNode),
h = a.version4;
for (b = 0, e = g.length; b < e; b += h ? 2 : 1) {
var j = (h ? g[b + 1] : "") || this._uniqueIDToClientID(g[b]);
if (!document.getElementById(j)) {
this._endPostBack(Error.invalidOperation(String.format(Sys.WebForms.Res.PRM_MissingPanel, j)), c, a);
return
}
}
var f = this._processUpdatePanelArrays(q, m, o, h);
f.oldUpdatePanelIDs = r;
f.oldUpdatePanelClientIDs = n;
f.childUpdatePanelIDs = p;
f.panelsToRefreshIDs = g;
a.updatePanelData = f
}
a.dataItems = {};
var d;
for (b = 0, e = a.dataItemNodes.length; b < e; b++) {
d = a.dataItemNodes[b];
a.dataItems[d.id] = d.content
}
for (b = 0, e = a.dataItemJsonNodes.length; b < e; b++) {
d = a.dataItemJsonNodes[b];
a.dataItems[d.id] = Sys.Serialization.JavaScriptSerializer.deserialize(d.content)
}
var l = this._get_eventHandlerList().getHandler("pageLoading");
if (l) l(this, this._getPageLoadingEventArgs(a));
Sys._ScriptLoader.readLoadedScripts();
Sys.Application.beginCreateComponents();
var k = Sys._ScriptLoader.getInstance();
this._queueScripts(k, a.scriptBlockNodes, true, false);
this._processingRequest = true;
k.loadScripts(0, Function.createDelegate(this, Function.createCallback(this._scriptIncludesLoadComplete, a)), Function.createDelegate(this, Function.createCallback(this._scriptIncludesLoadFailed, a)), null)
},
How should i modify the entire javascript or that function to add a custom delay feature?
So i can delay the client update at the client side as i wish after the postback is completed
Here my bounty having related question : How to defer the update at the client side after async postback in updatepanel

Why doesn't Twitter's follow button widget remember me?

I follow people. I go to check out their sites. Many have a 'follow' button with counter like this one
but if I am I am already following this person the button should be 'grayed' out like this all the time
but once you refresh the page or return at a later time it looks like I am not a follower. Instead, you need to click the 'follow' button on the site, then twitter's dialog box comes up only to tell me that I am already 'following'
and when you mouse over this button it says 'unfollow' in red.
Do does twitter have some sort of Follower.Event.Subscribe function that can recognise people when they are on a site that they 'follow.' If they can recognize follow numbers on a site so why not remember followers?
It come's down Cookies. If the token is not in your browser history how would twitter know that you have clicked it?
What you might find that if you sign into twitter first and then go to the sites and hit refresh it will change to following.
Also if you like me have a tiny Cache for your browser that kills everything on refresh or close then it will definitely not stand a chance at remembering you because your killing the cookie instantly.
UPDATE
It would seem twitter have changed how the use the follow buttons now.
Before if I was logged into twitter and I pressed follow it would just follow them but now I see a gateway popup with a stream etc.
What seems to have happened is Twitter have stopped cookie dropping and opted for a gateway api.
As for the button the key is in the following code:
! function() {
Function && Function.prototype && Function.prototype.bind && (/MSIE [678]/.test(navigator.userAgent) || ! function t(e, n, r) {
function i(s, a) {
if (!n[s]) {
if (!e[s]) {
var u = "function" == typeof require && require;
if (!a && u) return u(s, !0);
if (o) return o(s, !0);
var c = new Error("Cannot find module '" + s + "'");
throw c.code = "MODULE_NOT_FOUND", c
}
var f = n[s] = {
exports: {}
};
e[s][0].call(f.exports, function(t) {
var n = e[s][1][t];
return i(n ? n : t)
}, f, f.exports, t, e, n, r)
}
return n[s].exports
}
for (var o = "function" == typeof require && require, s = 0; s < r.length; s++) i(r[s]);
return i
}({
1: [
function(t, e, n) {
(function() {
"use strict";
function t(t) {
return "function" == typeof t || "object" == typeof t && null !== t
}
function n(t) {
return "function" == typeof t
}
function r(t) {
return "object" == typeof t && null !== t
}
function i() {}
function o() {
return function() {
process.nextTick(c)
}
}
function s() {
var t = 0,
e = new F(c),
n = document.createTextNode("");
return e.observe(n, {
characterData: !0
}),
function() {
n.data = t = ++t % 2
}
}
function a() {
var t = new MessageChannel;
return t.port1.onmessage = c,
function() {
t.port2.postMessage(0)
}
}
function u() {
return function() {
setTimeout(c, 1)
}
}
function c() {
for (var t = 0; U > t; t += 2) {
var e = q[t],
n = q[t + 1];
e(n), q[t] = void 0, q[t + 1] = void 0
}
U = 0
}
function f() {}
function l() {
return new TypeError("You cannot resolve a promise with itself")
}
function d() {
return new TypeError("A promises callback cannot return that same promise.")
}
function h(t) {
try {
return t.then
} catch (e) {
return J.error = e, J
}
}
function p(t, e, n, r) {
try {
t.call(e, n, r)
} catch (i) {
return i
}
}
function m(t, e, n) {
A(function(t) {
var r = !1,
i = p(n, e, function(n) {
r || (r = !0, e !== n ? w(t, n) : _(t, n))
}, function(e) {
r || (r = !0, b(t, e))
}, "Settle: " + (t._label || " unknown promise"));
!r && i && (r = !0, b(t, i))
}, t)
}
function g(t, e) {
e._state === B ? _(t, e._result) : t._state === z ? b(t, e._result) : E(e, void 0, function(e) {
w(t, e)
}, function(e) {
b(t, e)
})
}
function v(t, e) {
if (e.constructor === t.constructor) g(t, e);
else {
var r = h(e);
r === J ? b(t, J.error) : void 0 === r ? _(t, e) : n(r) ? m(t, e, r) : _(t, e)
}
}
function w(e, n) {
e === n ? b(e, l()) : t(n) ? v(e, n) : _(e, n)
}
function y(t) {
t._onerror && t._onerror(t._result), x(t)
}
function _(t, e) {
t._state === H && (t._result = e, t._state = B, 0 === t._subscribers.length || A(x, t))
}
function b(t, e) {
t._state === H && (t._state = z, t._result = e, A(y, t))
}
function E(t, e, n, r) {
var i = t._subscribers,
o = i.length;
t._onerror = null, i[o] = e, i[o + B] = n, i[o + z] = r, 0 === o && t._state && A(x, t)
}
function x(t) {
var e = t._subscribers,
n = t._state;
if (0 !== e.length) {
for (var r, i, o = t._result, s = 0; s < e.length; s += 3) r = e[s], i = e[s + n], r ? O(n, r, i, o) : i(o);
t._subscribers.length = 0
}
}
function T() {
this.error = null
}
function R(t, e) {
try {
return t(e)
} catch (n) {
return W.error = n, W
}
}
function O(t, e, r, i) {
var o, s, a, u, c = n(r);
if (c) {
if (o = R(r, i), o === W ? (u = !0, s = o.error, o = null) : a = !0, e === o) return void b(e, d())
} else o = i, a = !0;
e._state !== H || (c && a ? w(e, o) : u ? b(e, s) : t === B ? _(e, o) : t === z && b(e, o))
}
function N(t, e) {
try {
e(function(e) {
w(t, e)
}, function(e) {
b(t, e)
})
} catch (n) {
b(t, n)
}
}
function C(t, e, n, r) {
this._instanceConstructor = t, this.promise = new t(f, r), this._abortOnReject = n, this._validateInput(e) ? (this._input = e, this.length = e.length, this._remaining = e.length, this._init(), 0 === this.length ? _(this.promise, this._result) : (this.length = this.length || 0, this._enumerate(), 0 === this._remaining && _(this.promise, this._result))) : b(this.promise, this._validationError())
}
function I() {
throw new TypeError("You must pass a resolver function as the first argument to the promise constructor")
}
function P() {
throw new TypeError("Failed to construct 'Promise': Please use the 'new' operator, this object constructor cannot be called as a function.")
}
function S(t) {
this._id = X++, this._state = void 0, this._result = void 0, this._subscribers = [], f !== t && (n(t) || I(), this instanceof S || P(), N(this, t))
}
var j;
j = Array.isArray ? Array.isArray : function(t) {
return "[object Array]" === Object.prototype.toString.call(t)
};
var L, k = j,
U = (Date.now || function() {
return (new Date).getTime()
}, Object.create || function(t) {
if (arguments.length > 1) throw new Error("Second argument not supported");
if ("object" != typeof t) throw new TypeError("Argument must be an object");
return i.prototype = t, new i
}, 0),
A = function(t, e) {
q[U] = t, q[U + 1] = e, U += 2, 2 === U && L()
},
M = "undefined" != typeof window ? window : {},
F = M.MutationObserver || M.WebKitMutationObserver,
D = "undefined" != typeof Uint8ClampedArray && "undefined" != typeof importScripts && "undefined" != typeof MessageChannel,
q = new Array(1e3);
L = "undefined" != typeof process && "[object process]" === {}.toString.call(process) ? o() : F ? s() : D ? a() : u();
var H = void 0,
B = 1,
z = 2,
J = new T,
W = new T;
C.prototype._validateInput = function(t) {
return k(t)
}, C.prototype._validationError = function() {
return new Error("Array Methods must be provided an Array")
}, C.prototype._init = function() {
this._result = new Array(this.length)
};
var K = C;
C.prototype._enumerate = function() {
for (var t = this.length, e = this.promise, n = this._input, r = 0; e._state === H && t > r; r++) this._eachEntry(n[r], r)
}, C.prototype._eachEntry = function(t, e) {
var n = this._instanceConstructor;
r(t) ? t.constructor === n && t._state !== H ? (t._onerror = null, this._settledAt(t._state, e, t._result)) : this._willSettleAt(n.resolve(t), e) : (this._remaining--, this._result[e] = this._makeResult(B, e, t))
}, C.prototype._settledAt = function(t, e, n) {
var r = this.promise;
r._state === H && (this._remaining--, this._abortOnReject && t === z ? b(r, n) : this._result[e] = this._makeResult(t, e, n)), 0 === this._remaining && _(r, this._result)
}, C.prototype._makeResult = function(t, e, n) {
return n
}, C.prototype._willSettleAt = function(t, e) {
var n = this;
E(t, void 0, function(t) {
n._settledAt(B, e, t)
}, function(t) {
n._settledAt(z, e, t)
})
};
var V = function(t, e) {
return new K(this, t, !0, e).promise
},
$ = function(t, e) {
function n(t) {
w(o, t)
}
function r(t) {
b(o, t)
}
var i = this,
o = new i(f, e);
if (!k(t)) return b(o, new TypeError("You must pass an array to race.")), o;
for (var s = t.length, a = 0; o._state === H && s > a; a++) E(i.resolve(t[a]), void 0, n, r);
return o
},
Y = function(t, e) {
var n = this;
if (t && "object" == typeof t && t.constructor === n) return t;
var r = new n(f, e);
return w(r, t), r
},
G = function(t, e) {
var n = this,
r = new n(f, e);
return b(r, t), r
},
X = 0,
Q = S;
S.all = V, S.race = $, S.resolve = Y, S.reject = G, S.prototype = {
constructor: S,
then: function(t, e) {
var n = this,
r = n._state;
if (r === B && !t || r === z && !e) return this;
var i = new this.constructor(f),
o = n._result;
if (r) {
var s = arguments[r - 1];
A(function() {
O(r, i, s, o)
})
} else E(n, i, t, e);
return i
},
"catch": function(t) {
return this.then(null, t)
}
};
var Z = function() {
var t;
t = "undefined" != typeof global ? global : "undefined" != typeof window && window.document ? window : self;
var e = "Promise" in t && "resolve" in t.Promise && "reject" in t.Promise && "all" in t.Promise && "race" in t.Promise && function() {
var e;
return new t.Promise(function(t) {
e = t
}), n(e)
}();
e || (t.Promise = Q)
},
tt = {
Promise: Q,
polyfill: Z
};
"function" == typeof define && define.amd ? define(function() {
return tt
}) : "undefined" != typeof e && e.exports ? e.exports = tt : "undefined" != typeof this && (this.ES6Promise = tt)
}).call(this)
}, {}
],
2: [
function(t, e, n) {
var r = t(3),
i = t(36);
e.exports = function(t, e, n) {
var o, s, a, u, c = i.aug({}, n);
return arguments.length > 1 && "[object Object]" !== String(e) ? ((null === e || void 0 === e) && (c.expires = -1), "number" == typeof c.expires && (o = c.expires, s = new Date((new Date).getTime() + 60 * o * 1e3), c.expires = s), e = String(e), r.cookie = [encodeURIComponent(t), "=", c.raw ? e : encodeURIComponent(e), c.expires ? "; expires=" + c.expires.toUTCString() : "", c.path ? "; path=" + c.path : "", c.domain ? "; domain=" + c.domain : "", c.secure ? "; secure" : ""].join("")) : (c = e || {}, u = c.raw ? function(t) {
return t
} : decodeURIComponent, (a = new RegExp("(?:^|; )" + encodeURIComponent(t) + "=([^;]*)").exec(r.cookie)) ? u(a[1]) : null)
}
}, {
3: 3,
36: 36
}
],
3: [
function(t, e, n) {
e.exports = document
}, {}
],
4: [
function(t, e, n) {
e.exports = location
}, {}
],
5: [
function(t, e, n) {
e.exports = navigator
}, {}
],
6: [
function(t, e, n) {
e.exports = window
}, {}
],
7: [
function(t, e, n) {
function r(t) {
return a.isType("string", t) ? t.split(".") : a.isType("array", t) ? t : []
}
function i(t, e) {
var n = r(e),
i = n.slice(0, -1);
return i.reduce(function(t, e, n) {
if (t[e] = t[e] || {}, !a.isObject(t[e])) throw new Error(i.slice(0, n + 1).join(".") + " is already defined with a value.");
return t[e]
}, t)
}
function o(t, e) {
e = e || s, e[t] = e[t] || {}, Object.defineProperty(this, "base", {
value: e[t]
}), Object.defineProperty(this, "name", {
value: t
})
}
var s = t(6),
a = t(36);
a.aug(o.prototype, {
get: function(t) {
var e = r(t);
return e.reduce(function(t, e) {
return a.isObject(t) ? t[e] : void 0
}, this.base)
},
set: function(t, e, n) {
var o = r(t),
s = i(this.base, t),
a = o.slice(-1);
return n && a in s ? s[a] : s[a] = e
},
init: function(t, e) {
return this.set(t, e, !0)
},
unset: function(t) {
var e = r(t),
n = this.get(e.slice(0, -1));
n && delete n[e.slice(-1)]
},
aug: function(t) {
var e = this.get(t),
n = a.toRealArray(arguments).slice(1);
if (e = "undefined" != typeof e ? e : {}, n.unshift(e), !n.every(a.isObject)) throw new Error("Cannot augment non-object.");
return this.set(t, a.aug.apply(null, n))
},
call: function(t) {
var e = this.get(t),
n = a.toRealArray(arguments).slice(1);
if (!a.isType("function", e)) throw new Error("Function " + t + "does not exist.");
return e.apply(null, n)
},
fullPath: function(t) {
var e = r(t);
return e.unshift(this.name), e.join(".")
}
}), e.exports = o
}, {
36: 36,
6: 6
}
],
8: [
function(t, e, n) {
function r(t) {
var e, n, r, i = 0;
for (o = {}, t = t || s, e = t.getElementsByTagName("meta"); n = e[i]; i++) /^twitter:/.test(n.name) && (r = n.name.replace(/^twitter:/, ""), o[r] = n.content)
}
function i(t) {
return o[t]
}
var o, s = t(3);
r(), e.exports = {
init: r,
val: i
}
}, {
3: 3
}
],
9: [
function(t, e, n) {
var r = t(7);
e.exports = new r("__twttr")
}, {
7: 7
}
],
10: [
function(t, e, n) {
e.exports = ["hi", "zh-cn", "fr", "zh-tw", "msa", "fil", "fi", "sv", "pl", "ja", "ko", "de", "it", "pt", "es", "ru", "id", "tr", "da", "no", "nl", "hu", "fa", "ar", "ur", "he", "th", "cs", "uk", "vi", "ro", "bn"]
}, {}
],
11: [
function(t, e, n) {
function r(t) {
if (t && /^[\w_]{1,20}$/.test(t)) return t;
throw new Error("Invalid screen name")
}
function i(t, e) {
t.className += " " + e
}
function o(t) {
return t && "false" === t.toLowerCase()
}
function s(t) {
return st.getElementById(t)
}
function a(t) {
return t = t || A.event, t && t.preventDefault ? t.preventDefault() : t.returnValue = !1, t && t.stopPropagation ? t.stopPropagation() : t.cancelBubble = !0, !1
}
function u(t) {
var e = R && R.name ? R.name + " (#" + ut + ")" : "#" + ut;
return E ? void(C.title = _("View your profile on Twitter")) : t ? (i(O, "following"), void(C.title = _("You are following %{name} on Twitter", {
name: e
}))) : (O.className = O.className.replace(/ ?following/, ""), void(C.title = _("Fol…
What seem's to be going on here is a handshake with twitters secure server.
So that your information is encrypted.
and all that's happening if the handshake is initiated is that JS is graying out the button.
At no point is this api interacting with the website directly hence why you are not seeing a grayed out button when you are revisiting the site.
It's actually a good think it means that twitter is protecting your privacy as a user.
It also shows that twitter have decided to go down the do not track route for website's so they aren't scoping out a lot of user info.
Sorry about the wait on my answer and the lengthy comment's this must of only happened in recent month's because my last experience with Twitter buttons they had cookie drop's and didnt gateway you like it does now.

override javascript function local variable

There is an external function GoSearch which is exist in a javascript file search.js
How to override the private/local variable (b) of GoSearch function.
Example modify the variable b="?" to b="?cs=This Site&u=http://google.com"
GoSearch(q, G, p, E, r, F, D, C, B, j, n, z, y, x, w, A, l, v) {
ULShpi: ;
try {
AddSearchoptionsToQuery()
} catch (H) {}
var i = document.forms[0].elements[G].value;
i = i.replace(/\s*$/, "");
var u = "1";
if (q) u = document.forms[0].elements[q].Value;
if (i == "" || u == "0") {
alert(v);
if (null != event) {
event.returnValue = false;
return false
} else return
}
var b = "?";
if (suggestedQuery) b += "sq=1&";
b += "k=" + encodeURIComponent(i);
for (var k = ["rm", "rm1", "rm2", "rm3", "rm4", "rm5", "ql", "ql1", "ql2", "ql3", "ql4", "ql5", "v", "v1", "v2", "v3", "v4", "v5", "hs", "hs1", "hs2", "hs3", "hs4", "hs5"], h = 0; h < k.length; h++) {
var m = GetUrlKeyValue(k[h], true);
if (m && m.length > 0) b += "&" + k[h] + "=" + m
}
if (l != null && l != "") b += "&r=" + encodeURIComponent(l);
if (null != p) {
var t = document.forms[0].elements[p].value;
if (E) b += canonicalizedUtf8FromUnicode(" " + t);
else b += "&a=" + canonicalizedUtf8FromUnicode(" " + t)
}
var a = null,
c = "",
d = "",
o = null != j;
if (o) {
c = j;
d = j
} else if (r) {
a = document.forms[0].elements[F];
c = a.options[a.selectedIndex].getAttribute("scope");
d = a.options[a.selectedIndex].value
}
if (r || o) {
var f = "",
g = "",
e = false;
if (d == z) {
f = d;
c = "";
g = document.forms[0].elements[D].value;
e = true
}
if (d == y) {
f = d;
c = "";
g = document.forms[0].elements[C].value;
e = true
}
if (d == x) {
f = c;
c = "";
g = document.forms[0].elements[B].value;
e = true
}
if (c == w) {
c = a.options[a.selectedIndex].value;
e = true
}
if (e) n = A;
if (c != "") {
b += "&s=" + encodeURIComponent(c);
if (a.options[a.selectedIndex].value != "" && !e) n = a.options[a.selectedIndex].value
}
if (f != "") b += "&cs=" + encodeURIComponent(f);
if (g != "") b += "&u=" + encodeURIComponent(g)
}
var I = document.forms[0];
try {
external.AutoCompleteSaveForm(I)
} catch (s) {}
window.location = n + b;
try {
if (null != event) event.returnValue = false
} catch (s) {}
return
}
You can replace the GoSearch function with your own just on the page with the Search Box - by a delegate control.
Create a user control (ASCX) that puts JavaScript code on the page with the modified GoSearch function. Create a SP solution with a feature that will place the control to AdditionalPageHead - to every page head on the site or site collection where you activate the feature.
Check out how the search.js gets loaded on your page. If it is done not directly in the page head but delayed, you'd have to perform the GoSearch replacement dynamically after the search.js is loaded:
function ReplaceGoSearch {
GoSearch = function(...) {
...
};
}
ExecuteOrDelayUntilScriptLoaded(ReplaceGoSearch, "search.js");
--- Ferda
The fastest way that you can do this, is don't link to the external file directly. Download your version of the file, change what you need, and then serve that to your pages.
You can even go so far to download the file on the fly to your server, modify it, and push it out to the requesting page.

Categories

Resources