More optimizations

This commit is contained in:
seaweedchan 2013-08-16 05:30:10 -07:00
parent 81a2da0d27
commit 61b2a51836
3 changed files with 96 additions and 103 deletions

View File

@ -8465,44 +8465,38 @@
}); });
}, },
ready: function() { ready: function() {
var banner, btitle, child, children, i, subtitle; var banner, child, children, i;
banner = $(".boardBanner"); banner = $(".boardBanner");
if (Conf['Custom Board Titles']) {
btitle = $(".boardTitle", banner);
subtitle = $(".boardSubtitle", banner);
btitle.title = "Ctrl+click to edit board title";
subtitle.title = "Ctrl+click to edit board subtitle";
}
children = banner.children; children = banner.children;
i = 0; i = 0;
while (child = children[i++]) { while (child = children[i++]) {
if (child.tagName.toLowerCase() === "img") { if (i === 1) {
child.id = "Banner"; child.id = "Banner";
child.title = "Click to change"; child.title = "Click to change";
$.on(child, 'click', Banner.cb.toggle); $.on(child, 'click', Banner.cb.toggle);
continue; continue;
} }
if (Conf['Custom Board Titles']) { if (Conf['Custom Board Titles']) {
Banner.custom(child); Banner.custom(child).title = "Ctrl+click to edit board " + (i === 3 ? 'sub' : '') + "title";
Banner.custom(child).spellcheck = false;
} }
} }
}, },
types: {
jpg: 227,
png: 270,
gif: 253
},
cb: { cb: {
toggle: function() { toggle: function() {
var num, type; var num, type, types;
type = ['jpg', 'png', 'gif'][Math.floor(3 * Math.random())]; types = {
num = Math.floor(Banner.types[type] * Math.random()); jpg: 227,
png: 270,
gif: 253
};
type = Object.keys(types)[Math.floor(3 * Math.random())];
num = Math.floor(types[type] * Math.random());
return this.src = "//static.4chan.org/image/title/" + num + "." + type; return this.src = "//static.4chan.org/image/title/" + num + "." + type;
}, },
click: function(e) { click: function(e) {
if (e.ctrlKey) { if (e.ctrlKey) {
this.contentEditable = true; this.contentEditable = true;
this.spellcheck = false;
return this.focus(); return this.focus();
} }
}, },
@ -8514,6 +8508,7 @@
}, },
focus: function() { focus: function() {
var items, string, string2; var items, string, string2;
this.textContent = this.innerHTML;
string = "" + g.BOARD + "." + this.className; string = "" + g.BOARD + "." + this.className;
string2 = "" + string + ".orig"; string2 = "" + string + ".orig";
items = { items = {
@ -8526,40 +8521,39 @@
return $.set(string2, items.title); return $.set(string2, items.title);
} }
}); });
return this.textContent = this.innerHTML;
}, },
blur: function() { blur: function() {
$.set("" + g.BOARD + "." + this.className, this.textContent);
this.innerHTML = this.textContent; this.innerHTML = this.textContent;
return this.contentEditable = false; this.contentEditable = false;
return $.set("" + g.BOARD + "." + this.className, this.textContent);
} }
}, },
custom: function(child) { custom: function(child) {
var cachedTest, string, string2; var cachedTest, string;
cachedTest = child.innerHTML; cachedTest = child.innerHTML;
string = "" + g.BOARD + "." + child.className; string = "" + g.BOARD + "." + child.className;
string2 = "" + string + ".orig"; $.on(child, 'click keydown focus blur', function(e) {
return Banner.cb[e.type].apply(this, [e]);
});
$.get(string, cachedTest, function(item) { $.get(string, cachedTest, function(item) {
var title; var string2, title;
if (!(title = item[string])) { if (!(title = item[string])) {
return; return;
} }
if (Conf['Persistent Custom Board Titles']) { if (Conf['Persistent Custom Board Titles']) {
return child.innerHTML = title; return child.innerHTML = title;
} else {
return $.get(string2, cachedTest, function(itemb) {
if (cachedTest === itemb[string2]) {
return child.innerHTML = title;
} else {
$.set(string, cachedTest);
return $.set(string2, cachedTest);
}
});
} }
string2 = "" + string + ".orig";
return $.get(string2, cachedTest, function(itemb) {
if (cachedTest === itemb[string2]) {
return child.innerHTML = title;
} else {
$.set(string, cachedTest);
return $.set(string2, cachedTest);
}
});
}); });
return $.on(child, 'click keydown focus blur', function(e) { return child;
return Banner.cb[e.type].apply(this, [e]);
});
} }
}; };

