How to use the Bootstrap-wysiwyg text editor, give full play to the editor's advantages, I hope you can have some harvest.
Main Features:
Super Small 5kb
Automatic hotkey Support (Mac and Windows)
Drag and drop Insert picture, support picture upload (support mobile phone photo)
Support for sound input (chrome support)
Allow custom toolbars to use all bootstrap content, fonts
Do not use any of the coerced styles
..............................
In fact, more than this, we need to explore their own, refueling bar!
Use in fact very simple, poured into bootstrap related css,js,jquery, and Bootstrap-wysiwyg JS, as follows:
<link href= "Bootstrap-combined.no-icons.min.css" rel= "stylesheet" >
<link href= " Bootstrap-responsive.min.css "rel=" stylesheet ">
<link href=" http://netdna.bootstrapcdn.com/ Font-awesome/3.0.2/css/font-awesome.css "rel=" stylesheet "> <link rel=" stylesheet "href=" Index.css "type="
"Text/css" > </link>
<script src= "jquery1.9.1.min.js" type= "Text/javascript" ></script>
<script src= "bootstrap.min.js" ></script>
<script src= "bootstrap-wysiwyg.js" type= "text/" JavaScript "></script>
<script src=" external/jquery.hotkeys.js "type=" Text/javascript "></ Script>
Define related menu item properties and methods:
function inittoolbarbootstrapbindings () {var fonts = [' Serif ', ' Sans ', ' Arial ', ' Arial Black ', ' Courier ', ' Courie R New ', ' Comic Sans MS ', ' Helvetica ', ' Impact ', ' Lucida Grande ', ' Lucida Sans ', ' Tahoma ', ' Times ', ' New Roman ', '
Verdana '], Fonttarget = $ (' [Title=font] '). Siblings ('. Dropdown-menu '); $.each (fonts, function (idx, fontname) {fonttarget.append ($ (' <li><a data-edit= ' fontname ' + fontname + ' "Styl
E= "Font-family:\ ' + fontname + '" "> ' +fontname + ' </a></li>");
});
$ (' a[title] '). ToolTip ({container: ' body '});
$ ('. Dropdown-menu input '). Click (function () {return false;})
. Change (function () {$ (this). Parent ('. Dropdown-menu '). Siblings ('. Dropdown-toggle '). Dropdown (' Toggle ');})
. KeyDown (' Esc ', function () {this.value= '; $ (this). change ();});
$ (' [Data-role=magic-overlay] '). each (the function () {var overlay = $ (this), target = $ (overlay.data (' target ')); Overlay.css (' opacity ', 0). css (' position ', ' absolute '). Offset (Target.Offset ()). Width (target.outerwidth ()). Height (target.outerheight ());
});
if ("Onwebkitspeechchange" in Document.createelement ("input")) {var Editoroffset = $ (' #editor '). Offset (); $ (' #voiceBtn '). CSS (' position ', ' absolute '). Offset ({top:editorOffset.top, left:editoroffset.left+$ (' #editor ').
Innerwidth ()-35});
else {$ (' #voiceBtn '). Hide ();
}
};
function Showerroralert (reason, detail) {var msg= ';
if (reason=== ' Unsupported-file-type ') {msg = "unsupported format" +detail;}
else {console.log ("Error uploading file", reason, detail); } $ (' <div class= ' alert ' > <button type= ' button ' class= ' Close ' data-dismiss= ' alert ' >x</button> ' + '
<strong>file upload error</strong> ' +msg+ ' </div> '). Prependto (' #alerts ');
};
Inittoolbarbootstrapbindings ();
$ (' #editor '). WYSIWYG ({fileuploaderror:showerroralert});
Finally, the HTML code:
<div class= "Btn-toolbar" data-role= "Editor-toolbar" data-target= "#editor" > <div class= "Btn-group" > <a class= "btn dropdown-toggle" data-toggle= "dropdown" title= "Font" ><i class= "Icon-font" ></i><b class = "Caret" ></b></a> <ul class= "Dropdown-menu" > </ul> </div> <div class= "btn-gr OUP "> <a class=" btn dropdown-toggle data-toggle= "dropdown" title= "Font Size" ><i class= "Icon-text-height" ></i> <b class= "Caret" ></b></a> <ul class= "Dropdown-menu" > <li><a da ta-edit= "FontSize 5" ><font size= "5" >Huge</font></a></li> <li><a data-edit= " FontSize 3 "><font size=" 3 ">Normal</font></a></li> <li><a data-edit=" FontSize 1 " ><font size= "1" >Small</font></a></li> </ul> </div> <div class= "Btn-group" > <a class= "btn" data-edit= "bold" titlE= "Bold (ctrl/cmd+b)" ><i class= "Icon-bold" ></i></a> <a class= "btn" data-edit= "Italic" title= "Italic (ctrl/cmd+i)" ><i class= "Icon-italic" ></i></a> <a class= "BTN" Strikethrough "title=" strikethrough "><i class=" Icon-strikethrough "></i></a> <a class=" BTN " data-edit= "underline" title= "Underline (ctrl/cmd+u)" ><i class= "Icon-underline" ></i></a> </ div> <div class= "Btn-group" > <a class= "btn" data-edit= "insertunorderedlist" title= "Bullet list" ><i C lass= "Icon-list-ul" ></i></a> <a class= "btn" data-edit= "insertorderedlist" title= "Number List" > <i class= "Icon-list-ol" ></i></a> <a class= "btn" data-edit= "outdent" title= "Reduce indent (shift+ tab) "><i class=" Icon-indent-left "></i></a> <a class=" btn "data-edit=" indent "title=" indent (
tab) "><i class=" Icon-indent-right "></i></a></div> <div class= "Btn-group" > <a class= "btn" data-edit= "Justifyleft" title= "Align Left (ctrl/cmd+l)" &G T;<i class= "Icon-align-left" ></i></a> <a class= "btn" data-edit= "Justifycenter" Center ( ctrl/cmd+e) "><i class=" Icon-align-center "></i></a> <a class=" btn "data-edit=" Justifyright " Title= "Align Right (ctrl/cmd+r)" ><i class= "Icon-align-right" ></i></a> <a class= "BTN"
data-edit= "Justifyfull" title= "Justify (ctrl/cmd+j)" ><i class= "Icon-align-justify" ></i></a> </div> <div class= "Btn-group" > <a class= "btn dropdown-toggle" data-toggle= "dropdown" title= "Hyperlink" ><i class= "Icon-link" ></i></a> <div class= "Dropdown-menu input-append" > <input class= " Span2 "placeholder=" URL "type=" text "data-edit=" Createlink "/>" <button class= "btn" type= "button" >add</ button> </div> <a class= "btn" data-edit= "unlink""Title=" Remove Hyperlink "><i class=" Icon-cut "></i></a> </div> <div class=" Btn-group " > <a class= "btn" title= "Insert picture (or just drag & drop)" id= "picturebtn" ><i class= "Icon-picture" ;</i></a> <input type= "file" data-role= "Magic-overlay" "data-target=" #pictureBtn "data-edit=" Insertimage "/> </div> <div class=" Btn-group "> <a class=" btn "data-edit=" undo "title=" Undo (ctrl/c md+z) "><i class=" Icon-undo "></i></a> <a class=" btn "data-edit=" Redo "title=" Redo (ctrl/cmd+y ) "><i class=" icon-repeat "></i></a> </div> <input type=" text "data-edit=" InsertText "id
= "Voicebtn" x-webkit-speech= "" > </div> <div id= "editor" > Input ... </div>
If you want to further study, you can click here to learn, and then attach a wonderful topic: Bootstrap Learning Course
The above is the entire content of this article, I hope to help you learn, but also hope that we support the cloud habitat community.