add $.event

This commit is contained in:
Nicolas Stepien 2013-02-11 15:34:37 +01:00
parent fec837ecdc
commit f4f53b92f2
3 changed files with 157 additions and 177 deletions

View File

@ -780,6 +780,11 @@
el.removeEventListener(event, handler, false);
}
},
event: function(event, detail) {
return d.dispatchEvent(new CustomEvent(event, {
detail: detail
}));
},
open: function(url) {
return (GM_openInTab || window.open)(url, '_blank');
},
@ -1017,12 +1022,10 @@
href: 'javascript:;'
});
$.on(link, 'click', Settings.open);
d.dispatchEvent(new CustomEvent('AddMenuEntry', {
detail: {
$.event('AddMenuEntry', {
type: 'header',
el: link
}
}));
});
link = $.el('a', {
className: 'fourchan-settings-link',
textContent: '4chan Settings',
@ -1031,15 +1034,13 @@
$.on(link, 'click', function() {
return $.id('settingsWindowLink').click();
});
d.dispatchEvent(new CustomEvent('AddMenuEntry', {
detail: {
$.event('AddMenuEntry', {
type: 'header',
el: link,
open: function() {
return !Conf['Disable 4chan\'s extension'];
}
}
}));
});
if (!Conf['Disable 4chan\'s extension']) {
return;
}
@ -1275,9 +1276,7 @@
type = _ref[_i];
entry.subEntries.push(Filter.menu.createSubEntry(type[0], type[1]));
}
return d.dispatchEvent(new CustomEvent('AddMenuEntry', {
detail: entry
}));
return $.event('AddMenuEntry', entry);
},
createSubEntry: function(text, type) {
var el;
@ -1423,8 +1422,7 @@
makeStub = $.el('label', {
innerHTML: "<input type=checkbox checked=" + Conf['Stubs'] + "> Make stub"
});
return d.dispatchEvent(new CustomEvent('AddMenuEntry', {
detail: {
return $.event('AddMenuEntry', {
type: 'post',
el: div,
open: function(_arg) {
@ -1443,8 +1441,7 @@
el: makeStub
}
]
}
}));
});
},
hide: function() {
var makeStub, thread;
@ -1634,8 +1631,7 @@
makeStub = $.el('label', {
innerHTML: "<input type=checkbox name=makeStub checked=" + Conf['Stubs'] + "> Make stub"
});
return d.dispatchEvent(new CustomEvent('AddMenuEntry', {
detail: {
return $.event('AddMenuEntry', {
type: 'post',
el: div,
open: function(post) {
@ -1656,8 +1652,7 @@
el: makeStub
}
]
}
}));
});
},
hide: function() {
var makeStub, parent, post, replies, thisPost;
@ -1875,16 +1870,14 @@
textContent: 'Report this post'
});
$.on(a, 'click', ReportLink.report);
return d.dispatchEvent(new CustomEvent('AddMenuEntry', {
detail: {
return $.event('AddMenuEntry', {
type: 'post',
el: a,
open: function(post) {
ReportLink.post = post;
return !post.isDead;
}
}
}));
});
},
report: function() {
var id, post, set, url;
@ -1932,8 +1925,7 @@
return !!file;
}
};
d.dispatchEvent(new CustomEvent('AddMenuEntry', {
detail: {
$.event('AddMenuEntry', {
type: 'post',
el: div,
open: function(post) {
@ -1953,8 +1945,7 @@
return true;
},
subEntries: [postEntry, fileEntry]
}
}));
});
return $.on(d, 'QRPostSuccessful', this.cooldown.start);
},
"delete": function() {
@ -2045,8 +2036,7 @@
className: 'download-link',
textContent: 'Download file'
});
return d.dispatchEvent(new CustomEvent('AddMenuEntry', {
detail: {
return $.event('AddMenuEntry', {
type: 'post',
el: a,
open: function(_arg) {
@ -2059,8 +2049,7 @@
a.download = file.name;
return true;
}
}
}));
});
}
};
@ -2093,9 +2082,7 @@
type = _ref[_i];
entry.subEntries.push(this.createSubEntry(type[0], type[1]));
}
return d.dispatchEvent(new CustomEvent('AddMenuEntry', {
detail: entry
}));
return $.event('AddMenuEntry', entry);
},
createSubEntry: function(text, type) {
var el, open;

View File

@ -134,6 +134,8 @@ $.extend $,
for event in events.split ' '
el.removeEventListener event, handler, false
return
event: (event, detail) ->
d.dispatchEvent new CustomEvent event, {detail}
open: (url) ->
(GM_openInTab or window.open) url, '_blank'
hidden: ->

View File

@ -101,8 +101,7 @@ Settings =
textContent: '4chan X Settings'
href: 'javascript:;'
$.on link, 'click', Settings.open
d.dispatchEvent new CustomEvent 'AddMenuEntry',
detail:
$.event 'AddMenuEntry',
type: 'header'
el: link
@ -112,8 +111,7 @@ Settings =
textContent: '4chan Settings'
href: 'javascript:;'
$.on link, 'click', -> $.id('settingsWindowLink').click()
d.dispatchEvent new CustomEvent 'AddMenuEntry',
detail:
$.event 'AddMenuEntry',
type: 'header'
el: link
open: -> !Conf['Disable 4chan\'s extension']
@ -328,8 +326,7 @@ Filter =
# Add a sub entry for each filter type.
entry.subEntries.push Filter.menu.createSubEntry type[0], type[1]
d.dispatchEvent new CustomEvent 'AddMenuEntry',
detail: entry
$.event 'AddMenuEntry', entry
createSubEntry: (text, type) ->
el = $.el 'a',
@ -481,8 +478,7 @@ ThreadHiding =
makeStub = $.el 'label',
innerHTML: "<input type=checkbox checked=#{Conf['Stubs']}> Make stub"
d.dispatchEvent new CustomEvent 'AddMenuEntry',
detail:
$.event 'AddMenuEntry',
type: 'post'
el: div
open: ({thread, isReply}) ->
@ -634,8 +630,7 @@ ReplyHiding =
makeStub = $.el 'label',
innerHTML: "<input type=checkbox name=makeStub checked=#{Conf['Stubs']}> Make stub"
d.dispatchEvent new CustomEvent 'AddMenuEntry',
detail:
$.event 'AddMenuEntry',
type: 'post'
el: div
open: (post) ->
@ -804,8 +799,7 @@ ReportLink =
href: 'javascript:;'
textContent: 'Report this post'
$.on a, 'click', ReportLink.report
d.dispatchEvent new CustomEvent 'AddMenuEntry',
detail:
$.event 'AddMenuEntry',
type: 'post'
el: a
open: (post) ->
@ -845,8 +839,7 @@ DeleteLink =
$.on fileEl, 'click', DeleteLink.delete
!!file
d.dispatchEvent new CustomEvent 'AddMenuEntry',
detail:
$.event 'AddMenuEntry',
type: 'post'
el: div
open: (post) ->
@ -935,8 +928,7 @@ DownloadLink =
a = $.el 'a',
className: 'download-link'
textContent: 'Download file'
d.dispatchEvent new CustomEvent 'AddMenuEntry',
detail:
$.event 'AddMenuEntry',
type: 'post'
el: a
open: ({file}) ->
@ -975,8 +967,7 @@ ArchiveLink =
# Add a sub entry for each type.
entry.subEntries.push @createSubEntry type[0], type[1]
d.dispatchEvent new CustomEvent 'AddMenuEntry',
detail: entry
$.event 'AddMenuEntry', entry
createSubEntry: (text, type) ->
el = $.el 'a',