This example demonstrates how to add visible and draggable handles to D3’s d3.svg.brush component, rather than that relying on the invisible boundary of the brush extent. The handle sizes here are exaggerated for demonstration purposes!
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| function toJSON(node) { | |
| let propFix = { for: 'htmlFor', class: 'className' }; | |
| let specialGetters = { | |
| style: (node) => node.style.cssText, | |
| }; | |
| let attrDefaultValues = { style: '' }; | |
| let obj = { | |
| nodeType: node.nodeType, | |
| }; | |
| if (node.tagName) { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /** | |
| * Split a string into chunks of the given size | |
| * @param {String} string is the String to split | |
| * @param {Number} size is the size you of the cuts | |
| * @return {Array} an Array with the strings | |
| */ | |
| function splitString (string, size) { | |
| var re = new RegExp('.{1,' + size + '}', 'g'); | |
| return string.match(re); | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| var arr = ['abc', 'ab<', 'a<b', 'a>b', '>ab', 'a >>b', '<<ab>> ', '<scr>i<<pt>']; | |
| arr.map(function (item, index) { | |
| console.log(index, item, item.replace(/(\s*<+\s*|\s*>+\s*)/g, function (arg) { | |
| return (/^\S/.test(arg) ? ' ' : '') + arg + (/\S$/.test(arg) ? ' ' : ''); | |
| })); | |
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /* | |
| * Easing Functions - inspired from http://gizma.com/easing/ | |
| * only considering the t value for the range [0, 1] => [0, 1] | |
| */ | |
| EasingFunctions = { | |
| // no easing, no acceleration | |
| linear: function (t) { return t }, | |
| // accelerating from zero velocity | |
| easeInQuad: function (t) { return t*t }, | |
| // decelerating to zero velocity |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| (function() { | |
| var beforePrint = function() { | |
| console.log('Functionality to run before printing.'); | |
| }; | |
| var afterPrint = function() { | |
| console.log('Functionality to run after printing'); | |
| }; | |
| if (window.matchMedia) { | |
| var mediaQueryList = window.matchMedia('print'); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| function NameSpace(arg){ | |
| var root= this, | |
| arr, | |
| nodePath=[]; | |
| // check arg | |
| if(typeof arg !=='string' || /^([a-z_$][0-9a-z_$]*\.)*[a-z_$][0-9a-z_$]*$/gi.test(arg)==false){ | |
| console.error( "Invalid argument", arg) | |
| return; | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // Error message format | |
| { | |
| "success": false, | |
| "messageKey": "user_name_error", | |
| "message": [ // Not required, if provided, will show this message to user | |
| {type:"success", text:"task 1 done success"}, | |
| {type:"error", text:"task 2 failed"}, | |
| ], | |
| "mayRetry":false | |
| } |