View File

@ -8455,44 +8455,38 @@
}); });
}, },
ready: function() { ready: function() {
var banner, btitle, child, children, i, subtitle; var banner, child, children, i;
banner = $(".boardBanner"); banner = $(".boardBanner");
if (Conf['Custom Board Titles']) {
btitle = $(".boardTitle", banner);
subtitle = $(".boardSubtitle", banner);
btitle.title = "Ctrl+click to edit board title";
subtitle.title = "Ctrl+click to edit board subtitle";
}
children = banner.children; children = banner.children;
i = 0; i = 0;
while (child = children[i++]) { while (child = children[i++]) {
if (child.tagName.toLowerCase() === "img") { if (i === 1) {
child.id = "Banner"; child.id = "Banner";
child.title = "Click to change"; child.title = "Click to change";
$.on(child, 'click', Banner.cb.toggle); $.on(child, 'click', Banner.cb.toggle);
continue; continue;
} }
if (Conf['Custom Board Titles']) { if (Conf['Custom Board Titles']) {
Banner.custom(child); Banner.custom(child).title = "Ctrl+click to edit board " + (i === 3 ? 'sub' : '') + "title";
Banner.custom(child).spellcheck = false;
} }
} }
}, },
types: {
jpg: 227,
png: 270,
gif: 253
},
cb: { cb: {
toggle: function() { toggle: function() {
var num, type; var num, type, types;
type = ['jpg', 'png', 'gif'][Math.floor(3 * Math.random())]; types = {
num = Math.floor(Banner.types[type] * Math.random()); jpg: 227,
png: 270,
gif: 253
};
type = Object.keys(types)[Math.floor(3 * Math.random())];
num = Math.floor(types[type] * Math.random());
return this.src = "//static.4chan.org/image/title/" + num + "." + type; return this.src = "//static.4chan.org/image/title/" + num + "." + type;
}, },
click: function(e) { click: function(e) {
if (e.ctrlKey) { if (e.ctrlKey) {
this.contentEditable = true; this.contentEditable = true;
this.spellcheck = false;
return this.focus(); return this.focus();
} }
}, },
@ -8504,6 +8498,7 @@
}, },
focus: function() { focus: function() {
var items, string, string2; var items, string, string2;
this.textContent = this.innerHTML;
string = "" + g.BOARD + "." + this.className; string = "" + g.BOARD + "." + this.className;
string2 = "" + string + ".orig"; string2 = "" + string + ".orig";
items = { items = {
@ -8516,40 +8511,39 @@
return $.set(string2, items.title); return $.set(string2, items.title);
} }
}); });
return this.textContent = this.innerHTML;
}, },
blur: function() { blur: function() {
$.set("" + g.BOARD + "." + this.className, this.textContent);
this.innerHTML = this.textContent; this.innerHTML = this.textContent;
return this.contentEditable = false; this.contentEditable = false;
return $.set("" + g.BOARD + "." + this.className, this.textContent);
} }
}, },
custom: function(child) { custom: function(child) {
var cachedTest, string, string2; var cachedTest, string;
cachedTest = child.innerHTML; cachedTest = child.innerHTML;
string = "" + g.BOARD + "." + child.className; string = "" + g.BOARD + "." + child.className;
string2 = "" + string + ".orig"; $.on(child, 'click keydown focus blur', function(e) {
return Banner.cb[e.type].apply(this, [e]);
});
$.get(string, cachedTest, function(item) { $.get(string, cachedTest, function(item) {
var title; var string2, title;
if (!(title = item[string])) { if (!(title = item[string])) {
return; return;
} }
if (Conf['Persistent Custom Board Titles']) { if (Conf['Persistent Custom Board Titles']) {
return child.innerHTML = title; return child.innerHTML = title;
} else {
return $.get(string2, cachedTest, function(itemb) {
if (cachedTest === itemb[string2]) {
return child.innerHTML = title;
} else {
$.set(string, cachedTest);
return $.set(string2, cachedTest);
}
});
} }
string2 = "" + string + ".orig";
return $.get(string2, cachedTest, function(itemb) {
if (cachedTest === itemb[string2]) {
return child.innerHTML = title;
} else {
$.set(string, cachedTest);
return $.set(string2, cachedTest);
}
});
}); });
return $.on(child, 'click keydown focus blur', function(e) { return child;
return Banner.cb[e.type].apply(this, [e]);
});
} }
}; };

View File

@ -5,40 +5,40 @@ Banner =
ready: -> ready: ->
banner = $ ".boardBanner" banner = $ ".boardBanner"
if Conf['Custom Board Titles']
btitle = $ ".boardTitle", banner
subtitle = $ ".boardSubtitle", banner
btitle.title = "Ctrl+click to edit board title"
subtitle.title = "Ctrl+click to edit board subtitle"
{children} = banner {children} = banner
i = 0 i = 0
while child = children[i++] while child = children[i++]
if child.tagName.toLowerCase() is "img" if i is 1
child.id = "Banner" child.id = "Banner"
child.title = "Click to change" child.title = "Click to change"
$.on child, 'click', Banner.cb.toggle $.on child, 'click', Banner.cb.toggle
continue continue
if Conf['Custom Board Titles'] if Conf['Custom Board Titles']
Banner.custom child Banner.custom(child).title = "Ctrl+click to edit board #{if i is 3
'sub'
else
''}title"
Banner.custom(child).spellcheck = false
return return
types:
jpg: 227
png: 270
gif: 253
cb: cb:
toggle: -> toggle: ->
type = ['jpg', 'png', 'gif'][Math.floor 3 * Math.random()] types =
num = Math.floor Banner.types[type] * Math.random() jpg: 227
png: 270
gif: 253
type = Object.keys(types)[Math.floor 3 * Math.random()]
num = Math.floor types[type] * Math.random()
@src = "//static.4chan.org/image/title/#{num}.#{type}" @src = "//static.4chan.org/image/title/#{num}.#{type}"
click: (e) -> click: (e) ->
if e.ctrlKey if e.ctrlKey
@contentEditable = true @contentEditable = true
@spellcheck = false
@focus() @focus()
keydown: (e) -> keydown: (e) ->
@ -46,38 +46,43 @@ Banner =
return @blur() if !e.shiftKey and e.keyCode is 13 return @blur() if !e.shiftKey and e.keyCode is 13
focus: -> focus: ->
@textContent = @innerHTML
string = "#{g.BOARD}.#{@className}" string = "#{g.BOARD}.#{@className}"
string2 = "#{string}.orig" string2 = "#{string}.orig"
items =
title: @innerHTML items = {title: @innerHTML}
items[string] = '' items[string] = ''
items[string2] = false items[string2] = false
$.get items, (items) -> $.get items, (items) ->
unless items[string2] and items.title is items[string] unless items[string2] and items.title is items[string]
$.set string2, items.title $.set string2, items.title
@textContent = @innerHTML
return
blur: -> blur: ->
$.set "#{g.BOARD}.#{@className}", @textContent
@innerHTML = @textContent @innerHTML = @textContent
@contentEditable = false @contentEditable = false
$.set "#{g.BOARD}.#{@className}", @textContent
custom: (child) -> custom: (child) ->
cachedTest = child.innerHTML cachedTest = child.innerHTML
string = "#{g.BOARD}.#{child.className}" string = "#{g.BOARD}.#{child.className}"
string2 = "#{string}.orig"
$.on child, 'click keydown focus blur', (e) -> Banner.cb[e.type].apply @, [e]
$.get string, cachedTest, (item) -> $.get string, cachedTest, (item) ->
return unless title = item[string] return unless title = item[string]
if Conf['Persistent Custom Board Titles'] return child.innerHTML = title if Conf['Persistent Custom Board Titles']
child.innerHTML = title
else
$.get string2, cachedTest, (itemb) ->
if cachedTest is itemb[string2]
child.innerHTML = title
else
$.set string, cachedTest
$.set string2, cachedTest
$.on child, 'click keydown focus blur', (e) -> Banner.cb[e.type].apply @, [e] string2 = "#{string}.orig"
$.get string2, cachedTest, (itemb) ->
if cachedTest is itemb[string2]
child.innerHTML = title
else
$.set string, cachedTest
$.set string2, cachedTest
child