Remove dependency of Post, Thread, CatalogThread classes on Callbacks class.

This commit is contained in:
ccd0 2016-04-15 10:34:39 -07:00
parent 070af1c3f2
commit f1b82d013f
54 changed files with 80 additions and 82 deletions

View File

@ -40,12 +40,9 @@ sources_API := \
src/Images/ImageCommon.coffee
sources_classes := \
src/classes/Callbacks.coffee \
src/classes/CatalogThread.coffee \
src/classes/Post.coffee src/classes/Clone.coffee \
src/classes/Thread.coffee \
$(filter-out \
%/Callbacks.coffee %/CatalogThread.coffee %/Post.coffee %/Clone.coffee %/Thread.coffee \
%/Post.coffee %/Clone.coffee \
,$(call sort_dir,classes))
sources_General := \

View File

@ -3,7 +3,7 @@ Anonymize =
return unless g.VIEW in ['index', 'thread', 'archive'] and Conf['Anonymize']
return @archive() if g.VIEW is 'archive'
Post.callbacks.push
Callbacks.Post.push
name: 'Anonymize'
cb: @node

View File

@ -75,7 +75,7 @@ Filter =
delete @filters[key]
return unless Object.keys(@filters).length
Post.callbacks.push
Callbacks.Post.push
name: 'Filter'
cb: @node

View File

@ -6,7 +6,7 @@ PostHiding =
$.addClass doc, "reply-hide"
@db = new DataBoard 'hiddenPosts'
Post.callbacks.push
Callbacks.Post.push
name: 'Reply Hiding'
cb: @node

View File

@ -2,7 +2,7 @@ Recursive =
recursives: {}
init: ->
return unless g.VIEW in ['index', 'thread']
Post.callbacks.push
Callbacks.Post.push
name: 'Recursive'
cb: @node

View File

@ -4,7 +4,7 @@ ThreadHiding =
@db = new DataBoard 'hiddenThreads'
return @catalogWatch() if g.VIEW is 'catalog'
@catalogSet g.BOARD
Post.callbacks.push
Callbacks.Post.push
name: 'Thread Hiding'
cb: @node

View File

@ -72,7 +72,7 @@ Build.Test =
Build.Test.postsRemaining--
Build.Test.report() if Build.Test.postsRemaining is 0
post2.isFetchedQuote = true
Main.callbackNodes Post, [post2]
Main.callbackNodes 'Post', [post2]
testAll: ->
g.posts.forEach (post) ->

View File

@ -5,7 +5,7 @@ Index =
init: ->
return if g.BOARD.ID is 'f' or !Conf['JSON Index'] or g.VIEW isnt 'index'
CatalogThread.callbacks.push
Callbacks.CatalogThread.push
name: 'Catalog Features'
cb: @catalogNode
@ -599,8 +599,8 @@ Index =
# Add the threads in a container to make sure all features work.
$.nodes Index.nodes
Main.callbackNodes Thread, threads
Main.callbackNodes Post, posts
Main.callbackNodes 'Thread', threads
Main.callbackNodes 'Post', posts
Index.updateHideLabel()
$.event 'IndexRefresh'
@ -627,7 +627,7 @@ Index =
$.add threadRoot, nodes
Main.handleErrors errors if errors
Main.callbackNodes Post, posts
Main.callbackNodes 'Post', posts
buildCatalogViews: ->
threads = Index.sortedNodes
@ -636,7 +636,7 @@ Index =
catalogThreads = []
for thread in threads when !thread.catalogView
catalogThreads.push new CatalogThread Build.catalogThread(thread), thread
Main.callbackNodes CatalogThread, catalogThreads
Main.callbackNodes 'CatalogThread', catalogThreads
threads.map (thread) -> thread.catalogView.nodes.root
sizeCatalogViews: (nodes) ->

View File

@ -291,8 +291,8 @@ Main =
threads[0].fileLimit = /\bimagelimit *= *1\b/.test scriptData
threads[0].ipCount = if m = scriptData.match /\bunique_ips *= *(\d+)\b/ then +m[1]
Main.callbackNodes Thread, threads
Main.callbackNodesDB Post, posts, ->
Main.callbackNodes 'Thread', threads
Main.callbackNodesDB 'Post', posts, ->
QuoteThreading.insert post for post in posts
Main.expectInitFinished = true
$.event '4chanXInitFinished'
@ -303,14 +303,14 @@ Main =
callbackNodes: (klass, nodes) ->
i = 0
cb = klass.callbacks
cb = Callbacks[klass]
while node = nodes[i++]
cb.execute node
return
callbackNodesDB: (klass, nodes, cb) ->
i = 0
cbs = klass.callbacks
cbs = Callbacks[klass]
fn = ->
return false unless node = nodes[i]
cbs.execute node

View File

@ -23,11 +23,11 @@ FappeTyme =
if Conf['Werk Tyme']
$.sync 'werk', @set.bind(@, 'werk')
Post.callbacks.push
Callbacks.Post.push
name: 'Fappe Tyme'
cb: @node
CatalogThread.callbacks.push
Callbacks.CatalogThread.push
name: 'Werk Tyme'
cb: @catalogNode

View File

@ -15,7 +15,7 @@ Gallery =
Header.addShortcut el
Post.callbacks.push
Callbacks.Post.push
name: 'Gallery'
cb: @node

View File

@ -14,7 +14,7 @@ ImageExpand =
@videoControls = $.el 'span', className: 'video-controls'
$.extend @videoControls, <%= html('\u00A0<a href="javascript:;" title="You can also contract the video by dragging it to the left.">contract</a>') %>
Post.callbacks.push
Callbacks.Post.push
name: 'Image Expansion'
cb: @node

View File

@ -2,11 +2,11 @@ ImageHover =
init: ->
return if g.VIEW not in ['index', 'thread']
if Conf['Image Hover']
Post.callbacks.push
Callbacks.Post.push
name: 'Image Hover'
cb: @node
if Conf['Image Hover in Catalog']
CatalogThread.callbacks.push
Callbacks.CatalogThread.push
name: 'Image Hover'
cb: @catalogNode

View File

@ -4,7 +4,7 @@ ImageLoader =
return unless Conf['Image Prefetching'] or
Conf['Replace JPG'] or Conf['Replace PNG'] or Conf['Replace GIF'] or Conf['Replace WEBM']
Post.callbacks.push
Callbacks.Post.push
name: 'Image Replace'
cb: @node

View File

@ -2,7 +2,7 @@ Metadata =
init: ->
return unless Conf['WEBM Metadata'] and g.VIEW in ['index', 'thread'] and g.BOARD.ID isnt 'f'
Post.callbacks.push
Callbacks.Post.push
name: 'WEBM Metadata'
cb: @node

View File

@ -2,7 +2,7 @@ RevealSpoilers =
init: ->
return unless g.VIEW in ['index', 'thread'] and Conf['Reveal Spoiler Thumbnails']
Post.callbacks.push
Callbacks.Post.push
name: 'Reveal Spoiler Thumbnails'
cb: @node

View File

@ -14,7 +14,7 @@ Sauce =
@link = $.el 'a',
target: '_blank'
className: 'sauce'
Post.callbacks.push
Callbacks.Post.push
name: 'Sauce'
cb: @node

View File

@ -12,14 +12,14 @@ Volume =
Volume.inputs?.volume.value = x
if Conf['Mouse Wheel Volume']
Post.callbacks.push
Callbacks.Post.push
name: 'Mouse Wheel Volume'
cb: @node
return unless g.BOARD.ID in ['gif', 'wsg']
if Conf['Mouse Wheel Volume']
CatalogThread.callbacks.push
Callbacks.CatalogThread.push
name: 'Mouse Wheel Volume'
cb: @catalogNode

View File

@ -5,11 +5,11 @@ Linkify =
if Conf['Comment Expansion']
ExpandComment.callbacks.push @node
Post.callbacks.push
Callbacks.Post.push
name: 'Linkify'
cb: @node
CatalogThread.callbacks.push
Callbacks.CatalogThread.push
name: 'Linkify'
cb: @catalogNode

View File

@ -9,11 +9,11 @@ Menu =
$.extend @button, <%= html('<i class="fa fa-angle-down"></i>') %>
@menu = new UI.Menu 'post'
Post.callbacks.push
Callbacks.Post.push
name: 'Menu'
cb: @node
CatalogThread.callbacks.push
Callbacks.CatalogThread.push
name: 'Menu'
cb: @catalogNode

View File

@ -4,10 +4,10 @@ AntiAutoplay =
$.addClass doc, 'anti-autoplay'
@stop audio for audio in $$ 'audio[autoplay]', doc
window.addEventListener 'loadstart', ((e) => @stop e.target), true
Post.callbacks.push
Callbacks.Post.push
name: 'Disable Autoplaying Sounds'
cb: @node
CatalogThread.callbacks.push
Callbacks.CatalogThread.push
name: 'Disable Autoplaying Sounds'
cb: @node
$.ready => @process d.body

View File

@ -21,10 +21,10 @@ CatalogLinks =
return
if Conf['JSON Index'] and Conf['Use <%= meta.name %> Catalog']
Post.callbacks.push
Callbacks.Post.push
name: 'Catalog Link Rewrite'
cb: @node
CatalogThread.callbacks.push
Callbacks.CatalogThread.push
name: 'Catalog Link Rewrite'
cb: @node

View File

@ -5,7 +5,7 @@ ExpandComment =
@callbacks.push Fourchan.code if g.BOARD.ID is 'g'
@callbacks.push Fourchan.math if g.BOARD.ID is 'sci'
Post.callbacks.push
Callbacks.Post.push
name: 'Comment Expansion'
cb: @node

View File

@ -5,7 +5,7 @@ ExpandThread =
if Conf['JSON Index']
$.on d, 'IndexRefresh', @onIndexRefresh
else
Thread.callbacks.push
Callbacks.Thread.push
name: 'Expand Thread'
cb: -> ExpandThread.setButton @
@ -97,7 +97,7 @@ ExpandThread =
filesCount++ if 'file' of post
posts.push post
postsRoot.push root
Main.callbackNodes Post, posts
Main.callbackNodes 'Post', posts
$.after a, postsRoot
$.event 'PostsInserted'

View File

@ -2,7 +2,7 @@ FileInfo =
init: ->
return if g.VIEW not in ['index', 'thread'] or !Conf['File Info Formatting']
Post.callbacks.push
Callbacks.Post.push
name: 'File Info Formatting'
cb: @node

View File

@ -20,7 +20,7 @@ Fourchan =
}));
}, false);
'''
Post.callbacks.push
Callbacks.Post.push
name: 'Parse /g/ code'
cb: @code
@ -39,10 +39,10 @@ Fourchan =
window.MathJax.Hub.Queue ['Typeset', window.MathJax.Hub, e.target]
, false
, false
Post.callbacks.push
Callbacks.Post.push
name: 'Parse /sci/ math'
cb: @math
CatalogThread.callbacks.push
Callbacks.CatalogThread.push
name: 'Parse /sci/ math'
cb: @math

View File

@ -5,7 +5,7 @@ IDColor =
Heaven: [0, 0, 0, '#fff']
}
Post.callbacks.push
Callbacks.Post.push
name: 'Color User IDs'
cb: @node

View File

@ -2,7 +2,7 @@ IDHighlight =
init: ->
return unless g.VIEW in ['index', 'thread']
Post.callbacks.push
Callbacks.Post.push
name: 'Highlight by User ID'
cb: @node

View File

@ -9,7 +9,7 @@ RelativeDates =
$.on d, 'visibilitychange ThreadUpdate', @flush
if Conf['Relative Post Dates']
Post.callbacks.push
Callbacks.Post.push
name: 'Relative Post Dates'
cb: @node

View File

@ -5,11 +5,11 @@ RemoveSpoilers =
return unless Conf['Remove Spoilers']
Post.callbacks.push
Callbacks.Post.push
name: 'Reveal Spoilers'
cb: @node
CatalogThread.callbacks.push
Callbacks.CatalogThread.push
name: 'Reveal Spoilers'
cb: @node

View File

@ -2,10 +2,10 @@ ThreadLinks =
init: ->
return unless g.VIEW is 'index' and Conf['Open Threads in New Tab']
Post.callbacks.push
Callbacks.Post.push
name: 'Thread Links'
cb: @node
CatalogThread.callbacks.push
Callbacks.CatalogThread.push
name: 'Thread Links'
cb: @catalogNode

View File

@ -2,7 +2,7 @@ Time =
init: ->
return unless g.VIEW in ['index', 'thread'] and Conf['Time Formatting']
Post.callbacks.push
Callbacks.Post.push
name: 'Time Formatting'
cb: @node

View File

@ -1,7 +1,7 @@
MarkNewIPs =
init: ->
return if g.VIEW isnt 'thread' or !Conf['Mark New IPs']
Thread.callbacks.push
Callbacks.Thread.push
name: 'Mark New IPs'
cb: @node

View File

@ -32,7 +32,7 @@ ReplyPruning =
el: el
order: 190
Thread.callbacks.push
Callbacks.Thread.push
name: 'Reply Pruning'
cb: @node

View File

@ -2,7 +2,7 @@ ThreadExcerpt =
init: ->
return if g.BOARD.ID isnt 'f' or g.VIEW isnt 'thread' or !Conf['Thread Excerpt']
Thread.callbacks.push
Callbacks.Thread.push
name: 'Thread Excerpt'
cb: @node
node: -> d.title = Get.threadExcerpt @

View File

@ -33,7 +33,7 @@ ThreadStats =
$.on @pageCountEl, 'click', ThreadStats.fetchPage if @pageCountEl
Thread.callbacks.push
Callbacks.Thread.push
name: 'Thread Stats'
cb: @node

View File

@ -58,7 +58,7 @@ ThreadUpdater =
order: 110
subEntries: subEntries
Thread.callbacks.push
Callbacks.Thread.push
name: 'Thread Updater'
cb: @node
@ -316,7 +316,7 @@ ThreadUpdater =
unreadCount = Unread.posts?.size
unreadQYCount = Unread.postsQuotingYou?.size
Main.callbackNodes Post, posts
Main.callbackNodes 'Post', posts
if d.hidden or not d.hasFocus()
if Conf['Beep Quoting You'] and Unread.postsQuotingYou?.size > unreadQYCount

View File

@ -61,10 +61,10 @@ ThreadWatcher =
$.on @el, 'click', @cb
true
Post.callbacks.push
Callbacks.Post.push
name: 'Thread Watcher'
cb: @node
CatalogThread.callbacks.push
Callbacks.CatalogThread.push
name: 'Thread Watcher'
cb: @catalogNode

View File

@ -20,11 +20,11 @@ Unread =
@order = new RandomAccessList()
@position = null
Thread.callbacks.push
Callbacks.Thread.push
name: 'Unread'
cb: @node
Post.callbacks.push
Callbacks.Post.push
name: 'Unread'
cb: @addPost

View File

@ -33,7 +33,7 @@ QR =
$.on d, '4chanXInitFinished', @initReady
Post.callbacks.push
Callbacks.Post.push
name: 'Quick Reply'
cb: @node

View File

@ -14,10 +14,10 @@ QuoteBacklink =
init: ->
return if g.VIEW not in ['index', 'thread'] or !Conf['Quote Backlinks']
Post.callbacks.push
Callbacks.Post.push
name: 'Quote Backlinking Part 1'
cb: @firstNode
Post.callbacks.push
Callbacks.Post.push
name: 'Quote Backlinking Part 2'
cb: @secondNode
firstNode: ->

View File

@ -7,7 +7,7 @@ QuoteCT =
# \u00A0 is nbsp
@text = '\u00A0(Cross-thread)'
Post.callbacks.push
Callbacks.Post.push
name: 'Mark Cross-thread Quotes'
cb: @node
node: ->

View File

@ -5,7 +5,7 @@ QuoteInline =
if Conf['Comment Expansion']
ExpandComment.callbacks.push @node
Post.callbacks.push
Callbacks.Post.push
name: 'Quote Inlining'
cb: @node

View File

@ -7,7 +7,7 @@ QuoteOP =
# \u00A0 is nbsp
@text = '\u00A0(OP)'
Post.callbacks.push
Callbacks.Post.push
name: 'Mark OP Quotes'
cb: @node

View File

@ -5,7 +5,7 @@ QuotePreview =
if Conf['Comment Expansion']
ExpandComment.callbacks.push @node
Post.callbacks.push
Callbacks.Post.push
name: 'Quote Previewing'
cb: @node

View File

@ -3,7 +3,7 @@ QuoteStrikeThrough =
return unless g.VIEW in ['index', 'thread'] and
(Conf['Reply Hiding Buttons'] or (Conf['Menu'] and Conf['Reply Hiding Link']) or Conf['Filter'])
Post.callbacks.push
Callbacks.Post.push
name: 'Strike-through Quotes'
cb: @node

View File

@ -26,11 +26,11 @@ QuoteThreading =
el: @controls
order: 99
Thread.callbacks.push
Callbacks.Thread.push
name: 'Quote Threading'
cb: @setThread
Post.callbacks.push
Callbacks.Post.push
name: 'Quote Threading'
cb: @node

View File

@ -23,7 +23,7 @@ QuoteYou =
# \u00A0 is nbsp
@text = '\u00A0(You)'
Post.callbacks.push
Callbacks.Post.push
name: 'Mark Quotes of You'
cb: @node

View File

@ -5,7 +5,7 @@ Quotify =
if Conf['Comment Expansion']
ExpandComment.callbacks.push @node
Post.callbacks.push
Callbacks.Post.push
name: 'Resurrect Quotes'
cb: @node

View File

@ -1,4 +1,8 @@
class Callbacks
@Post = new Callbacks 'Post'
@Thread = new Callbacks 'Thread'
@CatalogThread = new Callbacks 'Catalog Thread'
constructor: (@type) ->
@keys = []

View File

@ -1,5 +1,4 @@
class CatalogThread
@callbacks = new Callbacks 'Catalog Thread'
toString: -> @ID
constructor: (root, @thread) ->

View File

@ -15,7 +15,7 @@ class Fetcher
# Stop here if the container has been removed while loading.
return unless @root.parentNode
clone = post.addClone @quoter.context, ($.hasClass @root, 'dialog')
Main.callbackNodes Clone, [clone]
Main.callbackNodes 'Post', [clone]
# Get rid of the side arrows/stubs.
{nodes} = clone
@ -79,7 +79,7 @@ class Fetcher
new Thread @threadID, board
post = new Post Build.postFromObject(post, @boardID), thread, board
post.isFetchedQuote = true
Main.callbackNodes Post, [post]
Main.callbackNodes 'Post', [post]
@insert post
archivedPost: ->
@ -185,7 +185,7 @@ class Fetcher
post.kill()
post.file.thumbURL = o.file.thumbURL if post.file
post.isFetchedQuote = true
Main.callbackNodes Post, [post]
Main.callbackNodes 'Post', [post]
@insert post
archiveTags:

View File

@ -1,5 +1,4 @@
class Post
@callbacks = new Callbacks 'Post'
toString: -> @ID
constructor: (root, @thread, @board) ->

View File

@ -1,5 +1,4 @@
class Thread
@callbacks = new Callbacks 'Thread'
toString: -> @ID
constructor: (@ID, @board) ->