Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 | 1x 24x 24x 24x 24x 24x 24x 24x 24x 24x 24x 24x 24x 24x 24x 24x 24x 32x 32x 24x 24x 24x 24x 24x 24x 24x 24x 9x 9x 9x 24x 24x 24x 24x 24x 24x 24x 24x 24x 24x 24x 7x 5x 5x 5x 5x 5x 5x 7x 7x 24x 24x 24x 24x 24x 24x 1x 1x 1x 24x 24x 24x 24x 24x 24x 24x 24x 24x 24x 24x 24x 24x 24x 24x 24x 24x 24x 24x 40x 40x 40x 40x 30x 30x 30x 23x 25x 25x 2x 2x 2x 2x 23x 30x 40x 40x 40x 3x 3x 3x 3x 40x 6x 5x 5x 5x 40x 21x 21x 24x 24x 24x 24x 24x 24x 24x 24x 3x 1x 1x 1x 2x 24x 24x 24x 24x 24x 24x 24x 24x 4x 1x 1x 1x 1x 1x 1x 1x 3x 24x 24x 24x 24x 24x 24x 24x 24x 24x 24x 24x 24x 1x 1x 1x 1x 1x | "use strict"
function notice () {
let
scroll = {'*':[]} // General events with their subscribers
, scrollOnce = {} // Single events with their subscribers
, ignore = new Set () // Ignore event names ( general and single )
, debugFlag = false
, debugHeader = ''
;
/**
* Register a regular event.
* @param {string|Symbol} e - Name of the event;
* @param {function} fn - Behaviour that will be assigned to this eventName;
* @returns void
*/
function on ( e, fn ) {
if ( !scroll[e] ) scroll[e] = []
scroll[e].push ( fn )
} // on func.
/**
* Register a single event that will be triggered only once.
* @param {string|Symbol} e - Name of the event; the wildcard '*' is not supported.
* @param {function} fn - Behaviour that will be executed when the event is triggered.
*/
function once ( e, fn ) {
if ( e === '*' ) return // The wildcard '*' doesn't work for 'once' events
if ( !scrollOnce[e] ) scrollOnce[e] = []
scrollOnce[e].push ( fn )
} // once func.
/**
* Remove a behavior (function) related to the specified event.
* If 'fx' is provided, only that specific function will be removed from the event.
* If 'fx' is not provided, all functions related to the event will be removed.
* Works with both regular and single events.
*
* @param {string|Symbol} e - Name of the event.
* @param {function} [fx] - Optional. The specific function to be removed.
*/
function off ( e, fx ) {
if ( fx ) { // fx is optional
if ( scroll[e] ) scroll[e] = scroll[e].filter ( fn => fn !== fx )
if ( scrollOnce[e] ) scrollOnce[e] = scrollOnce[e].filter ( fn => fn !== fx )
if ( scroll[e] && scroll[e].length === 0 ) delete scroll[e]
if ( scrollOnce[e] && scrollOnce[e].length === 0 ) delete scroll[e]
return
}
if ( scrollOnce[e] ) delete scrollOnce[e]
if ( scroll[e] ) delete scroll[e]
} // off func.
/**
* Resets all event-related data structures.
* Clears all general and single event subscriptions, as well as the ignore list.
*/
function reset () {
scroll = {'*':[]}
scrollOnce = {}
ignore = new Set ()
} // reset func.
/**
* Enables or disables debug mode.
* In debug mode, every triggered event prints a message to the console, including the event name and arguments.
* The header argument is optional and can be used to provide a prefix string for the debug message.
* @param {boolean} val - Enable or disable debug mode.
* @param {string} [header] - Optional. The header string for the debug message.
* @returns void
*/
function debug ( val, header ) {
debugFlag = val ? true : false
if ( header && (typeof header === 'string') ) debugHeader = header
} // debug func.
/**
* Triggers an event and executes all associated functions.
*
* @param {string|Symbol} e - Name of the event to be triggered.
* @param {...*} [args] - Optional. Arguments to be passed to the callback functions.
* @returns void
*/
function emit () {
const [ e, ...args ] = arguments
if ( debugFlag ) {
console.log ( `${debugHeader} Event "${e}" was triggered.`)
if ( args.length > 0 ) {
console.log ( 'Arguments:')
console.log ( ...args )
console.log ( '^----' )
}
}
function exeCallback ( name ) {
let stopped = false;
if ( name === '*' ) return
if ( ignore.has(name) ) return
scroll[name].every ( fn => {
const r = fn ( ...args );
if ( typeof(r) !== 'string' ) return true
if ( r.toUpperCase() === 'STOP' ) {
stopped = true
return false
}
return true
})
if ( !stopped ) scroll['*'].forEach ( fn => fn(e,...args) )
} // exeCallback func.
if ( e === '*' ) { // The wildcard '*' doesn't work for 'once' events
let evNames = Object.keys ( scroll )
evNames.forEach ( name => exeCallback(name) )
return
}
if ( scrollOnce[e] ) {
if ( ignore.has(e) ) return
scrollOnce[e].forEach ( fn => fn(...args) )
delete scrollOnce[e]
}
if ( scroll[e] ) {
exeCallback ( e )
}
} // emit func.
/**
* Enables again specified event.
*
* @param {string|Symbol} e - Name of the event to be enabled again; the wildcard '*' is supported.
* @returns void
*/
function start ( e ) {
if ( e === '*' ) {
ignore.clear ()
return
}
ignore.delete ( e )
} // start func.
/**
* Temporarily disables specified event.
*
* @param {string|Symbol} e - Name of the event to be disabled; the wildcard '*' is supported.
* @returns void
*/
function stop ( e ) {
if ( e === '*' ) {
const
evNames = Object.keys ( scroll )
, evOnceNames = Object.keys ( scrollOnce )
;
ignore = new Set ([ ...evOnceNames, ...evNames ])
return
}
ignore.add ( e )
} // stop func.
return {
on // Register a event
, once // Register a single event
, off // Unregister regular and single events
, reset // Unregister all events
, emit // Trigger a event
, stop // Ignore event for a while
, start // Remove event from ignore list
, debug
}
} // notice func.
export default notice
|