javascript - wysihtml5 - how disable underline tag -


i have small problem wysihtml5 on site. want allow few html tags , if remove underline parser rules , underline command wysihtml5 library, can still press ctrl(command)+u make selected text underlined. should rid of behaviour? advices.

new answer: here updated solution. updated existing keydown event handler (and added keyup handler tracking ctrl pressed state) follows:

// --------- shortcut logic --------- var ctrldown = 0;  dom.observe(element, "keydown", function(event) {   var keycode  = event ? event.which : window.event.keycode,     command    = shortcuts[keycode];   if (1 == event.ctrlkey) {     console.log('ctrl key pressed. setting ctrldown = 1.');     ctrldown = 1;   }   if (85 == keycode && 1 == ctrldown) {     console.log('pressed "u" (keycode 85), ctrl key still down. don\'t fire!');     return event.preventdefault(), !1;   }   if (1 == ctrldown && !event.altkey && command) {     console.log('shortcut ctrl + keycode ' + keycode + ' triggered.');     that.commands.exec(command), event.preventdefault();   } });  dom.observe(element, "keyup", function(event) {   // note: "event.ctrlkey" doesn't work keyup, use keycode/which    if (17 == (event ? event.which : window.event.keycode)) {     console.log('ctrl key released. setting ctrldown = 0.');     ctrldown = 0;   } }); 

i sent a pull request @ github.


original answer: needed do, disable ctrl+u keyboard shortcut, remove keycode "u" (85) shortcuts object @ line 8494 in wysihtml5-0.4.0pre.js.

change

  shortcuts = {     "66": "bold",     // b     "73": "italic",   //     "85": "underline" // u   }; 

to

  shortcuts = {     "66": "bold",     // b     "73": "italic"    //   }; 

and no longer able use ctrl+u shortcut within editor.

alternatively, catch keydown events , disable ctrl+u shortcut (ie. prevent default behaviour). like:

// --------- disable ctrl+u shortcut underlining texts --------- dom.observe(element, "keydown", function(event) {   if ((event.ctrlkey || event.metakey) && 'u' == string.fromcharcode(event.which).tolowercase()) {     //   }        }); 

Comments

Popular posts from this blog

node.js - Bad Request - node js ajax post -

Why does Ruby on Rails generate add a blank line to the end of a file? -

keyboard - Smiles and long press feature in Android -