Page MenuHomePhabricator

Refactor JS code
Closed, ResolvedPublic

Description

The Javascript modules are in dire need of a good clean up. Specifically, the ext.wikispeech.js has grown a bit to big and can be split into several smaller modules. A good time to do this is the "soft freeze" we plan to do when T133680 and T149302 are done, before work on the editor is committed.

Event Timeline

Where functions live, as of baba7b102e:

modules/ext.wikispeech.selectionPlayer.js
25:playSelectionIfValid
45:isSelectionValid
71:isTextSelected
84:getFirstNodeInSelection
125:getFirstTextNode
158:isNodeInUtterance
186:playSelection
271:getStartUtterance
316:isPointInItems
375:getNextTextNode
417:getStartToken
451:setStartTime
464:getLastNodeInSelection
506:getLastTextNode
545:getEndUtterance
583:getPreviousTextNode
625:getEndToken
664:setEndTime
679:addSelectionPlayer
710:showSelectionPlayer
744:getTextDirection
757:resetPreviousEndUtterance

modules/ext.wikispeech.highlighter.js
31:highlightUtterance
72:wrapTextNodes
117:startTokenHighlighting
133:highlightToken
180:getNodeInUtteranceHighlighting
200:setHighlightTokenTimer
235:removeWrappers
256:clearHighlightTokenTimer

modules/ext.wikispeech.js
24:enabledForNamespace
37:loadUtterances
76:addControlPanel
131:addButton
143:addStackToPlayStopButton
159:addSpanToPlayStopButton
172:addElementToPlayStopButtonStack
191:addLinkButton
212:playOrStop
227:isPlaying
235:stop
253:play
273:playUtterance
300:audioIsReady
314:addCanPlayListener
327:stopUtterance
351:skipAheadUtterance
368:getNextUtterance
384:getUtteranceByOffset
401:skipBackUtterance
434:getPreviousUtterance
445:skipAheadToken
472:getNextToken
494:getCurrentToken
531:isSilent
543:skipBackToken
570:getPreviousToken
595:getLastToken
609:addKeyboardShortcuts
670:eventMatchShortcut
693:prepareUtterance
757:loadAudio
801:requestTts
844:addTokens
897:addOffsetsAndItems
989:getStartOffsetInUtteranceString

modules/ext.wikispeech.util.js
22:getNodeForItem
46:getLast

First draft of proposed structure:

== ext.wikispeech.main == <-- start point
enabledForNamespace

== ext.wikispeech.ui ==
addControlPanel
addButton
addStackToPlayStopButton
addSpanToPlayStopButton
addElementToPlayStopButtonStack
addLinkButton
addCanPlayListener
addKeyboardShortcuts
eventMatchShortcut
addSelectionPlayer
showSelectionPlayer
getTextDirection

== ext.wikispeech.player ==
playOrStop
isPlaying
stop
play
playUtterance
audioIsReady
stopUtterance
skipAheadUtterance
skipBackUtterance
skipAheadToken
skipBackToken

== ext.wikispeech.selectionPlayer ==
playSelectionIfValid
isSelectionValid
isTextSelected
getFirstNodeInSelection
playSelection
setStartTime
getLastNodeInSelection
setEndTime
resetPreviousEndUtterance

== ext.wikispeech.storage == <--not too happy about this name
loadUtterances
prepareUtterance
loadAudio
requestTts
addTokens
addOffsetsAndItems
getStartOffsetInUtteranceString
getNextUtterance
getUtteranceByOffset
getNextToken
getCurrentToken
isSilent
getPreviousToken
getLastToken
getPreviousUtterance
getFirstTextNode
isNodeInUtterance
getStartUtterance
isPointInItems
getNextTextNode
getStartToken
getLastTextNode
getEndUtterance
getPreviousTextNode
getEndToken

== ext.wikispeech.highlighter ==
highlightUtterance
wrapTextNodes
startTokenHighlighting
highlightToken
getNodeInUtteranceHighlighting
setHighlightTokenTimer
removeWrappers
clearHighlightTokenTimer

== ext.wikispeech.util ==
getNodeForItem
getLast

Change 398851 had a related patch set uploaded (by Sebastian Berlin (WMSE); owner: Sebastian Berlin (WMSE)):
[mediawiki/extensions/Wikispeech@master] Refactor Javascript modules

https://gerrit.wikimedia.org/r/398851

@Lokal_Profil, have you had time to take a look at the status on the patch? There are some comments, but last we spoke about it, it sounded like you hadn't looked at the whole thing.

Haven't looked at this since 2017. IIRC I looked at some of the classes but not all. That said if you are wanting to do a rebase then feel free to do that now since I'll probably have to look at it all with fresh eyes anyway

Change 398851 merged by jenkins-bot:
[mediawiki/extensions/Wikispeech@master] Refactor Javascript modules

https://gerrit.wikimedia.org/r/398851

Stashbot added a subscriber: Stashbot.

Mentioned in SAL (#wikimedia-cloud) [2018-04-13T07:28:34Z] <sebastian-wmse> Deploy latest from Git master: 81fca40 (T149302), 2a69b6b (T182205, T174799)