Created
April 17, 2009 23:37
-
-
Save benjamn/97350 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
if (!window.console || !console.firebug) { | |
var names = ["log", "debug", "info", "warn", "error", "assert", "dir", "dirxml", "group", "groupEnd", "time", "timeEnd", "count", "trace", "profile", "profileEnd"]; | |
window.console = {}; | |
for (var i = 0; i < names.length; ++i) { | |
window.console[names[i]] = function() {} | |
} | |
} | |
function _(C, A) { | |
if (twttr.i18n) { | |
var B = twttr.i18n[C]; | |
if (B) { | |
C = B | |
} | |
} | |
if (A) { | |
for (var D in A) { | |
C = C.replace(new RegExp("\\%\\{" + D + "\\}", "gi"), A[D]) | |
} | |
} | |
return C | |
} | |
function h(A) { | |
return $("<div/>").text(A).html().replace(/\"/gi, """) | |
} | |
var DEBUG = false; | |
$.extend({ | |
log: function(A) { | |
if (window.console) { | |
console.log(A) | |
} | |
}, | |
debug: function(A) { | |
if (DEBUG) { | |
console.log(A) | |
} | |
}, | |
inspect: function(B) { | |
var A = "{\n"; | |
for (var C in B) { | |
A += "\t" + C + ": " + B[C] + "\n" | |
} | |
A += "}"; | |
console.log(A); | |
return A | |
} | |
}); | |
(function() { | |
if (document.all) { | |
if (/MSIE (\d+\.\d+);/.test(navigator.userAgent)) { | |
var A = new Number(RegExp.$1); | |
if (A >= 8) { | |
$.browser.msie8 = true | |
} else { | |
if (A >= 7) { | |
$.browser.msie7 = true | |
} else { | |
$.browser.msie6 = true | |
} | |
} | |
} | |
} | |
})(); | |
$.fn.isSidebarTab = function() { | |
return this.each(function() { | |
var A = $(this); | |
A.click(function() { | |
var B = A.attr("href"); | |
twttr.trackPageView(); | |
$.ajax({ | |
type: "GET", | |
url: B, | |
data: { | |
twttr: true | |
}, | |
dataType: "json", | |
success: function(C) { | |
twttr.processJson(C) | |
}, | |
complete: function() { | |
initializeTimeline(); | |
twttr.loaded() | |
} | |
}); | |
return false | |
}) | |
}) | |
}; | |
$.fn.isDeviceUpdateOption = function() { | |
return this.each(function() { | |
var A = $(this); | |
A.click(function() { | |
$.ajax({ | |
type: "POST", | |
dataType: "json", | |
url: "/account/update_send_via", | |
data: { | |
authenticity_token: twttr.form_authenticity_token, | |
"current_user[send_via]": A.attr("value"), | |
twttr: true | |
} | |
}) | |
}) | |
}) | |
}; | |
$.fn.isUpdateForm = function() { | |
return this.each(function() { | |
var J = $(this); | |
var F = J.find("textarea").isCharCounter(); | |
var A = J.find("input[type=submit]"); | |
var B = J.find("label.doing"); | |
var E = /^\s*@(\w+)\W+/; | |
var D = /^\s*[dD][mM]?\s+(?:(\w+)\W+)?/; | |
function I() { | |
var K = F.val(); | |
if (K.length > 140) { | |
alert(_("That update is over 140 characters!")); | |
return false | |
} else { | |
if (K.replace(/s\*/g, "") == "") { | |
return false | |
} else { | |
A.attr("disabled", "disabled"); | |
return true | |
} | |
} | |
} | |
function G(K) { | |
A.removeAttr("disabled", "disabled"); | |
var L = K.text; | |
if (K.messageForFlash) { (new InfoNotification()).setMessage(K.messageForFlash).show() | |
} else { | |
$("#timeline tr.hentry:first").removeClass("latest-status"); | |
if (K.status_li && $("body").attr("id") == "home") { | |
$.Timeline.prepend(K.status_li) | |
} | |
$("#update_count").fadeOut("medium", | |
function() { | |
$("#update_count").html(K.status_count).fadeIn("medium") | |
}); | |
if (K.latest_status) { | |
$("#latest_status").html(K.latest_status).isCurrentStatus(true) | |
} | |
} | |
if ($("body").attr("id") != "home") { (new ShortNotification()).setMessage(_("Your status has been updated!")).show() | |
} | |
F.val("").focusEnd(); | |
$("#in_reply_to_status_id").val(""); | |
$("#in_reply_to").val(""); | |
C(""); | |
F.trigger("change") | |
} | |
function C(L) { | |
var K; | |
if (K = L.match(D)) { | |
B.html(K[1] ? _("Direct message %{person}:", { | |
person: K[1] | |
}) : _("Direct message:")); | |
A.val(_("send")) | |
} else { | |
if (K = L.match(E)) { | |
B.html(_("Reply to %{screen_name}:", { | |
screen_name: K[1] | |
})); | |
A.val(_("reply")) | |
} else { | |
B.html(_("What are you doing?")); | |
A.val(_("update")) | |
} | |
} | |
} | |
F.bind("keyup blur focus", | |
function() { | |
C($(this).val()) | |
}); | |
J.submit(function() { | |
if (I()) { | |
twttr.googleAnalytics("/status/update/refresh"); | |
var P = F.val(); | |
var O = { | |
authenticity_token: twttr.form_authenticity_token, | |
status: P, | |
twttr: true | |
}; | |
var L = window.location.href; | |
if ($("body").attr("id") == "home" && ((L.indexOf("page=") == -1) || L.match(/page=1(?!\d)/))) { | |
O.return_rendered_status = true | |
} | |
var K = $("#in_reply_to_status_id").val(); | |
var N; | |
if (K && (N = P.match(E))) { | |
if (N[1] == $("#in_reply_to").val()) { | |
O.in_reply_to_status_id = K | |
} | |
} | |
var M = $("#source").val(); | |
if (M) { | |
O.source = M | |
} | |
$.ajax({ | |
type: "POST", | |
dataType: "json", | |
url: "/status/update", | |
data: O, | |
success: G | |
}) | |
} | |
return false | |
}); | |
try { | |
F.focusEnd() | |
} catch(H) {} | |
}) | |
}; | |
$.fn.isDirectMessageForm = function() { | |
return this.each(function() { | |
var K = $(this); | |
var C = K.find("textarea").isCharCounter(); | |
var B = /^\s*[dD][mM]?\s+([A-Za-z0-9]{1,20})[^A-Za-z0-9]/; | |
var E = K.find("select"); | |
var A = K.find("#update-submit"); | |
var F = ""; | |
K.find("input[type=submit]").attr("disabled", "disabled").addClass("disabled"); | |
try { | |
C.focusEnd() | |
} catch(H) {} | |
function D(M) { | |
if (E.val()) { | |
return | |
} | |
if ((matches = M.match(B)) && matches[1] && (F != matches[1])) { | |
var L = true; | |
E.find("option").each(function() { | |
if (this.innerHTML.toLowerCase() == matches[1].toLowerCase()) { | |
E.val(this.value); | |
L = false; | |
return false | |
} | |
}); | |
if (L) { | |
E.append(_('<option value="%{screen_name}">%{screen_name}</option>', { | |
screen_name: matches[1] | |
})); | |
E.val(matches[1]) | |
} | |
F = matches[1] | |
} | |
} | |
A.click(function(L) { | |
var O = C.val(); | |
var M = O.match(B); | |
var N = E.find("option[value=" + E.val() + "]"); | |
if (M && M[1] && M[1].toLowerCase() == N.text().toLowerCase()) { | |
C.val(O.replace(B, "")) | |
} | |
return true | |
}); | |
E.change(function(L) { | |
C.trigger("update", L) | |
}); | |
C.bind("keyup blur focus", | |
function(L) { | |
D($(this).val()); | |
C.trigger("update", L) | |
}); | |
function G(L) { (new ShortNotification()).setMessage(L.messageForFlash).show(); | |
if ($("body").attr("id") == "sent") { | |
$.Timeline.prepend(L.direct_message_li) | |
} | |
C.val(""); | |
E.val(""); | |
F = ""; | |
C.trigger("change") | |
} | |
if (E.length > 0) { | |
function I() { | |
if (E.length && (E.find("option").length == 0)) { | |
$.ajax({ | |
type: "GET", | |
dataType: "json", | |
url: "/direct_messages/recipients_list", | |
data: { | |
twttr: true | |
}, | |
success: function(M) { | |
if (M) { | |
var L = []; | |
$.each(M, | |
function() { | |
var N = this; | |
if ((N.length > 1) && N[0] && N[1]) { | |
L.push('<option value="' + N[0] + '">' + N[1] + "</option>") | |
} | |
}); | |
E.html('<option value="" selected="selected"></option>' + L.join("")) | |
} | |
}, | |
error: function(L) { | |
alert("error: " + L) | |
} | |
}) | |
} | |
} | |
var J = $("body").attr("id"); | |
if (J == "direct_messages" || J == "inbox" || J == "sent") { | |
I() | |
} | |
K.bind("loadrecipients", null, | |
function(L) { | |
I() | |
}); | |
K.submit(function() { | |
twttr.googleAnalytics("/direct_messages/create/refresh"); | |
var M = C.val(); | |
var L = { | |
authenticity_token: twttr.form_authenticity_token, | |
text: M, | |
"user[id]": E.val(), | |
twttr: true | |
}; | |
$.ajax({ | |
type: "POST", | |
dataType: "json", | |
url: "/direct_messages/create", | |
data: L, | |
success: G | |
}); | |
return false | |
}) | |
} | |
}) | |
}; | |
$.fn.isCharCounter = function() { | |
return this.each(function() { | |
var A = true; | |
var F = $(this); | |
var J = F.parents("form"); | |
var E = J.find(".char-counter"); | |
var H = J.find("input[type=submit]"); | |
var D = J.find("select"); | |
function C() { | |
H.attr("disabled", "disabled").addClass("disabled"); | |
A = true | |
} | |
function G() { | |
if (A) { | |
H.removeAttr("disabled").removeClass("disabled"); | |
A = false | |
} | |
} | |
function B() { | |
var L = F.val(); | |
var K = L.length; | |
E.html("" + (140 - K)); | |
if (K <= 0) { | |
E.css("color", "#cccccc"); | |
C() | |
} else { | |
if (K <= 140 && (D.length == 0 || D.val())) { | |
G() | |
} else { | |
C() | |
} | |
if (K > 130) { | |
E.css("color", "#d40d12") | |
} else { | |
if (K > 120) { | |
E.css("color", "#5c0002") | |
} else { | |
E.css("color", "#cccccc") | |
} | |
} | |
} | |
} | |
var I = "blur focus change " + ($.browser.mozilla ? "paste input": "keyup"); | |
F.bind(I, | |
function(K) { | |
B() | |
}); | |
D.change(function(K) { | |
B() | |
}); | |
F.focus() | |
}) | |
}; | |
$.fn.isCurrentStatus = function(A) { | |
return this.each(function() { | |
var F = $(this); | |
var C = F.find("#latest_text"); | |
var E = C.find(".status-text"); | |
var D = $(this).parent("#currently"); | |
var H = D.find("strong"); | |
$("#latest_text_full, #latest_text").click(function() { | |
$("#latest_text_full, #latest_text").toggle() | |
}); | |
var G = E.css("color"); | |
C.css("color", "transparent"); | |
var B = $("#latest_text_full .status-text").text(); | |
twttr.truncateToHeight(B, $("#latest_text .status-text"), $("#latest_text"), 40, { | |
minlength: 60 | |
}); | |
C.css("color", G); | |
if (A) { | |
if (D.css("visibility") == "hidden") { | |
D.css("visibility", "visible") | |
} | |
var I = D.find("span, strong").animate({ | |
color: "#333333" | |
}, | |
500); | |
clearTimeout(twttr.timeouts.latest_status_timeout); | |
twttr.timeouts.latest_status_timeout = setTimeout(function() { | |
I.animate({ | |
color: G | |
}, | |
1500) | |
}, | |
1500) | |
} | |
}) | |
}; | |
$.fn.isNotificationSetting = function() { | |
return this.each(function() { | |
var B = $(this); | |
var A = B.attr("id").replace("notify_on_", "").replace("notify_off_", ""); | |
B.click(function() { | |
var C = B.attr("value"); | |
$.ajax({ | |
type: "POST", | |
dataType: "text", | |
url: "/friends/" + C + "/" + A, | |
data: { | |
authenticity_token: twttr.form_authenticity_token, | |
twttr: true | |
}, | |
success: function(D) { | |
if (D.match(/success/)) { | |
$(".follow-control").trigger("refresh", ["notify_" + (C == "follow" ? "on": "off")]) | |
} else { | |
twttr.error() | |
} | |
} | |
}) | |
}) | |
}) | |
}; | |
$.fn.isNudgable = function() { | |
return this.each(function() { | |
var A = $(this); | |
A.click(function() { | |
var B = A.parents("form"); | |
B.find("input[name=authenticity_token]").val(twttr.form_authenticity_token); | |
B.submit(); | |
return false | |
}) | |
}) | |
}; | |
$.fn.isSelectAll = function(A) { | |
return this.each(function() { | |
var B = $(this); | |
if (typeof(A) == "string") { | |
var D = $(A).find("input[type=checkbox]") | |
} else { | |
var D = A | |
} | |
function C() { | |
var E = true; | |
D.each(function() { | |
if (!this.checked) { | |
E = false; | |
return false | |
} | |
}); | |
B.get(0).checked = E | |
} | |
B.click(function() { | |
var E = B.get(0).checked; | |
D.each(function() { | |
this.checked = E | |
}); | |
$(this).trigger("select-all-changed", E) | |
}); | |
D.click(function() { | |
C(); | |
$(this).trigger("checkbox-changed", this.checked) | |
}) | |
}) | |
}; | |
$.fn.isFollowControl = function() { | |
return this.each(function() { | |
var I = $(this); | |
var H = I.parents(".follow-actions"); | |
var A = I.find(".follow-button"); | |
var B = H.attr("class").split(" ").pop(); | |
var E = H.attr("id").replace("follow_actions_", ""); | |
var C = H.find("#follow-toggle"); | |
var G = H.find(".remove-button"); | |
var D = $("#flash"); | |
H.find(".notify-input").isNotificationSetting(); | |
function F(J) { | |
$.ajax({ | |
type: "GET", | |
dataType: "json", | |
url: "/account/refresh_follow_control/" + E, | |
data: { | |
action_taken: J | |
}, | |
success: function(K) { | |
twttr.processJson(K); | |
$(".follow-control").isFollowControl() | |
} | |
}) | |
} | |
A.click(function() { | |
$.ajax({ | |
type: "POST", | |
dataType: "json", | |
url: "/friendships/create/" + E, | |
data: { | |
authenticity_token: twttr.form_authenticity_token, | |
twttr: true | |
}, | |
success: function(J) { | |
if (J.result == "Bring") { | |
twttr.error() | |
} else { | |
if (J.success) { | |
I.trigger("refresh", ["followed"]) | |
} else { | |
if (J.result != "242") { | |
if (J.notice) { | |
D.html('<div class="content-bubble-arrow"><p class="round">' + J.notice + "</p></div>"); | |
D.fadeIn(200); | |
setTimeout(function() { | |
D.slideUp() | |
}, | |
9000) | |
} else { | |
twttr.error() | |
} | |
} | |
} | |
} | |
}, | |
beforeSend: function() { | |
$("#follow-flash").css("visibility", "hidden"); | |
twttr.loading() | |
}, | |
complete: twttr.loaded | |
}); | |
return false | |
}); | |
I.bind("refresh", | |
function(J, K) { | |
F(K) | |
}); | |
C.click(function() { | |
$("#follow-flash").css("visibility", "hidden"); | |
var J = H.find("#follow-details").toggle(); | |
if (J.css("display") == "block") { | |
C.removeClass("closed").addClass("opened") | |
} else { | |
C.removeClass("opened").addClass("closed") | |
} | |
return false | |
}); | |
G.click(function() { | |
$.ajax({ | |
type: "POST", | |
dataType: "text", | |
url: "/friendships/destroy/" + E, | |
data: { | |
authenticity_token: twttr.form_authenticity_token, | |
twttr: true | |
}, | |
success: function(J) { | |
if (J.match(/success/)) { | |
I.trigger("refresh", ["removed"]) | |
} else { | |
twttr.error() | |
} | |
} | |
}); | |
return false | |
}) | |
}) | |
}; | |
$.fn.isFollowRequestLinks = function() { | |
return this.each(function() { | |
var B = $(this); | |
var D = B.hasClass("ifr-profile"); | |
var F = D ? B.attr("id").replace("ifr_", "") : ""; | |
var A = B.find("#accept_all_requests"); | |
var C = B.find("#deny_all_requests"); | |
function E(G) { | |
var H = { | |
decision: G, | |
authenticity_token: twttr.form_authenticity_token | |
}; | |
if (D) { | |
H.id = F; | |
H.source = "profile" | |
} | |
$.ajax({ | |
type: "POST", | |
url: "/friend_requests/" + (D ? "decision": "all"), | |
dataType: "text", | |
data: H, | |
cache: false, | |
success: function(I) { | |
if (I == "fail") { | |
alert(_("Whoops! Something went wrong. Please refresh the page and try again!")) | |
} else { | |
if (D) { | |
B.fadeOut("medium", | |
function() { | |
B.html(I) | |
}); | |
B.fadeIn("medium") | |
} else { | |
var J = window.location; | |
uri = J.protocol + "//" + J.host + "/"; | |
window.location = uri | |
} | |
} | |
} | |
}) | |
} | |
A.click(function() { | |
E("accept"); | |
return false | |
}); | |
C.click(function() { | |
E("deny"); | |
return false | |
}) | |
}) | |
}; | |
$.fn.isTabMenu = function() { | |
return this.each(function() { | |
var B = $(this); | |
if ($this.id == "networktab") { | |
return true | |
} | |
function A(C) { | |
B.find("li a").each(function() { | |
var E = $(this); | |
var F = E.parent(); | |
var D = ""; | |
if (((D = E.attr("class")) == C) && !F.hasClass("active")) { | |
F.addClass("active"); | |
$("#" + D).show() | |
} else { | |
F.removeClass("active"); | |
$("#" + D).hide() | |
} | |
}) | |
} | |
B.find("li a").each(function() { | |
var C = $(this); | |
C.click(function() { | |
A(C.attr("class")); | |
return false | |
}) | |
}) | |
}) | |
}; | |
$.fn.isLinkMenu = function() { | |
$(this).one("click", B); | |
function B() { | |
var C = $(this); | |
var D = C.siblings(":hidden"); | |
$("body, a").one("click", { | |
link: C, | |
menu: D | |
}, | |
A); | |
D.click(function(E) { | |
E.stopPropagation() | |
}).show(); | |
return false | |
} | |
function A(C) { | |
C.data.menu.hide(); | |
C.data.link.one("click", B); | |
if ($(C.target).attr("id") == C.data.link.attr("id")) { | |
return false | |
} | |
} | |
}; | |
$.fn.focusEnd = function() { | |
return this.each(function() { | |
var A = this; | |
if (A.style.display != "none") { | |
if ($.browser.msie) { | |
A.focus(); | |
var B = A.createTextRange(); | |
B.collapse(false); | |
B.select() | |
} else { | |
A.setSelectionRange(A.value.length, A.value.length); | |
A.focus() | |
} | |
} | |
}) | |
}; | |
(function(A) { | |
A.fn.isPasswordStrengthField = function(B, C) { | |
return this.each(function() { | |
if (!B) { | |
return | |
} | |
if (!C) { | |
C = {} | |
} | |
var I = A(this); | |
var K = A(B); | |
K.append('<span class="pstrength-text"></span>'); | |
var G = K.find(".pstrength-text"); | |
function F(L) { | |
K.children().each(function() { | |
var M = A(this); | |
if (M.hasClass("pstrength-text")) { | |
if (L) { | |
M.show() | |
} else { | |
M.hide() | |
} | |
} else { | |
if (L) { | |
M.hide() | |
} else { | |
M.show() | |
} | |
} | |
}) | |
} | |
function J(L) { | |
var N = 0; | |
var M = C.minlength ? C.minlength: 6; | |
if (L.length < M) { | |
return { | |
score: L.length, | |
message: _("Too short"), | |
className: "password-invalid" | |
} | |
} | |
if (C.username) { | |
var O = (typeof(C.username) == "function") ? C.username() : C.username; | |
if (O && (L.toLowerCase() == O.toLowerCase())) { | |
return { | |
score: 0, | |
message: _("Too obvious"), | |
className: "password-invalid" | |
} | |
} | |
} | |
if (A.inArray(L.toLowerCase(), ["password", "password1", "password12", "password123", "qwerty", "asdfgh", "123456", "abcdef", "abc123", "monkey", "letmein"]) != -1) { | |
return { | |
score: 0, | |
message: _("Too obvious"), | |
className: "password-invalid" | |
} | |
} | |
N += L.length * 4; | |
N += (E(1, L).length - L.length) * 1; | |
N += (E(2, L).length - L.length) * 1; | |
N += (E(3, L).length - L.length) * 1; | |
N += (E(4, L).length - L.length) * 1; | |
if (L.match(/(.*[0-9].*[0-9].*[0-9])/)) { | |
N += 5 | |
} | |
if (L.match(/(.*[!,@,#,$,%,^,&,*,?,_,~].*[!,@,#,$,%,^,&,*,?,_,~])/)) { | |
N += 5 | |
} | |
if (L.match(/([a-z].*[A-Z])|([A-Z].*[a-z])/)) { | |
N += 10 | |
} | |
if (L.match(/([a-zA-Z])/) && L.match(/([0-9])/)) { | |
N += 15 | |
} | |
if (L.match(/([!,@,#,$,%,^,&,*,?,_,~])/) && L.match(/([0-9])/)) { | |
N += 15 | |
} | |
if (L.match(/([!,@,#,$,%,^,&,*,?,_,~])/) && L.match(/([a-zA-Z])/)) { | |
N += 15 | |
} | |
if (L.match(/^\w+$/) || L.match(/^\d+$/)) { | |
N -= 10 | |
} | |
if (N < 0) { | |
N = 0 | |
} | |
if (N > 100) { | |
N = 100 | |
} | |
if (N < 34) { | |
return { | |
score: N, | |
message: _("Weak"), | |
className: "password-weak" | |
} | |
} | |
if (N < 50) { | |
return { | |
score: N, | |
message: _("Good"), | |
className: "password-good" | |
} | |
} | |
if (N < 75) { | |
return { | |
score: N, | |
message: _("Strong"), | |
className: "password-strong" | |
} | |
} | |
return { | |
score: N, | |
message: _("Very Strong"), | |
className: "password-verystrong" | |
} | |
} | |
function E(M, P) { | |
var L = ""; | |
for (var O = 0; O < P.length; O++) { | |
var Q = true; | |
for (var N = 0; N < M && (N + O + M) < P.length; N++) { | |
Q = Q && (P.charAt(N + O) == P.charAt(N + O + M)) | |
} | |
if (N < M) { | |
Q = false | |
} | |
if (Q) { | |
O += M - 1; | |
Q = false | |
} else { | |
L += P.charAt(O) | |
} | |
} | |
return L | |
} | |
function D(L) { | |
if (L && K.hasClass(L)) { | |
return false | |
} | |
K.removeClass("password-weak").removeClass("password-good").removeClass("password-strong").removeClass("password-verystrong").removeClass("password-invalid"); | |
return true | |
} | |
function H() { | |
var M = I.val(); | |
if (M.length == 0) { | |
D(); | |
F(false) | |
} else { | |
if (M.length) { | |
F(true) | |
} | |
} | |
if (M.length > 0) { | |
var L = J(M); | |
G.html(L.message); | |
if (D(L.className)) { | |
K.addClass(L.className) | |
} | |
} | |
} | |
I.bind("show-password-meter", | |
function() { | |
K.show() | |
}); | |
I.bind("hide-password-meter", | |
function() { | |
K.hide() | |
}); | |
I.keyup(function() { | |
H() | |
}); | |
I.blur(function() { | |
if (this.value.length == 0) { | |
D(); | |
I.trigger("hide-password-meter") | |
} | |
}); | |
if (I.val()) { | |
H(); | |
K.show() | |
} | |
}) | |
} | |
})(jQuery); | |
$.fn.focusFirstTextField = function() { | |
return this.find("input[type=text]:visible:enabled:first").focus().length > 0 | |
}, | |
$.fn.focusFirstTextArea = function() { | |
return this.find("textarea:visible:enabled:first").focus().length > 0 | |
}; | |
$.fn.focusFirstTextElement = function() { | |
return this.focusFirstTextField() || this.focusFirstTextArea() | |
}; | |
$.fn.isWrapped = function(B) { | |
if (!B) { | |
return | |
} | |
var F = $(this); | |
F.hide(); | |
var D = F.html(); | |
var G = D.length; | |
var H = ""; | |
var C = F.width(); | |
var A = C / B; | |
var E = G / A; | |
for (var I = 0; I <= A; I += 1) { | |
H += (D.substr(E * I, E) + "\n") | |
} | |
F.html(H).show() | |
}; | |
(function(A) { | |
A.fn.isOAuthApplication = function() { | |
return this.each(function() { | |
var D = A(this); | |
var C = D.attr("id").replace("oauth_application_", ""); | |
var B = D.find(".revoke-access"); | |
B.click(function() { | |
A.ajax({ | |
type: "POST", | |
dataType: "json", | |
url: "/oauth/revoke", | |
data: { | |
authenticity_token: twttr.form_authenticity_token, | |
token: C, | |
twttr: true | |
}, | |
success: function(E) { | |
if (E.revoked) { | |
D.addClass("revoked") | |
} else { | |
D.removeClass("revoked") | |
} | |
B.text(E.label) | |
} | |
}); | |
return false | |
}) | |
}) | |
} | |
})(jQuery); | |
(function(A) { | |
A.fn.isBulletin = function() { | |
return this.each(function() { | |
var B = A(this); | |
var C = B.find("a.close"); | |
C.click(function() { | |
B.fadeOut(); | |
return false | |
}) | |
}) | |
} | |
})(jQuery); | |
(function() { | |
$.fn.isDeviceFailBulletin = function() { | |
return this.each(function() { | |
var A = $(this); | |
var B = A.find("a.hide-fail-notice, a.close"); | |
var C = B.attr("id").replace("hide_device_", ""); | |
B.click(function() { | |
$.ajax({ | |
type: "POST", | |
dataType: "text", | |
url: "/devices/update/" + C, | |
data: { | |
authenticity_token: twttr.form_authenticity_token, | |
"device[fail_alert]": "0", | |
twttr: true | |
}, | |
success: function(D) { | |
if (D.match(/success/)) { | |
A.fadeOut(200) | |
} else { | |
twttr.error() | |
} | |
}, | |
beforeSend: null, | |
complete: null | |
}); | |
return false | |
}) | |
}) | |
} | |
})(); | |
(function() { | |
$.fn.isBouncingEmailBulletin = function() { | |
return this.each(function() { | |
var A = $(this); | |
A.find("a.close").click(function() { | |
$.ajax({ | |
type: "POST", | |
dataType: "text", | |
url: "/bouncers/reset", | |
data: { | |
authenticity_token: twttr.form_authenticity_token, | |
twttr: true | |
}, | |
beforeSend: null, | |
complete: null | |
}); | |
return false | |
}) | |
}) | |
} | |
})(); | |
$.fn.isLoading = function() { | |
$(this).addClass("loading") | |
}; | |
$.fn.isLoaded = function() { | |
$(this).removeClass("loading") | |
}; | |
if (!window.twttr) { | |
var _tmp = {}; | |
var twttr = (function() { | |
var rtn = { | |
timeouts: {}, | |
processJson: function(json) { | |
if (typeof(json) == "object") { | |
var evals = []; | |
$.each(json, | |
function(selector, content) { | |
var c = selector.charAt(0); | |
if (c == "$") { | |
evals.push(content) | |
} else { | |
if (c == "!") { | |
var notification = window[selector.substring(1) + "Notification"]; | |
if (notification) { (new notification()).setMessage(content).show() | |
} | |
} else { | |
var contentPadded = "<div>" + content + "</div>"; | |
var $content = $(selector, $(contentPadded)); | |
if ($content.length == 1) { | |
$(selector).replaceWith($content) | |
} else { | |
$(selector).html(content) | |
} | |
} | |
} | |
}); | |
$.each(evals, | |
function(index, js) { | |
if (js) { | |
eval(js) | |
} | |
}) | |
} | |
}, | |
truncateToHeight: function(txt, $textContainer, $container, height, opts) { | |
if (!opts) { | |
opts = {} | |
} | |
if (!opts.minlength) { | |
opts.minlength = 0 | |
} | |
if (opts.minlength && (txt.length < opts.minlength)) { | |
$textContainer.text(txt); | |
return txt | |
} | |
var curr = txt.substring(0, opts.minlength); | |
for (var i = opts.minlength; i < txt.length; i++) { | |
curr += txt.charAt(i); | |
$textContainer.text(curr + "..."); | |
if (height >= 0 && $container.height() > height) { | |
$textContainer.text(curr = curr.substring(0, curr.length - 1) + "..."); | |
return curr | |
} | |
} | |
$textContainer.text(curr); | |
return curr | |
}, | |
googleAnalytics: function(trackid) { | |
if (window.pageTracker) { | |
window.pageTracker._trackEvent("Ajax", "refresh", trackid, null) | |
} | |
}, | |
trackPageView: function(action, query, suffix) { | |
if (window.pageTracker) { | |
var analyticsAction; | |
if (action) { | |
analyticsAction = action.toString(); | |
if (analyticsAction.indexOf("/timeline/") < 0) { | |
analyticsAction = "/timeline/" + analyticsAction | |
} | |
if (query) { | |
analyticsAction = "/timeline/search/tweets/" + encodeURIComponent(h(page.query)) | |
} | |
if (suffix) { | |
analyticsAction = analyticsAction + suffix | |
} | |
window.pageTracker._trackPageview(analyticsAction) | |
} else { | |
window.pageTracker._trackPageview() | |
} | |
} | |
}, | |
fadeAndReplace: function(selector, content) { | |
$(selector).fadeOut("medium", | |
function() { | |
$(selector).html(content) | |
}); | |
$(selector).fadeIn("medium") | |
}, | |
error: function(msg) { | |
alert(msg ? msg: _("Whoops! Something went wrong. Please refresh the page and try again!")) | |
}, | |
loading: function() { | |
$("#loader").fadeIn(200) | |
}, | |
loaded: function() { | |
$("#loader").fadeOut(200) | |
}, | |
updateLocation: function(href) { | |
document.location.hash = href.replace(/^https?:\/\/.+?\//, "").replace(/#/gi, "%23").replace(/\s/gi, "+") | |
} | |
}; | |
return rtn | |
})() | |
} | |
$.fn.occasionally = function(H, J) { | |
var I = $(this); | |
var F = this; | |
var E = $.extend({ | |
interval: 10000, | |
max: null, | |
maxed: function() {}, | |
decay: 2 | |
}, | |
J); | |
var C = 0; | |
var A; | |
var G = E.decay; | |
var B = E.interval; | |
I.data("continueOccasionally", true); | |
function D() { | |
if (E.max && C > E.max) { | |
clearInterval(A); | |
B = E.interval; | |
E.maxed(F); | |
return | |
} | |
C += 1; | |
if (H(F)) { | |
console.log("not backing off"); | |
B = E.interval | |
} else { | |
console.log("backing off"); | |
B = B * G | |
} | |
if (I.data("continueOccasionally") == false) { | |
clearInterval(A); | |
C = 0; | |
B = E.interval | |
} else { | |
A = setTimeout(function() { | |
D() | |
}, | |
B) | |
} | |
} | |
A = setTimeout(function() { | |
D() | |
}, | |
B); | |
return $(this) | |
}; | |
(function(A) { | |
A.ajaxSetup({ | |
beforeSend: twttr.loading, | |
complete: twttr.loaded | |
}) | |
})(jQuery); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment