update framework

This commit is contained in:
James Campos 2011-01-15 14:45:41 -08:00
parent 1ab8666f69
commit c750b9b62e
2 changed files with 33 additions and 64 deletions

View File

@ -31,7 +31,7 @@ config =
'Thread Watcher': [true, 'Bookmark threads'] 'Thread Watcher': [true, 'Bookmark threads']
'Unread Count': [true, 'Show unread post count in tab title'] 'Unread Count': [true, 'Show unread post count in tab title']
#utility #framework
AEOS = AEOS =
init: -> init: ->
#x-browser #x-browser
@ -72,9 +72,10 @@ AEOS =
} }
' '
#dialog creation #dialog creation
makeDialog: (id, position) -> makeDialog: (id, position, html) ->
dialog = document.createElement 'div' dialog = document.createElement 'div'
dialog.className = 'reply dialog' dialog.className = 'reply dialog'
dialog.innerHTML = html
dialog.id = id dialog.id = id
switch position switch position
when 'topleft' when 'topleft'
@ -93,6 +94,9 @@ AEOS =
top = GM_getValue "#{id}Top", top top = GM_getValue "#{id}Top", top
if left then dialog.style.left = left else dialog.style.right = '0px' if left then dialog.style.left = left else dialog.style.right = '0px'
if top then dialog.style.top = top else dialog.style.bottom = '0px' if top then dialog.style.top = top else dialog.style.bottom = '0px'
$('div.move', dialog).addEventListener 'mousedown', AEOS.move, true
$('div.move a[name=close]', dialog)?.addEventListener 'click', (-> remove $ id), true
dialog dialog
#movement #movement
move: (e) -> move: (e) ->
@ -128,9 +132,11 @@ AEOS =
GM_setValue "#{id}Left", div.style.left GM_setValue "#{id}Left", div.style.left
GM_setValue "#{id}Top", div.style.top GM_setValue "#{id}Top", div.style.top
#convenience
d = document d = document
g = null #globals g = null #globals
#utility
$ = (selector, root) -> $ = (selector, root) ->
root or= d.body root or= d.body
root.querySelector selector root.querySelector selector
@ -584,7 +590,6 @@ options = ->
remove div remove div
return return
div = AEOS.makeDialog 'options', 'center'
hiddenNum = g.hiddenReplies.length + g.hiddenThreads.length hiddenNum = g.hiddenReplies.length + g.hiddenThreads.length
html = '<div class="move">Options <a name=close>X</a></div><div>' html = '<div class="move">Options <a name=close>X</a></div><div>'
for option, value of config for option, value of config
@ -594,9 +599,9 @@ options = ->
html += "<div><a class=sauce>Flavors</a></div>" html += "<div><a class=sauce>Flavors</a></div>"
html += "<div><textarea style=\"display: none;\" name=flavors>#{GM_getValue 'flavors', g.flavors}</textarea></div>" html += "<div><textarea style=\"display: none;\" name=flavors>#{GM_getValue 'flavors', g.flavors}</textarea></div>"
html += "<input type=\"button\" value=\"hidden: #{hiddenNum}\"><br>" html += "<input type=\"button\" value=\"hidden: #{hiddenNum}\"><br>"
div.innerHTML = html
$('div.move', div).addEventListener 'mousedown', AEOS.move, true div = AEOS.makeDialog 'options', 'center', html
$('a[name=close]', div).addEventListener 'click', (-> remove($ '#options')), true
for input in $$ 'input[type="checkbox"]', div for input in $$ 'input[type="checkbox"]', div
input.addEventListener 'change', changeCheckbox, true input.addEventListener 'change', changeCheckbox, true
$('a.sauce', div).addEventListener 'click', editSauce, true $('a.sauce', div).addEventListener 'click', editSauce, true
@ -630,24 +635,9 @@ qrText = (link) ->
quickReply = (link, text) -> quickReply = (link, text) ->
unless qr = $ '#qr' unless qr = $ '#qr'
#make quick reply dialog html = "<div class=move>Quick Reply <input type=checkbox title=autohide><a name=close title=close>X</a></div>"
qr = AEOS.makeDialog 'qr', 'topleft' qr = AEOS.makeDialog 'qr', 'topleft', html
titlebar = n 'div',
innerHTML: 'Quick Reply '
className: 'move'
listener: ['mousedown', AEOS.move]
addTo qr, titlebar
autohideB = n 'input',
type: 'checkbox'
className: 'pointer'
title: 'autohide'
listener: ['click', autohide]
closeB = n 'a',
textContent: 'X'
className: 'pointer'
title: 'close'
listener: ['click', closeQR]
addTo titlebar, autohideB, tn(' '), closeB
form = $ 'form[name=post]' form = $ 'form[name=post]'
clone = form.cloneNode true clone = form.cloneNode true
#remove recaptcha scripts #remove recaptcha scripts
@ -882,14 +872,12 @@ updateNow = ->
g.req = request url, updateCallback g.req = request url, updateCallback
updaterMake = -> updaterMake = ->
div = AEOS.makeDialog 'updater', 'topright'
html = "<div class=move><span id=count></span> <span id=timer>Thread Updater</span></div>" html = "<div class=move><span id=count></span> <span id=timer>Thread Updater</span></div>"
html += "<div><label>Auto Update<input type=checkbox name=auto></label></div>" html += "<div><label>Auto Update<input type=checkbox name=auto></label></div>"
html += "<div><label>Interval (s)<input type=text name=interval></label></div>" html += "<div><label>Interval (s)<input type=text name=interval></label></div>"
html += "<div><input type=button value='Update Now'></div>" html += "<div><input type=button value='Update Now'></div>"
div.innerHTML = html div = AEOS.makeDialog 'updater', 'topright', html
$('div.move', div).addEventListener 'mousedown', AEOS.move, true
auto = $ 'input[name=auto]', div auto = $ 'input[name=auto]', div
auto.addEventListener 'click', updateAuto, true auto.addEventListener 'click', updateAuto, true
interval = $ 'input[name=interval]', div interval = $ 'input[name=interval]', div
@ -1231,9 +1219,8 @@ if getConfig 'Quick Report'
if getConfig 'Thread Watcher' if getConfig 'Thread Watcher'
#create watcher #create watcher
watcher = AEOS.makeDialog 'watcher', 'topleft'
watcher.innerHTML = '<div class="move">Thread Watcher</div><div></div>' watcher.innerHTML = '<div class="move">Thread Watcher</div><div></div>'
$('div', watcher).addEventListener('mousedown', AEOS.move, true) watcher = AEOS.makeDialog 'watcher', 'topleft', html
addTo d.body, watcher addTo d.body, watcher
watcherUpdate() watcherUpdate()

View File

@ -72,10 +72,11 @@
}\ }\
'); ');
}, },
makeDialog: function(id, position) { makeDialog: function(id, position, html) {
var dialog, left, top; var dialog, left, top, _ref;
dialog = document.createElement('div'); dialog = document.createElement('div');
dialog.className = 'reply dialog'; dialog.className = 'reply dialog';
dialog.innerHTML = html;
dialog.id = id; dialog.id = id;
switch (position) { switch (position) {
case 'topleft': case 'topleft':
@ -106,6 +107,12 @@
} else { } else {
dialog.style.bottom = '0px'; dialog.style.bottom = '0px';
} }
$('div.move', dialog).addEventListener('mousedown', AEOS.move, true);
if ((_ref = $('div.move a[name=close]', dialog)) != null) {
_ref.addEventListener('click', (function() {
return remove($(id));
}), true);
}
return dialog; return dialog;
}, },
move: function(e) { move: function(e) {
@ -749,7 +756,6 @@
remove(div); remove(div);
return; return;
} }
div = AEOS.makeDialog('options', 'center');
hiddenNum = g.hiddenReplies.length + g.hiddenThreads.length; hiddenNum = g.hiddenReplies.length + g.hiddenThreads.length;
html = '<div class="move">Options <a name=close>X</a></div><div>'; html = '<div class="move">Options <a name=close>X</a></div><div>';
for (option in config) { for (option in config) {
@ -761,11 +767,7 @@
html += "<div><a class=sauce>Flavors</a></div>"; html += "<div><a class=sauce>Flavors</a></div>";
html += "<div><textarea style=\"display: none;\" name=flavors>" + (GM_getValue('flavors', g.flavors)) + "</textarea></div>"; html += "<div><textarea style=\"display: none;\" name=flavors>" + (GM_getValue('flavors', g.flavors)) + "</textarea></div>";
html += "<input type=\"button\" value=\"hidden: " + hiddenNum + "\"><br>"; html += "<input type=\"button\" value=\"hidden: " + hiddenNum + "\"><br>";
div.innerHTML = html; div = AEOS.makeDialog('options', 'center', html);
$('div.move', div).addEventListener('mousedown', AEOS.move, true);
$('a[name=close]', div).addEventListener('click', (function() {
return remove($('#options'));
}), true);
_ref = $$('input[type="checkbox"]', div); _ref = $$('input[type="checkbox"]', div);
for (_i = 0, _len = _ref.length; _i < _len; _i++) { for (_i = 0, _len = _ref.length; _i < _len; _i++) {
input = _ref[_i]; input = _ref[_i];
@ -803,28 +805,10 @@
return text; return text;
}; };
quickReply = function(link, text) { quickReply = function(link, text) {
var auto, autoBox, autohideB, clone, closeB, form, input, qr, script, submit, textarea, titlebar, xpath, _i, _len, _ref, _ref2; var auto, autoBox, clone, form, html, input, qr, script, submit, textarea, xpath, _i, _len, _ref, _ref2;
if (!(qr = $('#qr'))) { if (!(qr = $('#qr'))) {
qr = AEOS.makeDialog('qr', 'topleft'); html = "<div class=move>Quick Reply <input type=checkbox title=autohide><a name=close title=close>X</a></div>";
titlebar = n('div', { qr = AEOS.makeDialog('qr', 'topleft', html);
innerHTML: 'Quick Reply ',
className: 'move',
listener: ['mousedown', AEOS.move]
});
addTo(qr, titlebar);
autohideB = n('input', {
type: 'checkbox',
className: 'pointer',
title: 'autohide',
listener: ['click', autohide]
});
closeB = n('a', {
textContent: 'X',
className: 'pointer',
title: 'close',
listener: ['click', closeQR]
});
addTo(titlebar, autohideB, tn(' '), closeB);
form = $('form[name=post]'); form = $('form[name=post]');
clone = form.cloneNode(true); clone = form.cloneNode(true);
_ref = $$('script', clone); _ref = $$('script', clone);
@ -1119,13 +1103,11 @@
}; };
updaterMake = function() { updaterMake = function() {
var auto, div, html, interval; var auto, div, html, interval;
div = AEOS.makeDialog('updater', 'topright');
html = "<div class=move><span id=count></span> <span id=timer>Thread Updater</span></div>"; html = "<div class=move><span id=count></span> <span id=timer>Thread Updater</span></div>";
html += "<div><label>Auto Update<input type=checkbox name=auto></label></div>"; html += "<div><label>Auto Update<input type=checkbox name=auto></label></div>";
html += "<div><label>Interval (s)<input type=text name=interval></label></div>"; html += "<div><label>Interval (s)<input type=text name=interval></label></div>";
html += "<div><input type=button value='Update Now'></div>"; html += "<div><input type=button value='Update Now'></div>";
div.innerHTML = html; div = AEOS.makeDialog('updater', 'topright', html);
$('div.move', div).addEventListener('mousedown', AEOS.move, true);
auto = $('input[name=auto]', div); auto = $('input[name=auto]', div);
auto.addEventListener('click', updateAuto, true); auto.addEventListener('click', updateAuto, true);
interval = $('input[name=interval]', div); interval = $('input[name=interval]', div);
@ -1397,7 +1379,8 @@
if (getConfig('Image Expansion')) { if (getConfig('Image Expansion')) {
delform = $('form[name=delform]'); delform = $('form[name=delform]');
expand = n('div', { expand = n('div', {
innerHTML: "<label>Expand Images<input type=checkbox id=imageExpand></label>" innerHTML: '<label>Expand Images<input type=checkbox id=imageExpand></label>\
<select><option>full</option><option>fit width</option><option>fit screen</option></select>'
}); });
$("input", expand).addEventListener('click', imageExpandClick, true); $("input", expand).addEventListener('click', imageExpandClick, true);
inBefore(delform.firstChild, expand); inBefore(delform.firstChild, expand);
@ -1540,9 +1523,8 @@
}); });
} }
if (getConfig('Thread Watcher')) { if (getConfig('Thread Watcher')) {
watcher = AEOS.makeDialog('watcher', 'topleft');
watcher.innerHTML = '<div class="move">Thread Watcher</div><div></div>'; watcher.innerHTML = '<div class="move">Thread Watcher</div><div></div>';
$('div', watcher).addEventListener('mousedown', AEOS.move, true); watcher = AEOS.makeDialog('watcher', 'topleft', html);
addTo(d.body, watcher); addTo(d.body, watcher);
watcherUpdate(); watcherUpdate();
threads = g.watched[g.BOARD] || []; threads = g.watched[g.BOARD] || [];