Created
February 7, 2013 01:43
-
-
Save nanha/4727678 to your computer and use it in GitHub Desktop.
Twitter Archive 페이지에서 핵심인 application.min.js
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
var Grailbird = function (b, a, c) { | |
Grailbird.data = Grailbird.data || {}; | |
Grailbird.data[b + "_" + a] = c | |
}; | |
(function (b) { | |
var f = {}, e = {}, a = {}; | |
var c = { | |
empty_month: Hogan.compile('<li class="without-tweets" title="" rel="tooltip" data-placement="bottom" data-date="" data-count="0"><span class="value">{{this_month}}</span></li>'), | |
month_bar: Hogan.compile('<li><a href="#" class="with-tweets" title="{{str_title}}: {{str_count}}" rel="tooltip" data-placement="bottom" data-idx="{{data_idx}}" data-date="{{str_title}}" data-count="{{this_count}}"><span class="bar" style="height: {{this_height}}%;"></span><span class="value">{{this_month}}</span></a></li>'), | |
header_str: Hogan.compile('{{title_str}} <span class="count">{{count}} {{content_type}}</span>'), | |
user_header: Hogan.compile('<li><h1 class="brand">@{{screen_name}}</h1></li>'), | |
user_nav: Hogan.compile('<a href="#" class="icon-sprite icon-user dropdown-toggle" data-toggle="dropdown"></a><ul class="dropdown-menu"><li><a href="#user-info" data-toggle="modal"><i class="icon-user"></i>View account details</a></li><li class="divider"></li><li><a href="https://twitter.com/{{screen_name}}" target="_blank"><i class="icon-share-alt"></i>View profile on Twitter</a></li></ul>'), | |
modal_header: Hogan.compile('<h3>Account details <span class="download-date muted">as of {{created_at_relative}}</span></h3>'), | |
modal_user_details: Hogan.compile('<h3>{{full_name}}</h3><h4 class="muted">@{{screen_name}}</h4><div class="stats muted">{{#bio}}<p>{{bio}}</p>{{/bio}}<p>{{#location}}<a href="https://maps.google.com/?q={{location}}">{{location}}</a>{{/location}}{{#url}}{{#location}} · {{/location}}<a href="{{url}}" title="{{#expanded_url}}{{expanded_url}}{{/expanded_url}}{{^expanded_url}}{{url}}{{/expanded_url}}">{{#display_url}}{{display_url}}{{/display_url}}{{^display_url}}{{url}}{{/display_url}}</a>{{/url}}</p></div>'), | |
modal_payload_details: Hogan.compile('<p>{{tweets}} <span class="footer-label muted">Tweets</span></p>'), | |
modal_account_details: Hogan.compile('<p>#{{id}} <span class="footer-label muted">User ID</span></p><p class="truncated">{{created_at_relative}} <span class="footer-label muted">Joined</span></p>'), | |
nav_tab: Hogan.compile('<li class="{{sectionClass}}"><a href="#">{{sectionName}}</a></li>') | |
}; | |
b.init = function () { | |
var g = $(document), | |
h = $(".tweets-header"); | |
twt.settings.showLocalTimes = true; | |
twt.settings.product = "archive"; | |
Grailbird.data = Grailbird.data || {}; | |
Grailbird.current_index = 0; | |
f = Grailbird.user(); | |
f.init(); | |
e = Grailbird.tweets(); | |
f.setState(e); | |
e.init(); | |
$(".brand").click(function (i) { | |
i.preventDefault(); | |
i.stopImmediatePropagation(); | |
$(".row .contents, .sidebar").removeClass("container-messages"); | |
$(".tweets-header .nav-clear").hide(); | |
$(".container").removeClass("searching"); | |
f.setState(e); | |
e.init() | |
}); | |
$(".tweets-header .nav-arrow").tooltip().click(function () { | |
e.displayTweets(Number($(this).attr("data-idx"))); | |
$(this).tooltip("show") | |
}); | |
$(".navbar-search").submit(function (l) { | |
l.preventDefault(); | |
var k = /^\s+|\s+$/g, | |
i = $(this).find(".search-query").val(), | |
j = i.replace(k, ""); | |
if (!Grailbird.isValidSearchStr(j)) { | |
$(".navbar-search").trigger("invalidSearch"); | |
return | |
} | |
$(".navbar-search").trigger("dismissTooltip"); | |
$(".nav-arrow-left, .nav-arrow-right").tooltip("hide").hide(); | |
$(".container .tweets").fadeOut(0, function () { | |
$(".months .with-tweets, .histogram").removeClass("active"); | |
$(".container").addClass("searching in-progress"); | |
$(".tweets-header-title").empty().text("Searching for ‘" + i + "’ …"); | |
$(this).empty(); | |
$(this).fadeIn(100); | |
f.search(i) | |
}) | |
}).tooltip().bind("dismissTooltip", function (i) { | |
i.preventDefault(); | |
$(this).tooltip("hide") | |
}).bind("invalidSearch", function (i) { | |
i.preventDefault(); | |
$(this).attr("data-original-title", "Your query must be at least two characters.").tooltip("show") | |
}); | |
$(".navbar-search .search-query").blur(function (i) { | |
$(".navbar-search").trigger("dismissTooltip") | |
}); | |
$(".sidebar-nav .search-mask, .tweets-header .nav-clear").tooltip().click(jQuery.proxy(function (i) { | |
i.preventDefault(); | |
f.getState().resetSearch() | |
}, Grailbird)); | |
$(".icon-compose").tooltip(); | |
$(".icon-compose a").click(function (i) { | |
i.preventDefault(); | |
twt.popup($(this).attr("href")) | |
}); | |
$(document).keyup(function (i) { | |
if ($(".container.searching").length === 0) { | |
if (i.keyCode === 37) { | |
i.preventDefault(); | |
$(".nav-arrow-left:visible").click(); | |
$(".nav-arrow-right").tooltip("hide") | |
} | |
if (i.keyCode === 39) { | |
i.preventDefault(); | |
$(".nav-arrow-right:visible").click(); | |
$(".nav-arrow-left").tooltip("hide") | |
} | |
} else { | |
if (i.keyCode === 27) { | |
$(".tweets-header .nav-clear:visible").click() | |
} | |
} | |
if (i.keyCode === 191) { | |
$(".navbar-search .search-query:not(:focus)").focus().select() | |
} | |
}); | |
$(window).scroll(function () { | |
var i = g.scrollTop(); | |
if (i > 0) { | |
h.addClass("raised") | |
} else { | |
h.removeClass("raised") | |
} | |
}) | |
}; | |
b.extend = function (m) { | |
var h = Array.prototype.slice.call(arguments, 1), | |
j = 0, | |
g = h.length, | |
n, k; | |
for (j; j < g; j++) { | |
k = h[j]; | |
for (n in k) { | |
if (k[n] !== undefined) { | |
m[n] = k[n] | |
} | |
} | |
} | |
return m | |
}; | |
(function (g) { | |
g.base = { | |
init: function () { | |
$(".navbar-search .search-query").attr("placeholder", this.search_placeholder); | |
this.buildNavigation(); | |
this.displayTweets(0) | |
}, | |
buildNavigation: function () { | |
var k = ["January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"], | |
s = this, | |
h = $('<div class="histogram"><h3></h3><ol class="months unstyled"></ol></div>'), | |
l, n = [], | |
p; | |
$(".content-nav").empty(); | |
var m = _.max(this.status_index, function (i) { | |
return i.tweet_count | |
}), | |
j = function () { | |
if (l) { | |
n = n.reverse(); | |
if (n.length < 12) { | |
for (var i = 0; i < 12; i++) { | |
if (!n[i] || n[i].match(/class="value">(\d+)<\/span>/)[1] != i + 1) { | |
n.splice(i, 0, c.empty_month.render({ | |
this_month: i + 1 | |
})) | |
} | |
} | |
} | |
l.find(".months").append(n.join("")) | |
} | |
}; | |
for (var o = 0; o < this.status_index.length; o++) { | |
var q = k[this.status_index[o]["month"] - 1] + " " + this.status_index[o]["year"], | |
r = { | |
this_year: this.status_index[o]["year"], | |
this_month: this.status_index[o]["month"], | |
this_count: Grailbird.insertCommas(this.status_index[o]["tweet_count"]), | |
this_height: (this.status_index[o]["tweet_count"] / m.tweet_count) * 100, | |
str_title: q, | |
str_count: Grailbird.insertCommas(this.status_index[o]["tweet_count"]) + " " + this.pluralize(this.status_index[o]["tweet_count"]), | |
data_idx: o | |
}; | |
this.status_index[o]["title_str"] = q; | |
if (this.status_index[o]["year"] !== p) { | |
j(); | |
l = h.clone(); | |
n = []; | |
l.find("h3").text(r.this_year); | |
$(".content-nav").append(l); | |
p = r.this_year | |
} | |
n.push(c.month_bar.render(r)) | |
} | |
j(); | |
$(".months .with-tweets").tooltip().click(function () { | |
s.displayTweets(Number($(this).attr("data-idx"))) | |
}) | |
}, | |
displayTweets: function (i) { | |
Grailbird.current_index = i; | |
var k = { | |
border: false, | |
showMedia: true, | |
popupWebIntents: true | |
}; | |
var o = this, | |
n = 0, | |
p = 0, | |
m = this.status_index[i], | |
h = m.var_name, | |
l = c.header_str.render({ | |
title_str: m.title_str, | |
count: Grailbird.insertCommas(m.tweet_count), | |
content_type: this.pluralize(m.tweet_count) | |
}), | |
j = function () { | |
$(".tweets-header-title").fadeOut(100); | |
$(".container .contents .tweets").fadeOut(100, function () { | |
$(".tweets-header-title").empty().html(l).attr("title", ""); | |
$(this).empty(); | |
$(window).scrollTop(0); | |
$(".navbar-search .search-query").val(""); | |
twt.timeline(Grailbird.data[h], k).renderTo(".tweets"); | |
$(".tweets-header-title").fadeIn(100); | |
$(this).fadeIn(100) | |
}) | |
}; | |
if (this.status_index[i].year === undefined) { | |
$(".user-list .user").removeClass("active"); | |
$($(".user-list .user")[i]).addClass("active"); | |
k.showActions = false | |
} else { | |
$(".months .with-tweets, .histogram").removeClass("active"); | |
$('.months .with-tweets[data-idx="' + i + '"]').addClass("active").parents(".histogram").addClass("active") | |
} | |
n = Number(i) + 1; | |
p = Number(i) - 1; | |
if (i === 0) { | |
p = null; | |
$(".tweets-header .nav-arrow-right").hide() | |
} | |
if (this.status_index.length - 1 == i) { | |
n = null; | |
$(".tweets-header .nav-arrow-left").hide() | |
} | |
if (i < this.status_index.length - 1) { | |
$(".tweets-header .nav-arrow-left").attr({ | |
"data-idx": n, | |
"data-original-title": this.status_index[n]["title_str"] | |
}).show() | |
} | |
if (i > 0) { | |
$(".tweets-header .nav-arrow-right").attr({ | |
"data-idx": p, | |
"data-original-title": this.status_index[p]["title_str"] | |
}).show() | |
} | |
if (!Grailbird.data[h]) { | |
Grailbird.loadScript(m, j) | |
} else { | |
j() | |
} | |
}, | |
pluralize: function (h) { | |
return (Number(h) === 1) ? this.str_singular : this.str_plural | |
}, | |
search: function (r) { | |
var m = this.status_index, | |
n = this.status_index.length, | |
p, s = [], | |
q = new RegExp(r, "im"), | |
i = h(r), | |
l = new RegExp(i, "im"), | |
o = 0; | |
while (n--) { | |
p = m[n]; | |
if (!Grailbird.data[p.var_name]) { | |
Grailbird.loadScript(p, (function (t) { | |
return function () { | |
j(t.var_name) | |
} | |
})(p)) | |
} else { | |
window.setTimeout((function (t) { | |
return function () { | |
j(t.var_name) | |
} | |
})(p), 1) | |
} | |
} | |
function h(t) { | |
return t.replace(/[-[\]{}()*+?.,\\^$|#\s]/g, "\\$&") | |
} | |
function j(u) { | |
var t = _.filter(Grailbird.data[u], function (w) { | |
var v = false; | |
if ( !! w.text.match(q)) { | |
v = true | |
} else { | |
if ( !! (w.user && (w.user.screen_name.match(q) || ("@" + w.user.screen_name).match(q) || w.user.name.match(q)))) { | |
v = true | |
} else { | |
if ( !! (w.entities)) { | |
_.each(w.entities.urls || [], function (x) { | |
if ((x.display_url && x.display_url.match(l)) || (x.expanded_url && x.expanded_url.match(l))) { | |
v = true; | |
return | |
} | |
}); | |
_.each(w.entities.media || [], function (x) { | |
if ((x.display_url && x.display_url.match(l)) || (x.expanded_url && x.expanded_url.match(l))) { | |
v = true; | |
return | |
} | |
}) | |
} else { | |
if ( !! (w.retweeted_status && (w.retweeted_status.text.match(q)))) { | |
v = true | |
} else { | |
if ( !! (w.retweeted_status && (w.retweeted_status.user && w.retweeted_status.user.name.match(q)))) { | |
v = true | |
} else { | |
if ( !! (w.retweeted_status && (w.retweeted_status.user && w.retweeted_status.user.screen_name.match(q)))) { | |
v = true | |
} else { | |
if ( !! (w.retweeted_status && (w.retweeted_status_user && ("@" + w.retweeted_status.user.screen_name).match(q)))) { | |
v = true | |
} | |
} | |
} | |
} | |
} | |
} | |
} | |
return v | |
}); | |
_.each(t, function (v) { | |
s.push(v) | |
}); | |
k() | |
} | |
function k() { | |
o++; | |
if (o == m.length) { | |
var t = _.sortBy(s, function (w) { | |
return Date.parse(w.created_at) * -1 | |
}), | |
v = [s.length], | |
u; | |
v.push((s.length === 1) ? " result matches " : " results match "); | |
v.push("‘" + r + "’"); | |
u = v.join(""); | |
$(".container .tweets").fadeOut(100, function () { | |
$(".container").addClass("searching").removeClass("in-progress"); | |
$(".tweets-header-title").empty().text(u).attr("title", u); | |
$(this).empty(); | |
twt.timeline(t, { | |
border: false, | |
showMedia: true, | |
popupWebIntents: false | |
}).renderTo(".tweets"); | |
_.each($(".e-content .p-name, .h-card .screen-name"), function (w) { | |
_.each($(w).find("*").andSelf(), function (x) { | |
$(x).highlight(r, "found") | |
}) | |
}); | |
$(this).fadeIn(100) | |
}) | |
} | |
} | |
}, | |
resetSearch: function () { | |
$(".container").removeClass("searching"); | |
e.displayTweets(Grailbird.current_index) | |
} | |
} | |
})(a); | |
(function (g) { | |
var h = function () { | |
this.str_singular = "Tweet"; | |
this.str_plural = "Tweets"; | |
this.search_placeholder = "Search all Tweets"; | |
this.status_index = tweet_index | |
}; | |
h.prototype = Grailbird.extend({}, a.base); | |
g.tweets = function () { | |
return new h() | |
} | |
})(Grailbird); | |
(function (g) { | |
var h = function () { | |
var i | |
}; | |
h.prototype.init = function () { | |
user_details.created_at_relative = twt.formattedDate(user_details.created_at); | |
payload_details.created_at_relative = twt.formattedDate(payload_details.created_at); | |
user_details.id = Grailbird.insertCommas(user_details.id); | |
payload_details.tweets = Grailbird.insertCommas(payload_details.tweets); | |
$("#primary-nav").append(c.user_header.render(user_details)); | |
$("#util-nav .dropdown").append(c.user_nav.render(user_details)); | |
$(".modal-header").append(c.modal_header.render(payload_details)); | |
$(".modal-body .user-details").append(c.modal_user_details.render(user_details)); | |
$(".modal-footer .stats").append(c.modal_payload_details.render(payload_details)).append(c.modal_account_details.render(user_details)) | |
}; | |
h.prototype.setState = function (i) { | |
this.active_display = i | |
}; | |
h.prototype.getState = function () { | |
return this.active_display | |
}; | |
h.prototype.search = function (i) { | |
this.active_display.search(i) | |
}; | |
g.user = function () { | |
return new h() | |
} | |
})(Grailbird); | |
b.createNavTab = function (i, h) { | |
var g = "nav-" + i.toLowerCase(); | |
$("#primary-nav").append(c.nav_tab.render({ | |
sectionClass: g, | |
sectionName: i | |
})); | |
$sectionTab = $("." + g); | |
$sectionTab.click(function (j) { | |
$(this).addClass("active").siblings().removeClass("active"); | |
$(".row .contents, .sidebar").removeClass("container-messages"); | |
f.setState(h); | |
h.init() | |
}); | |
return $sectionTab | |
}; | |
b.isValidSearchStr = function (g) { | |
return g.length > 1 | |
}; | |
b.loadScript = function (i, k) { | |
var j = i.file_name, | |
h = document.createElement("script"), | |
g = function () { | |
i.loaded = true; | |
k && k() | |
}; | |
h.src = j; | |
h.charset = "utf-8"; | |
h.onreadystatechange = function () { | |
if (this.readyState == "complete" || this.readyState == "loaded") { | |
g() | |
} | |
}; | |
h.onload = g; | |
document.getElementsByTagName("head")[0].appendChild(h) | |
}; | |
b.insertCommas = function d(g) { | |
g = g.toString(); | |
return (g.length > 3) ? self.Grailbird.insertCommas(g.substr(0, g.length - 3)) + "," + g.substr(g.length - 3) : g | |
} | |
})(Grailbird); | |
jQuery.fn.highlight = function (d, c) { | |
var b = new RegExp(d, "gi"), | |
a = Hogan.compile('<span class="{{class_name}}">{{{match}}}</span>'); | |
return this.each(function () { | |
$(this).contents().filter(function () { | |
return (this.nodeType == 3 && b.test(this.nodeValue)) || ($(this).text().toLowerCase() === d.toLowerCase()) | |
}).replaceWith(function () { | |
if (this.nodeValue === null) { | |
return a.render({ | |
class_name: c, | |
match: $(this).html() | |
}) | |
} else { | |
return (this.nodeValue || "").replace(b, function (e) { | |
return a.render({ | |
class_name: c, | |
match: e | |
}) | |
}) | |
} | |
}) | |
}) | |
}; | |
$(document).ready(function () { | |
Grailbird.init() | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment