Plugin for writing HTMLAREA controls: Classic Tutorial

xiaoxiao2021-03-05  28

HTMLAREA is a powerful WysiwyG HTML editor. Its power is not only reflected in its functionality and maturity, but also reflects that it provides developers with a flexible architecture to write your own plugins! Below will be explained by an actual example to explain the development process of the plugin.

1 First create a directory for your plugin in its plugin directory, such as FormControl, the role of this plugin is inserted into the HTML form element in the page. In this case, we only implement the simplest text input box insertion.

2 Next, create a Form-Control.js file.

// Object That Will Insert Form Control INTO HTMLAREA-3.0 Function FormControl (Editor) {this.Editor = Editor

Var cfg = editor.config; var tt = formControl.i18n; var bl = formcontrol.btnlist; var self = this;

// register the Toolbar Buttons Provided by this plugin var Toolbar = ["linebreak";

For (VAR I IN BL) {var btn = BL [I]; if (! btn) {Toolbar.push ("separator");} else {var ID = "to-" btn [0]; cfg.registerButton (id, tt [id], editor.imgurl (btn [0] ".gif", "formControl", false, function (editor, id) {// dispatch button press Event self.ButtonPress (Editor, ID) ;}); Toolbar.push (ID);}}

// Add a new line in the Toolbar cfg.toolbar.push (toolbar);

FormControl._plugininfo = {name: "formControl", Version: "1.0", developer: "daniel summer", developer_url: "http://www.exoplatform.com", c_owner: "Daniel Summer", Sponsor: "EXO Platform SARL ", sponsor_url:" http://www.exoplatform.com ", license:" htmlarea "};

FormControl.Prototype.ButtonPress = function (editor, button_id) {this.EDitor = editor; var mozbr = htmlarea.is_gecko? "
": "; var i18n = formControl.i18n;

switch (button_id) {case "TO-insert-input": this._insertInput (editor); break; case "insertCombo":}} // this function requires the file PopupDiv / PopupWin to be loaded from browser // Called when the user clicks the Insert Input buttonFormControl.prototype._insertInput = function (editor) {var sel = editor._getSelection (); var range = editor._createRange (sel); var editor = editor; // for nested functions editor._popupDialog ( " INSERT_INPUT.HTML ", Function (param) {if (!) {i (!) {}} var doc = Editor._doc; // Create The Table Element var Input = Doc.createElement (" Input " ); // assign the given arguments for (var value = param [field]; if (! Value) {Continue;} switch (field) {copy "f_name": input.name = value; Break }}} If (htmlarea.is_ie) {range.pastehtml;} else {// INSERT The INPUT Editor.insertNodeation (Input);} return true;}, NULL);

FormControl.btnlist = [// Basic Controls ["Insert-Input"], NULL, // Separator

// Macro Controls ["Insert-Date"]

];

3 Next to build a resource file for en.js in the LANG directory

FormControl.I18N = {// Items that appear in menu. Please note that an underscore (_) // character in the translation (right column) will cause the following // letter to become underlined and be shortcut for that menu option.

"To-Insert-Input": "INSERT INSERT", "To-Insert-Date": "Insert Date Macro", Dialogs: {"You Must Enter The Name of the Input Field": "You Must Enter the name of the name of there INPUT FIELD "}}; 4 to establish two pictures, put in IMG directory insert-date.gif insert-input.gif

5 Enclose Insert_input.html in the popups directory

INSERT / MODIFY LINK </ Title> <script type = "text / javascript" src = "popup.js"> </ script> <script type = "text / javascript"> WINDOW.RESIZETO (400 200);</p> <p>I18n = window.opener.formControl.i18n.dialogs;</p> <p>Function I18N (STR) {RETURN (I18N [Str] || STR);</p> <p>Function officechanged () {var f = document.getlementByid ("f_other_target"); if (this.Value == "_oud") {f.style.visibility = "visible"; f.select (); f.focus () } Else f.style.visibility = "hidden";</p> <p>function Init () {__dlg_translate (I18N); __dlg_init (); var param = window.dialogArguments; document.getElementById ( "f_name") focus ();. document.getElementById ( "f_name") select ();.};</p> <p>Function onok () {var required = {"f_name": i18n ("You Must Enter the name of the input field")}}; for (var i in required) {var = document.getlementByid (i); if (! El.Value) {Alert (Required [i]); el.focus (); return false;}} // Pass data back to the calling window var fields = ["f_name"]; var param = new object (); For (VAR i in fields) {var ID = fields [i]; var = document.getlementById (ID); param [id] = el.value;} __dlg_close (param); return false;}; function oncancel () {__Dlg_close (null); returnaf;</p> <p></ script></p> <p><style type = "text / css"> HTML, Body {Background: Buttonface; Color: ButtonText; Font: 11px Tahoma, Verdana, Sans-Serif; Margin: 0px; Padding: 0px;} Body {Padding: 5px;} Table {FONT: 11PX Tahoma, Verdana, Sans-Serif;} SELECT, INPUT, Button {Font: 11px Tahoma, Verdana, Sans-Serif;} button {width: 70px;} Table .Label {text-align: Right; Width: 8EM;</p> <p>.title {background: #ddf; color: # 000; font-weight: bold; font-size: 120%; Padding: 3px 10px; margin-bottom: 10px; border-bottom: 1px solid black; letter-spacing: 2px }</p> <p>#buttons {margin-top: 1em; border-top: 1px solid # 999; padding: 2px; text-align: right;} </ stop></p> <p></ hEAD></p> <p><body οnlοad = "init ()> <div class =" title "> INSERT INPUT </ DIV></p> <p><table border = "0" style = "width: 100%;"> <tr> <td class = "label"> name: </ td> <td> <input type = "text" id = "f_name" style = "Width: 100%" /> </ td> </ tr> </ table></p> <p><div id = "buttons"> <button type = "button" name = "οnclick =" Return (); "> OK </ button> <button type =" button "name =" ca Zan "οnclick =" Return oncancel (); "> Cancel </ button> </ div> </ body> </ html></p> <p>6 Create a test file in an example directory</p> <p>Add the following code in the corresponding position</p> <p><script type = "text / javascript"> HTMLAREA.LOADPLUGIN ("formControl"); var editor = null; function inIniteditor () {editor = new htmlarea ("ta");</p> <p>// register the formcontrol plugin with ou editor editor.registerplugin ("formcontrol");</p> <p>So far, the entire plugin can work normally. This is just a form of development plug-ins, and you can override the function of the original button. Or refer to the plugin itself to understand the more complex plug-in writing method.</p></div><div class="text-center mt-3 text-grey"> 转载请注明原文地址:https://www.9cbs.com/read-36376.html</div><div class="plugin d-flex justify-content-center mt-3"></div><hr><div class="row"><div class="col-lg-12 text-muted mt-2"><i class="icon-tags mr-2"></i><span class="badge border border-secondary mr-2"><h2 class="h6 mb-0 small"><a class="text-secondary" href="tag-2.html">9cbs</a></h2></span></div></div></div></div><div class="card card-postlist border-white shadow"><div class="card-body"><div class="card-title"><div class="d-flex justify-content-between"><div><b>New Post</b>(<span class="posts">0</span>) </div><div></div></div></div><ul class="postlist list-unstyled"> </ul></div></div><div class="d-none threadlist"><input type="checkbox" name="modtid" value="36376" checked /></div></div></div></div></div><footer class="text-muted small bg-dark py-4 mt-3" id="footer"><div class="container"><div class="row"><div class="col">CopyRight © 2020 All Rights Reserved </div><div class="col text-right">Processed: <b>0.029</b>, SQL: <b>9</b></div></div></div></footer><script src="./lang/en-us/lang.js?2.2.0"></script><script src="view/js/jquery.min.js?2.2.0"></script><script src="view/js/popper.min.js?2.2.0"></script><script src="view/js/bootstrap.min.js?2.2.0"></script><script src="view/js/xiuno.js?2.2.0"></script><script src="view/js/bootstrap-plugin.js?2.2.0"></script><script src="view/js/async.min.js?2.2.0"></script><script src="view/js/form.js?2.2.0"></script><script> var debug = DEBUG = 0; var url_rewrite_on = 1; var url_path = './'; var forumarr = {"1":"Tech"}; var fid = 1; var uid = 0; var gid = 0; xn.options.water_image_url = 'view/img/water-small.png'; </script><script src="view/js/wellcms.js?2.2.0"></script><a class="scroll-to-top rounded" href="javascript:void(0);"><i class="icon-angle-up"></i></a><a class="scroll-to-bottom rounded" href="javascript:void(0);" style="display: inline;"><i class="icon-angle-down"></i></a></body></html><script> var forum_url = 'list-1.html'; var safe_token = 'a_2FdOUjOXiMa2Pv5h6QAg1UWik6vEvqSYK4ZtzmCXklgkKrY1VBgF2YGt7fpGrrIrzT3ZbNRsILwq9J4itrUo_2BA_3D_3D'; var body = $('body'); body.on('submit', '#form', function() { var jthis = $(this); var jsubmit = jthis.find('#submit'); jthis.reset(); jsubmit.button('loading'); var postdata = jthis.serializeObject(); $.xpost(jthis.attr('action'), postdata, function(code, message) { if(code == 0) { location.reload(); } else { $.alert(message); jsubmit.button('reset'); } }); return false; }); function resize_image() { var jmessagelist = $('div.message'); var first_width = jmessagelist.width(); jmessagelist.each(function() { var jdiv = $(this); var maxwidth = jdiv.attr('isfirst') ? first_width : jdiv.width(); var jmessage_width = Math.min(jdiv.width(), maxwidth); jdiv.find('img, embed, iframe, video').each(function() { var jimg = $(this); var img_width = this.org_width; var img_height = this.org_height; if(!img_width) { var img_width = jimg.attr('width'); var img_height = jimg.attr('height'); this.org_width = img_width; this.org_height = img_height; } if(img_width > jmessage_width) { if(this.tagName == 'IMG') { jimg.width(jmessage_width); jimg.css('height', 'auto'); jimg.css('cursor', 'pointer'); jimg.on('click', function() { }); } else { jimg.width(jmessage_width); var height = (img_height / img_width) * jimg.width(); jimg.height(height); } } }); }); } function resize_table() { $('div.message').each(function() { var jdiv = $(this); jdiv.find('table').addClass('table').wrap('<div class="table-responsive"></div>'); }); } $(function() { resize_image(); resize_table(); $(window).on('resize', resize_image); }); var jmessage = $('#message'); jmessage.on('focus', function() {if(jmessage.t) { clearTimeout(jmessage.t); jmessage.t = null; } jmessage.css('height', '6rem'); }); jmessage.on('blur', function() {jmessage.t = setTimeout(function() { jmessage.css('height', '2.5rem');}, 1000); }); $('#nav li[data-active="fid-1"]').addClass('active'); </script>