From 4f727a59bcee3ec91520449638dab48bfb6d7d37 Mon Sep 17 00:00:00 2001 From: atomiks Date: Fri, 5 Jan 2018 23:33:48 +1100 Subject: [PATCH 1/8] Add event utils --- snippets/off.md | 16 ++++++++++++++++ snippets/on.md | 25 +++++++++++++++++++++++++ tag_database | 2 ++ 3 files changed, 43 insertions(+) create mode 100644 snippets/off.md create mode 100644 snippets/on.md diff --git a/snippets/off.md b/snippets/off.md new file mode 100644 index 000000000..6c3764ae0 --- /dev/null +++ b/snippets/off.md @@ -0,0 +1,16 @@ +### off + +Removes an event listener from an element. + +Use `EventTarget.removeEventListener()` to remove an event listener to an element. + +```js +const off = (el, evt, fn, opts = false) => el.removeEventListener(evt, fn, opts); +``` + +```js +// See the `on` snippet. +const fn = () => console.log('!'); +const ref = on(document.body, 'click', fn, { target: 'p' }); +off(document.body, 'click', ref); // no longer logs '!' upon clicking a `p` el child of the body +``` diff --git a/snippets/on.md b/snippets/on.md new file mode 100644 index 000000000..c8fa6ee20 --- /dev/null +++ b/snippets/on.md @@ -0,0 +1,25 @@ +### on + +Adds an event listener to an element with the ability to use event delegation. + +Use `EventTarget.addEventListener()` to add an event listener to an element. If there is a +`target` property supplied to the options object, ensure the event target matches the +target specified and then invoke the callback by supplying the correct `this` context. +Use `options` to pass options to `addEventListener` or omit it to use bubbling by default. +In order to use this function with `off`, the reference to the custom delegator function +is returned if the `target` option is specified. + +```js +const on = (el, evt, fn, opts = {}) => { + const delegatorFn = e => e.target.matches(opts.target) && fn.call(e.target, e); + el.addEventListener(evt, opts.target ? delegatorFn : fn, opts.options || false); + if (opts.target) return delegatorFn; +}; +``` + +```js +const fn = () => console.log('!'); +on(document.body, 'click', fn); // logs '!' upon clicking the body +on(document.body, 'click', fn, { target: 'p' }); // logs '!' upon clicking a `p` element child of the body +on(document.body, 'click', fn, { options: true }); // use capturing instead of bubbling +``` diff --git a/tag_database b/tag_database index dc0014097..0a8812040 100644 --- a/tag_database +++ b/tag_database @@ -108,6 +108,8 @@ negate:logic nthElement:array objectFromPairs:object objectToPairs:object +off:browser +on:browser once:function onUserInputChange:browser orderBy:object From acf68012ad66748a44731146836cc7f9614b6c48 Mon Sep 17 00:00:00 2001 From: atomiks Date: Fri, 5 Jan 2018 23:36:02 +1100 Subject: [PATCH 2/8] fix typo --- snippets/off.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/snippets/off.md b/snippets/off.md index 6c3764ae0..63f70419f 100644 --- a/snippets/off.md +++ b/snippets/off.md @@ -2,7 +2,7 @@ Removes an event listener from an element. -Use `EventTarget.removeEventListener()` to remove an event listener to an element. +Use `EventTarget.removeEventListener()` to remove an event listener from an element. ```js const off = (el, evt, fn, opts = false) => el.removeEventListener(evt, fn, opts); From 428f4ec8ff1e7904f7dc2170fccd4b1771aebdbc Mon Sep 17 00:00:00 2001 From: atomiks Date: Sat, 6 Jan 2018 02:59:00 +1100 Subject: [PATCH 3/8] Update tag_database --- tag_database | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tag_database b/tag_database index 0a8812040..247ab82c4 100644 --- a/tag_database +++ b/tag_database @@ -108,8 +108,8 @@ negate:logic nthElement:array objectFromPairs:object objectToPairs:object -off:browser -on:browser +off:browser,utility +on:browser,utility once:function onUserInputChange:browser orderBy:object From 517aaa78c1395581a49d573b78b701f882c20760 Mon Sep 17 00:00:00 2001 From: atomiks Date: Sat, 6 Jan 2018 03:00:03 +1100 Subject: [PATCH 4/8] Update off.md --- snippets/off.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/snippets/off.md b/snippets/off.md index 63f70419f..71cbd7b3b 100644 --- a/snippets/off.md +++ b/snippets/off.md @@ -2,7 +2,7 @@ Removes an event listener from an element. -Use `EventTarget.removeEventListener()` to remove an event listener from an element. +Use `EventTarget.removeEventListener()` to remove an event listener from an element. Omit the fourth argument `opts` to use `false` or specify it based on the options used when the event listener was added. ```js const off = (el, evt, fn, opts = false) => el.removeEventListener(evt, fn, opts); From 81bfc987923094bcdd29c1b40751b2fe63954b13 Mon Sep 17 00:00:00 2001 From: atomiks Date: Sat, 6 Jan 2018 03:01:08 +1100 Subject: [PATCH 5/8] Update on.md --- snippets/on.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/snippets/on.md b/snippets/on.md index c8fa6ee20..f25404d3a 100644 --- a/snippets/on.md +++ b/snippets/on.md @@ -7,7 +7,8 @@ Use `EventTarget.addEventListener()` to add an event listener to an element. If target specified and then invoke the callback by supplying the correct `this` context. Use `options` to pass options to `addEventListener` or omit it to use bubbling by default. In order to use this function with `off`, the reference to the custom delegator function -is returned if the `target` option is specified. +is returned if the `target` option is specified. Omit `opts` to default to non-delegation +behavior and event bubbling. ```js const on = (el, evt, fn, opts = {}) => { From 4b4ed5c7ed8b7a69ae95189fcee40c0509a24e63 Mon Sep 17 00:00:00 2001 From: Angelos Chalaris Date: Fri, 5 Jan 2018 18:05:23 +0200 Subject: [PATCH 6/8] Update off.md --- snippets/off.md | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/snippets/off.md b/snippets/off.md index 71cbd7b3b..726dca29e 100644 --- a/snippets/off.md +++ b/snippets/off.md @@ -2,15 +2,15 @@ Removes an event listener from an element. -Use `EventTarget.removeEventListener()` to remove an event listener from an element. Omit the fourth argument `opts` to use `false` or specify it based on the options used when the event listener was added. +Use `EventTarget.removeEventListener()` to remove an event listener from an element. +Omit the fourth argument `opts` to use `false` or specify it based on the options used when the event listener was added. ```js const off = (el, evt, fn, opts = false) => el.removeEventListener(evt, fn, opts); ``` ```js -// See the `on` snippet. const fn = () => console.log('!'); -const ref = on(document.body, 'click', fn, { target: 'p' }); -off(document.body, 'click', ref); // no longer logs '!' upon clicking a `p` el child of the body +document.body.addEventListener('click', fn); +off(document.body, 'click', fn); // no longer logs '!' upon clicking on the page ``` From d06c0410bf07b1cb657fc81e9fd5d13311836ac8 Mon Sep 17 00:00:00 2001 From: Angelos Chalaris Date: Fri, 5 Jan 2018 18:07:52 +0200 Subject: [PATCH 7/8] Update on.md --- snippets/on.md | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/snippets/on.md b/snippets/on.md index f25404d3a..64a2478c7 100644 --- a/snippets/on.md +++ b/snippets/on.md @@ -2,13 +2,9 @@ Adds an event listener to an element with the ability to use event delegation. -Use `EventTarget.addEventListener()` to add an event listener to an element. If there is a -`target` property supplied to the options object, ensure the event target matches the -target specified and then invoke the callback by supplying the correct `this` context. -Use `options` to pass options to `addEventListener` or omit it to use bubbling by default. -In order to use this function with `off`, the reference to the custom delegator function -is returned if the `target` option is specified. Omit `opts` to default to non-delegation -behavior and event bubbling. +Use `EventTarget.addEventListener()` to add an event listener to an element. If there is a `target` property supplied to the options object, ensure the event target matches the target specified and then invoke the callback by supplying the correct `this` context. +Returns a reference to the custom delegator function, in order to be possible to use with [`off`](#off). +Omit `opts` to default to non-delegation behavior and event bubbling. ```js const on = (el, evt, fn, opts = {}) => { From 206ebc9ae1b598c3fdc0ace92a3775e53e237ad7 Mon Sep 17 00:00:00 2001 From: Angelos Chalaris Date: Fri, 5 Jan 2018 18:09:44 +0200 Subject: [PATCH 8/8] Update tag_database --- tag_database | 221 ++++++++++++++++++++++++--------------------------- 1 file changed, 105 insertions(+), 116 deletions(-) diff --git a/tag_database b/tag_database index 247ab82c4..099c08007 100644 --- a/tag_database +++ b/tag_database @@ -1,188 +1,177 @@ -anagrams:string -arrayToHtmlList:browser -average:math +anagrams:string,recursion +arrayToHtmlList:browser,array +average:math,array bottomVisible:browser byteSize:string -call:adapter -capitalize:string -capitalizeEveryWord:string +call:adapter,function +capitalize:string,array +capitalizeEveryWord:string,regexp chainAsync:function chunk:array clampNumber:math -cleanObj:object -cloneRegExp:utility +cleanObj:object,json +cloneRegExp:utility,regexp coalesce:utility coalesceFactory:utility -collatz:math -collectInto:adapter +collectInto:adapter,function,array compact:array compose:function -copyToClipboard:browser +copyToClipboard:browser,string,advanced countOccurrences:array countVowels:string -currentURL:browser -curry:function -deepFlatten:array +currentURL:browser,url +curry:function,recursion +deepFlatten:array,recursion defer:function detectDeviceType:browser -difference:array -differenceWith:array -digitize:math +difference:array,math +differenceWith:array,function +digitize:math,array distance:math distinctValuesOfArray:array -dropElements:array +dropElements:array,function dropRight:array elementIsVisibleInViewport:browser -elo:math -escapeHTML:string -escapeRegExp:string +elo:math,array,advanced +escapeHTML:string,browser,regexp +escapeRegExp:string,regexp everyNth:array -extendHex:utility -factorial:math -factors:math -fibonacci:math -fibonacciCountUntilNum:math -fibonacciUntilNum:math +extendHex:utility,string +factorial:math,recursion +fibonacci:math,array filterNonUnique:array flatten:array -flattenDepth:array -flip:adapter -formatDuration:date +flattenDepth:array,recursion +flip:adapter,function +formatDuration:date,math,string,utility fromCamelCase:string -functionName:function -gcd:math +functionName:function,utility +gcd:math,recursion geometricProgression:math getDaysDiffBetweenDates:date getScrollPosition:browser -getStyle:browser -getType:utility -getURLParameters:utility +getStyle:browser,css +getType:type +getURLParameters:utility,browser,string,url groupBy:array hammingDistance:math -hasClass:browser +hasClass:browser,css hasFlags:node head:array -hexToRGB:utility -hide:browser -howManyTimes:math -httpsRedirect:browser +hexToRGB:utility,string,math,advanced +hide:browser,css +httpsRedirect:browser,url initial:array initialize2DArray:array -initializeArrayWithRange:array -initializeArrayWithValues:array +initializeArrayWithRange:array,math +initializeArrayWithValues:array,amth inRange:math -intersection:array +intersection:array,math invertKeyValues:object -isAbsoluteURL:string -isArmstrongNumber:math -isArray:utility -isArrayLike:utility -isBoolean:utility +isAbsoluteURL:string,utility,browser,url +isArray:type,array +isArrayLike:type,array +isBoolean:type isDivisible:math isEven:math -isFunction:utility -isNull:utility -isNumber:utility +isFunction:type,function +isNull:type +isNumber:type,math isPrime:math -isPrimitive:utility -isPromiseLike:utility +isPrimitive:type,function,array,string +isPromiseLike:type,function,promise isSorted:array -isString:utility -isSymbol:utility +isString:type,string +isSymbol:type isTravisCI:node -isValidJSON:utility +isValidJSON:type,json join:array -JSONToDate:date -JSONToFile:node +JSONToFile:node,json last:array -lcm:math +lcm:math,recursion lowercaseKeys:object -luhnCheck:math -mapObject:array -mask:string -maxN:array -median:math +luhnCheck:math,utility +mapObject:array,object +mask:string,utility,regexp +maxN:array,math +median:math,array memoize:function -minN:array -negate:logic +minN:array,amth +negate:logic,function nthElement:array -objectFromPairs:object -objectToPairs:object -off:browser,utility -on:browser,utility +objectFromPairs:object,array +objectToPairs:object,array +off:browser,event +on:browser,event once:function -onUserInputChange:browser -orderBy:object +onUserInputChange:browser,event,advanced +orderBy:object,array palindrome:string percentile:math pick:array -pipeFunctions:adapter +pipeFunctions:adapter,function pluralize:string powerset:math -prettyBytes:utility -primes:math -promisify:adapter +prettyBytes:utility,string,math +primes:math,array +promisify:adapter,function,promise pull:array pullAtIndex:array pullAtValue:array -quickSort:array -randomHexColorCode:utility -randomIntegerInRange:math -randomNumberInRange:math -readFileLines:node -redirect:browser +randomHexColorCode:utility,random +randomIntegerInRange:math,utility,random +randomNumberInRange:math,utility,random +readFileLines:node,array,string +redirect:browser,url reducedFilter:array remove:array -repeatString:string -reverseString:string +reverseString:string,array RGBToHex:utility round:math -runAsync:browser -runPromisesInSeries:function -sample:array -sampleSize:array +runAsync:browser,function,advanced,promise,url +runPromisesInSeries:function,promise +sample:array,random +sampleSize:array,random scrollToTop:browser -sdbm:utility +sdbm:math,utility select:object setStyle:browser shallowClone:object -show:browser -shuffle:array -similarity:array -size:object -sleep:function -solveRPN:math +show:browser,css +shuffle:array,random +similarity:array,math +size:object,array,string +sleep:function,promise sortCharactersInString:string -sortedIndex:array -speechSynthesis:browser +sortedIndex:array,math splitLines:string spreadOver:adapter -standardDeviation:math -sum:math +standardDeviation:math,array +sum:math,array sumPower:math -symmetricDifference:array +symmetricDifference:array,math tail:array take:array takeRight:array timeTaken:utility -toCamelCase:string -toDecimalMark:utility -toEnglishDate:date +toCamelCase:string,regexp +toDecimalMark:utility,math +toEnglishDate:date,string toggleClass:browser -toKebabCase:string +toKebabCase:string,regexp tomorrow:date -toOrdinalSuffix:utility -toSnakeCase:string +toOrdinalSuffix:utility,math +toSnakeCase:string,regexp truncateString:string -truthCheckCollection:object -unescapeHTML:string -union:array -untildify:node -UUIDGeneratorBrowser:browser -UUIDGeneratorNode:node -validateNumber:utility +truthCheckCollection:object,logic,array +unescapeHTML:string,browser +union:array,math +untildify:node,string +UUIDGeneratorBrowser:browser,utility,random +UUIDGeneratorNode:node,utility,random +validateNumber:utility,math without:array -words:string -yesNo:utility +words:string,regexp +yesNo:utility,regexp zip:array -zipObject:array +zipObject:array,object