You are here

README.txt in BUEditor 5

Same filename in this branch
  1. 5 README.txt
  2. 5 library/README.txt
Same filename and directory in other branches
  1. 8.2 README.txt
  2. 8 README.txt
  3. 6.2 README.txt
  4. 6 README.txt
  5. 7 README.txt
- BUEditor:
A plain textarea editor aiming to facilitate code writing.
The most important feature of this editor is its highly customizable functionality.
It's possible to add image and text buttons whose functions are determined by the user.
Buttons can be customized to generate code snippets, html tags, bbcode tags etc.


- HOW TO INSTALL:
1) Copy editor directory to your modules directory.
2) Enable the module at module administration page.
3) Add/edit editors and buttons at: admin/settings/bueditor.
4) There is the default editor you can use as a starting point.
5) You may install IMCE module to use it as a file/image browser in editor's image & link dialogs.


- EXPORTING AND DELETING BUTTONS:
You should first select the buttons you want to export or delete, using checkboxes next to them.
Then select the action you want to take in the selectbox below the list and press GO.


- ADDING BUTTONS:
You can add buttons to an editor by two methods;
1- Manually entering the values for new button fields located at the bottom of the button list.
2- Importing a CSV file that contains previously exported buttons.


- BUTTON PROPERTIES
TITLE:(required) Title or name of the button. Displayed as a hint on mouse over. A title can be translated
by prefixing it with "t:". Ex: t:Bold turns into t('Bold')
CONTENT: Html or javascript code that is processed when the button is clicked. This can also be
php code that is pre evaluated and return html or javascript code. See BUTTON TYPES.
ICON: Image or text to display the button.
KEY: Accesskey that is supported by some browsers as a shortcut on web pages. With the right
key combinations users can fire the button's click event. Use Alt+KEY in Internet Explorer, and
Shift+Alt+KEY in Firefox.
WEIGHT: Required for sorting the buttons. Line-up is from the lightest to heaviest.


- BUTTON TYPES
There are three types of buttons regarding the CONTENT property;
1- HTML BUTTONS 
2- JAVASCRIPT BUTTONS 
3- PHP BUTTONS


- HTML BUTTONS
These are used for directly inserting plain text or html into the textarea.
It is possible to use the selected text in the textarea by using the place holder %TEXT%
For example, assume that the button content is:
<p>%TEXT%</p>
and it is clicked after selecting the "Hello world!" text in the textarea. Then the result is:
<p>Hello world!</p>
with the selection preserved.
Multiple occurances of %TEXT% is possible and each will be replaced by the selected text. 
These type of buttons are useful for simple html tags or other tag systems like BBCode.
Note: if you want to insert some text containing the phrase %TEXT%, use a javascript button.


- JAVASCRIPT BUTTONS
The content of a javascript button must begin with a 3 charater text "js:" to be differentiated from a
html button. The remaining code is treated as a javascript code and executed in a function when the
button is clicked. These type of buttons are used for special cases where it is insufficient to just replace the 
selected text.
Editor has many ready-to-use methods and variables making it easier to create javascript buttons.
See EDITOR VARIABLES AND METHODS and especially EDITOR INSTANCE variables and methods.


- PHP BUTTONS
The content of a php button must begin with "php:". The remaining code is pre evaluated at the server 
side and expected to return some code. According to the return value of the php code the real type of 
the button is determined. If the php code returns nothing or false, the button is disabled and does not
show up in the editor.
A php button is indeed a html or javascript button. Php execution is for some special purposes. For example,
it is possible to disable or change the content of the button for a specific user role;
Button with content
php: 
if (user_access('access foo')) {
  return 'js: alert("You have the permission to access foo")';
}
turns into a javascript button having the returned content for users having "access foo" permission. for others 
it is disabled and doesnt show up.


- EDITOR VARIABLES
editor:
the top most container variable having other variables and methods in it.

editor.active:
currently active or last used editor istance. When a button is clicked or a textarea is focused, 
the corresponding editor instance becomes the editor.active. If there are multiple editor instances, accesskeys 
are switched to work on the editor.active.
editor.active is widely used in javascript buttons since the methods of the current editor instance are accessed 
using it. Each editor instance has its own variables and methods that can(should) be used by javascript buttons. 
See EDITOR INSTANCE

editor.dialog:
dialog object of the editor used like a pop-up window for getting user input or displaying data.
It has its own variables and methods. See EDITOR DIALOG


- EDITOR METHODS
editor.processTextarea(T):
integrates the editor into the textarea T. This can be used for dynamic editor integration at any time after page load.

editor.openPopup(id, title, content):
opens a pop-up dialog having the given "id", titled as "title" and containing the "content". Returns the js object
representing the pop-up(a html table object).
This pop-up object has its internal "open(title, content, keeppos)" and "close()" methods which can be used for 
further open and close operations. if "keeppos" is set, pop-up opens at previos position, otherwise position is reset.
Since pop-up object is a html table object, it has all the methods and properties of a regular table.
The difference between a pop-up and editor.dialog is that editor.dialog can only have one instance visible at a time,
and it doesnt allow textarea editing when it is open.

editor.createPopup(id, title, content):
This method is used by openPopup method. Creates and returns the pop-up object for further use.(does not open it)


- EDITOR INSTANCE (a must-read for javascript button creators)
Each editor running on the page for a textarea is called an instance. Editor instances have their own variables 
and methods that make it easy to edit textarea content. Active instance on the page can be accessed by the 
variable "editor.active".

Lets assume that we assigned editor.active to a variable E  in our js button's content(actually we dont need this
anymore since the button function is now called with the parameter E).
Here are the VARIABLES of the istance E:

E.textArea: textarea of the instance as an HTML object.
E.buttons: indexed array of buttons of the instance as HTML objects(input objects, type is button or image)
E.bindex: latest/currently clicked button index that can be used in E.buttons. Ex: E.buttons[E.bindex]

Here are the METHODS of the instance E:

E.focus():
Focus on the textarea of the instance.

E.getContent():
Returns the content of the textarea.

E.setContent(text):
Replaces the content of the textarea with the given text.

E.getSelection():
Returns the selected text in the textarea.

E.replaceSelection(text, cursor):
Replace the selected text in the textrea with the given text.
The optinal second argument specifies the position of the caret after replacement.
if cursor='start', it is placed at the begining of the replaced text.
if cursor='end', it is placed at the end of the replaced text.
if cursor is not defined, the selection is preserved containing the replaced text.

E.tagSelection(left, right, cursor):
Encloses the selected text in the textarea with the given left and right texts.
The optional third argument specifies the position of the caret after enclosing.
if cursor='start', it is placed at the begining of the selected text.
if cursor='end', it is placed at the end of the selected text.
if cursor is not defined, the selection is preserved.

E.makeSelection(start, end):
Create a selection by selecting the characters between the indexes "start" and "end".

E.posSelection():
Returns the index values of selection start and selection end.
Returns {start: X, end: Y} where X is the start index and Y is the end index.
Note: No selection is also a selection where start=end=caret position.

E.buttonsDisabled(state, bindex):
Dynamically enable/disable buttons of the instance.
the first argument defines the state of the buttons and should be set to true or false.
the optional second argument defines the index of the button whose state will not change.
Ex: to disable all buttons except the pressed button;
js: E.buttonsDisabled(true, E.bindex);


- EDITOR DIALOG
Editor dialog is an object shared by all editor instances. It can be used to display any kind of data, ie. a html form
to get some user input. 
Here are the methods of editor dialog

editor.dialog.open(title, content):
Opens the dialog with the given title and content in it.

editor.dialog.close():
Closes the dialog.


- EDITOR ICONS
Icons are stored in "icons" folder of the editor. You can put additional icons into this folder to make them visible
in the icon list in the editor edit page.


- EDITOR LIBRARY
While creating a javascript button you may want to use functions or variables from an external javascript library, 
in order to shorten the content text and make it clean. In this case, you should place your javascript library inside 
the "library" folder of the editor. The .js files in this directory will be automatically loaded together with the editor. 
Note that library/...js files are common and are loaded for every editor you define.
In case you want a library file to be loaded for only a specific editor, you should create a sub-folder under library 
directory, which has the same name as the editor. For example, library/editorFoo/...js files will only be loaded 
for the editor having the name "editorFoo".


- EDITOR TEMP DIRECTORY
After starting to use the editor, you might notice that an extra folder named as bueditor in system file directory is 
created. This directory is used to store javascript files that contain buttons of your editors. Including them in a file 
instead of including them inline, allows browser caching and reduces page load time.
Since buttons may have php code that makes them change dynamically, md5 is used to track the changes in buttons 
script. If there is a matching file in the folder, it is loaded. Otherwise, a new file is created and loaded. If file loading 
fails, buttons are included as inline script.
Note: Files older than 15 days are cleaned in each cron run.
If download method is PRIVATE, buttons are always included inline.


- KNOWN ISSUES
Accesskeys in Internet Explorer:
Pressing an accesskey(Alt+KEY) when there is a selection, deselects it with preserving the caret position.

Accesskeys in Firefox:
If there are multiple editors in the page, accesskeys(Shift+Alt+KEY) will work on only the first editor instance. 
This is becouse FF does not allow dynamic adjustment of accesskeys.

New line character:
Since new line is represented by different characters (\r, \r\n, \n) on different platforms, there may be some 
unexpected behaviour of the editor in some platform-browser combos regarding the cursor position after text 
insertion/replacement. Specify new line characters as "\n", if you have to use any in your scripts.

POST variable limit:
Although it's a rare case, consider increasing your server post variable limit if you have problems while adding too many buttons.


- DEFAULT BUTTONS
BUEditor comes with a few default buttons that may help you extend the editor:

Insert/edit image:
Inserts image html after getting the src, width, height, alt attributes from the user. If IMCE module is installed, 
and the user has access to it, a Browse button will appear linking to IMCE image browser.
Editing a previously inserted image is possible if the html code of the image is selected with no extra characters.

Insert/edit link:
Inserts link html after getting the href, title attributes from the user. If IMCE module is installed, and the user has 
access to it, a Browse button will appear linking to IMCE file browser.
Editing a previously inserted link is possible if the html code of the link is selected with no extra characters.

Bold:
Encloses the selected text with the tag <strong>

Italic:
Encloses the selected text with the tag <em>

Ordered list:
Converts the lines in the selected text to a numbered list. It is also possible to start a new list with no selection. 
If the selection is an ordered list which was previosly created by this button, the lines in the text are restored.

Unordered list:
Converts the lines in the selected text to a bulleted list. It is also possible to start a new list with no selection. 
If the selection is an unordered list which was previosly created by this button, the lines in the text are restored.

Teaser break:
Inserts Drupal teaser break which is <!--break-->

Preview:
Previews the textarea content. By default, lines and paragraphs break automatically. Set first argument to true to preview pure html. Set second argument to true to preview only the selected text:
eDefPreview(true);//no conversion of new lines. preview is based on pure HTML.
eDefPreview(false, true);//only the selection is previewed.

Help:
Displays the title(hint) for each button in the editor.


- TIPS AND TRICKS

How to disable a button temporarily?
Make the first line of the button content:
php: return;/*
and the last line:
*/

How to extend image or link dialogs to get values for other attributes of "img" and "a" tags from the user?
How to create a dialog for any tag just like image or link dialogs?

There is the eDefTagDialog(tag, fields, dtitle, stitle, func) function in default buttons library to create a dialog for
any tag. 
tag -> tag name
fields -> an array of attributes that are eiter strings or objects.
dtitle -> dialog title. if not specified, "(tag) Tag Dialog" is used.
stitle -> laber for submit button. if not specified, browser decides on it.
func -> name of the function that will be executed after submission instead of the default one. (for advanced use)

The simplest form, for example:
eDefTagDialog('div', ['id', 'class', 'style']);
will create a DIV Tag Dialog requesting values of attributes id, class and style. It will also detect if the selection
is a proper DIV tag, and if so, will put the values of attributes to the corresponding fields. After submission, it will
enclose/replace the selection in textarea.

You might have noticed that fields in image/link dialogs are declared as objects not asstrings. That's a
customized form of declaring attributes. It is ideal to use an object if you want
- a field type other than textfield (type: 'select', options: {'left': 'Left', 'right': 'Right'}) - only select is supported.
- a custom label (title: 'Image URL')
- a default value (value: ' ')
- some prefix or suffix text or html (prefix: '[ ', suffix: ' ]')
- to join two fields in a single line like in image width & height fields (getnext: true)
- to set custom attributes for the field (attributes: {size: 10, style: 'width: 200px'})
The field object must have a name property that specifies the attribute name. {name: 'href'}

So lets add an "align" attribute field to the image dialog(note that it's not XHTML compliant):

The field object to pass to eDefTagDialog is;
{
  name: 'align',//required
  title: 'Image align', // if we dont set it, it will be set as 'Align' automatically.(name whose first letter is uppercase)
  type: 'select', // we use a selectbox instead of a plain textfield.
  options: {'': '', left: 'Left', right: 'Right', center: 'Center'} // set options in the form-> {attribute-value: 'Visible value'}
}

Lets add it to the form in the image button's content:

var form = [
 {name: 'src', title: 'Image URL'},
 {name: 'width', title: 'Width x Height', suffix: ' x ', getnext: true, attributes: {size: 3}},
 {name: 'height', attributes: {size: 3}},
 {name: 'alt', title: 'Alternative text'},
 {name: 'align', title: 'Image align', type: 'select', options: {'': '', left: 'Left', right: 'Right', center: 'Center'}} //align
];
eDefTagDialog('img', form, 'Insert/edit image', 'OK');

That's it. We now have an image dialog which can also get/set the "align" attribute of an image tag.


How to create a button that gets user input and adds it to the textarea?
Button content should be like this:
js:
// function that inserts the user input from the form into the textarea.
editor.getUserInput = function(form) {
  editor.active.replaceSelection('User input is: '+ form.elements["user_input"].value);
  editor.dialog.close();//close the dialog when done.
}
//form html. we define an input field named as "user_input".
var userForm = '<form onsubmit="editor.getUserInput(this); return false;">';//run getUserInput on submission
userForm += 'Input : <input type="text" name="user_input" />';
userForm += '<input type="submit" value="Submit" /></form>';
//open editor dialog with a title and the user form.
editor.dialog.open('User Input', userForm);

This example uses a form which is more suitable for complex user input. If you want to get just a single input you 
may consider using javascript prompt(). Here is an example that gets image URL as a user input
js:
var url = prompt('URL', '');//prompt for URL
var code = '<img src="'+ url +'" />';//put the url into the code.
editor.active.replaceSelection(code);//replace the selection with the code.


How to create a button to insert XHTML-compatible Underlined text?
Since <u> is not XHTML-compatible, you should use CSS. First of all, you need to define a class in your theme's 
CSS file, for instance; 
.underlined-text {text-decoration: underline;}
As the above class exists, you can use it in your button content:

<span class="underlined-text">%TEXT%</span>

Where %TEXT% will be replaced by the selected text in the textarea.

File

README.txt
View source
  1. - BUEditor:
  2. A plain textarea editor aiming to facilitate code writing.
  3. The most important feature of this editor is its highly customizable functionality.
  4. It's possible to add image and text buttons whose functions are determined by the user.
  5. Buttons can be customized to generate code snippets, html tags, bbcode tags etc.
  6. - HOW TO INSTALL:
  7. 1) Copy editor directory to your modules directory.
  8. 2) Enable the module at module administration page.
  9. 3) Add/edit editors and buttons at: admin/settings/bueditor.
  10. 4) There is the default editor you can use as a starting point.
  11. 5) You may install IMCE module to use it as a file/image browser in editor's image & link dialogs.
  12. - EXPORTING AND DELETING BUTTONS:
  13. You should first select the buttons you want to export or delete, using checkboxes next to them.
  14. Then select the action you want to take in the selectbox below the list and press GO.
  15. - ADDING BUTTONS:
  16. You can add buttons to an editor by two methods;
  17. 1- Manually entering the values for new button fields located at the bottom of the button list.
  18. 2- Importing a CSV file that contains previously exported buttons.
  19. - BUTTON PROPERTIES
  20. TITLE:(required) Title or name of the button. Displayed as a hint on mouse over. A title can be translated
  21. by prefixing it with "t:". Ex: t:Bold turns into t('Bold')
  22. CONTENT: Html or javascript code that is processed when the button is clicked. This can also be
  23. php code that is pre evaluated and return html or javascript code. See BUTTON TYPES.
  24. ICON: Image or text to display the button.
  25. KEY: Accesskey that is supported by some browsers as a shortcut on web pages. With the right
  26. key combinations users can fire the button's click event. Use Alt+KEY in Internet Explorer, and
  27. Shift+Alt+KEY in Firefox.
  28. WEIGHT: Required for sorting the buttons. Line-up is from the lightest to heaviest.
  29. - BUTTON TYPES
  30. There are three types of buttons regarding the CONTENT property;
  31. 1- HTML BUTTONS
  32. 2- JAVASCRIPT BUTTONS
  33. 3- PHP BUTTONS
  34. - HTML BUTTONS
  35. These are used for directly inserting plain text or html into the textarea.
  36. It is possible to use the selected text in the textarea by using the place holder %TEXT%
  37. For example, assume that the button content is:
  38. %TEXT%

  39. and it is clicked after selecting the "Hello world!" text in the textarea. Then the result is:
  40. Hello world!

  41. with the selection preserved.
  42. Multiple occurances of %TEXT% is possible and each will be replaced by the selected text.
  43. These type of buttons are useful for simple html tags or other tag systems like BBCode.
  44. Note: if you want to insert some text containing the phrase %TEXT%, use a javascript button.
  45. - JAVASCRIPT BUTTONS
  46. The content of a javascript button must begin with a 3 charater text "js:" to be differentiated from a
  47. html button. The remaining code is treated as a javascript code and executed in a function when the
  48. button is clicked. These type of buttons are used for special cases where it is insufficient to just replace the
  49. selected text.
  50. Editor has many ready-to-use methods and variables making it easier to create javascript buttons.
  51. See EDITOR VARIABLES AND METHODS and especially EDITOR INSTANCE variables and methods.
  52. - PHP BUTTONS
  53. The content of a php button must begin with "php:". The remaining code is pre evaluated at the server
  54. side and expected to return some code. According to the return value of the php code the real type of
  55. the button is determined. If the php code returns nothing or false, the button is disabled and does not
  56. show up in the editor.
  57. A php button is indeed a html or javascript button. Php execution is for some special purposes. For example,
  58. it is possible to disable or change the content of the button for a specific user role;
  59. Button with content
  60. php:
  61. if (user_access('access foo')) {
  62. return 'js: alert("You have the permission to access foo")';
  63. }
  64. turns into a javascript button having the returned content for users having "access foo" permission. for others
  65. it is disabled and doesnt show up.
  66. - EDITOR VARIABLES
  67. editor:
  68. the top most container variable having other variables and methods in it.
  69. editor.active:
  70. currently active or last used editor istance. When a button is clicked or a textarea is focused,
  71. the corresponding editor instance becomes the editor.active. If there are multiple editor instances, accesskeys
  72. are switched to work on the editor.active.
  73. editor.active is widely used in javascript buttons since the methods of the current editor instance are accessed
  74. using it. Each editor instance has its own variables and methods that can(should) be used by javascript buttons.
  75. See EDITOR INSTANCE
  76. editor.dialog:
  77. dialog object of the editor used like a pop-up window for getting user input or displaying data.
  78. It has its own variables and methods. See EDITOR DIALOG
  79. - EDITOR METHODS
  80. editor.processTextarea(T):
  81. integrates the editor into the textarea T. This can be used for dynamic editor integration at any time after page load.
  82. editor.openPopup(id, title, content):
  83. opens a pop-up dialog having the given "id", titled as "title" and containing the "content". Returns the js object
  84. representing the pop-up(a html table object).
  85. This pop-up object has its internal "open(title, content, keeppos)" and "close()" methods which can be used for
  86. further open and close operations. if "keeppos" is set, pop-up opens at previos position, otherwise position is reset.
  87. Since pop-up object is a html table object, it has all the methods and properties of a regular table.
  88. The difference between a pop-up and editor.dialog is that editor.dialog can only have one instance visible at a time,
  89. and it doesnt allow textarea editing when it is open.
  90. editor.createPopup(id, title, content):
  91. This method is used by openPopup method. Creates and returns the pop-up object for further use.(does not open it)
  92. - EDITOR INSTANCE (a must-read for javascript button creators)
  93. Each editor running on the page for a textarea is called an instance. Editor instances have their own variables
  94. and methods that make it easy to edit textarea content. Active instance on the page can be accessed by the
  95. variable "editor.active".
  96. Lets assume that we assigned editor.active to a variable E in our js button's content(actually we dont need this
  97. anymore since the button function is now called with the parameter E).
  98. Here are the VARIABLES of the istance E:
  99. E.textArea: textarea of the instance as an HTML object.
  100. E.buttons: indexed array of buttons of the instance as HTML objects(input objects, type is button or image)
  101. E.bindex: latest/currently clicked button index that can be used in E.buttons. Ex: E.buttons[E.bindex]
  102. Here are the METHODS of the instance E:
  103. E.focus():
  104. Focus on the textarea of the instance.
  105. E.getContent():
  106. Returns the content of the textarea.
  107. E.setContent(text):
  108. Replaces the content of the textarea with the given text.
  109. E.getSelection():
  110. Returns the selected text in the textarea.
  111. E.replaceSelection(text, cursor):
  112. Replace the selected text in the textrea with the given text.
  113. The optinal second argument specifies the position of the caret after replacement.
  114. if cursor='start', it is placed at the begining of the replaced text.
  115. if cursor='end', it is placed at the end of the replaced text.
  116. if cursor is not defined, the selection is preserved containing the replaced text.
  117. E.tagSelection(left, right, cursor):
  118. Encloses the selected text in the textarea with the given left and right texts.
  119. The optional third argument specifies the position of the caret after enclosing.
  120. if cursor='start', it is placed at the begining of the selected text.
  121. if cursor='end', it is placed at the end of the selected text.
  122. if cursor is not defined, the selection is preserved.
  123. E.makeSelection(start, end):
  124. Create a selection by selecting the characters between the indexes "start" and "end".
  125. E.posSelection():
  126. Returns the index values of selection start and selection end.
  127. Returns {start: X, end: Y} where X is the start index and Y is the end index.
  128. Note: No selection is also a selection where start=end=caret position.
  129. E.buttonsDisabled(state, bindex):
  130. Dynamically enable/disable buttons of the instance.
  131. the first argument defines the state of the buttons and should be set to true or false.
  132. the optional second argument defines the index of the button whose state will not change.
  133. Ex: to disable all buttons except the pressed button;
  134. js: E.buttonsDisabled(true, E.bindex);
  135. - EDITOR DIALOG
  136. Editor dialog is an object shared by all editor instances. It can be used to display any kind of data, ie. a html form
  137. to get some user input.
  138. Here are the methods of editor dialog
  139. editor.dialog.open(title, content):
  140. Opens the dialog with the given title and content in it.
  141. editor.dialog.close():
  142. Closes the dialog.
  143. - EDITOR ICONS
  144. Icons are stored in "icons" folder of the editor. You can put additional icons into this folder to make them visible
  145. in the icon list in the editor edit page.
  146. - EDITOR LIBRARY
  147. While creating a javascript button you may want to use functions or variables from an external javascript library,
  148. in order to shorten the content text and make it clean. In this case, you should place your javascript library inside
  149. the "library" folder of the editor. The .js files in this directory will be automatically loaded together with the editor.
  150. Note that library/...js files are common and are loaded for every editor you define.
  151. In case you want a library file to be loaded for only a specific editor, you should create a sub-folder under library
  152. directory, which has the same name as the editor. For example, library/editorFoo/...js files will only be loaded
  153. for the editor having the name "editorFoo".
  154. - EDITOR TEMP DIRECTORY
  155. After starting to use the editor, you might notice that an extra folder named as bueditor in system file directory is
  156. created. This directory is used to store javascript files that contain buttons of your editors. Including them in a file
  157. instead of including them inline, allows browser caching and reduces page load time.
  158. Since buttons may have php code that makes them change dynamically, md5 is used to track the changes in buttons
  159. script. If there is a matching file in the folder, it is loaded. Otherwise, a new file is created and loaded. If file loading
  160. fails, buttons are included as inline script.
  161. Note: Files older than 15 days are cleaned in each cron run.
  162. If download method is PRIVATE, buttons are always included inline.
  163. - KNOWN ISSUES
  164. Accesskeys in Internet Explorer:
  165. Pressing an accesskey(Alt+KEY) when there is a selection, deselects it with preserving the caret position.
  166. Accesskeys in Firefox:
  167. If there are multiple editors in the page, accesskeys(Shift+Alt+KEY) will work on only the first editor instance.
  168. This is becouse FF does not allow dynamic adjustment of accesskeys.
  169. New line character:
  170. Since new line is represented by different characters (\r, \r\n, \n) on different platforms, there may be some
  171. unexpected behaviour of the editor in some platform-browser combos regarding the cursor position after text
  172. insertion/replacement. Specify new line characters as "\n", if you have to use any in your scripts.
  173. POST variable limit:
  174. Although it's a rare case, consider increasing your server post variable limit if you have problems while adding too many buttons.
  175. - DEFAULT BUTTONS
  176. BUEditor comes with a few default buttons that may help you extend the editor:
  177. Insert/edit image:
  178. Inserts image html after getting the src, width, height, alt attributes from the user. If IMCE module is installed,
  179. and the user has access to it, a Browse button will appear linking to IMCE image browser.
  180. Editing a previously inserted image is possible if the html code of the image is selected with no extra characters.
  181. Insert/edit link:
  182. Inserts link html after getting the href, title attributes from the user. If IMCE module is installed, and the user has
  183. access to it, a Browse button will appear linking to IMCE file browser.
  184. Editing a previously inserted link is possible if the html code of the link is selected with no extra characters.
  185. Bold:
  186. Encloses the selected text with the tag
  187. Italic:
  188. Encloses the selected text with the tag
  189. Ordered list:
  190. Converts the lines in the selected text to a numbered list. It is also possible to start a new list with no selection.
  191. If the selection is an ordered list which was previosly created by this button, the lines in the text are restored.
  192. Unordered list:
  193. Converts the lines in the selected text to a bulleted list. It is also possible to start a new list with no selection.
  194. If the selection is an unordered list which was previosly created by this button, the lines in the text are restored.
  195. Teaser break:
  196. Inserts Drupal teaser break which is
  197. Preview:
  198. Previews the textarea content. By default, lines and paragraphs break automatically. Set first argument to true to preview pure html. Set second argument to true to preview only the selected text:
  199. eDefPreview(true);//no conversion of new lines. preview is based on pure HTML.
  200. eDefPreview(false, true);//only the selection is previewed.
  201. Help:
  202. Displays the title(hint) for each button in the editor.
  203. - TIPS AND TRICKS
  204. How to disable a button temporarily?
  205. Make the first line of the button content:
  206. php: return;/*
  207. and the last line:
  208. */
  209. How to extend image or link dialogs to get values for other attributes of "img" and "a" tags from the user?
  210. How to create a dialog for any tag just like image or link dialogs?
  211. There is the eDefTagDialog(tag, fields, dtitle, stitle, func) function in default buttons library to create a dialog for
  212. any tag.
  213. tag -> tag name
  214. fields -> an array of attributes that are eiter strings or objects.
  215. dtitle -> dialog title. if not specified, "(tag) Tag Dialog" is used.
  216. stitle -> laber for submit button. if not specified, browser decides on it.
  217. func -> name of the function that will be executed after submission instead of the default one. (for advanced use)
  218. The simplest form, for example:
  219. eDefTagDialog('div', ['id', 'class', 'style']);
  220. will create a DIV Tag Dialog requesting values of attributes id, class and style. It will also detect if the selection
  221. is a proper DIV tag, and if so, will put the values of attributes to the corresponding fields. After submission, it will
  222. enclose/replace the selection in textarea.
  223. You might have noticed that fields in image/link dialogs are declared as objects not asstrings. That's a
  224. customized form of declaring attributes. It is ideal to use an object if you want
  225. - a field type other than textfield (type: 'select', options: {'left': 'Left', 'right': 'Right'}) - only select is supported.
  226. - a custom label (title: 'Image URL')
  227. - a default value (value: ' ')
  228. - some prefix or suffix text or html (prefix: '[ ', suffix: ' ]')
  229. - to join two fields in a single line like in image width & height fields (getnext: true)
  230. - to set custom attributes for the field (attributes: {size: 10, style: 'width: 200px'})
  231. The field object must have a name property that specifies the attribute name. {name: 'href'}
  232. So lets add an "align" attribute field to the image dialog(note that it's not XHTML compliant):
  233. The field object to pass to eDefTagDialog is;
  234. {
  235. name: 'align',//required
  236. title: 'Image align', // if we dont set it, it will be set as 'Align' automatically.(name whose first letter is uppercase)
  237. type: 'select', // we use a selectbox instead of a plain textfield.
  238. options: {'': '', left: 'Left', right: 'Right', center: 'Center'} // set options in the form-> {attribute-value: 'Visible value'}
  239. }
  240. Lets add it to the form in the image button's content:
  241. var form = [
  242. {name: 'src', title: 'Image URL'},
  243. {name: 'width', title: 'Width x Height', suffix: ' x ', getnext: true, attributes: {size: 3}},
  244. {name: 'height', attributes: {size: 3}},
  245. {name: 'alt', title: 'Alternative text'},
  246. {name: 'align', title: 'Image align', type: 'select', options: {'': '', left: 'Left', right: 'Right', center: 'Center'}} //align
  247. ];
  248. eDefTagDialog('img', form, 'Insert/edit image', 'OK');
  249. That's it. We now have an image dialog which can also get/set the "align" attribute of an image tag.
  250. How to create a button that gets user input and adds it to the textarea?
  251. Button content should be like this:
  252. js:
  253. // function that inserts the user input from the form into the textarea.
  254. editor.getUserInput = function(form) {
  255. editor.active.replaceSelection('User input is: '+ form.elements["user_input"].value);
  256. editor.dialog.close();//close the dialog when done.
  257. }
  258. //form html. we define an input field named as "user_input".
  259. var userForm = '
    ';//run getUserInput on submission
  260. userForm += 'Input : ';
  261. userForm += '';
  262. //open editor dialog with a title and the user form.
  263. editor.dialog.open('User Input', userForm);
  264. This example uses a form which is more suitable for complex user input. If you want to get just a single input you
  265. may consider using javascript prompt(). Here is an example that gets image URL as a user input
  266. js:
  267. var url = prompt('URL', '');//prompt for URL
  268. var code = '';//put the url into the code.
  269. editor.active.replaceSelection(code);//replace the selection with the code.
  270. How to create a button to insert XHTML-compatible Underlined text?
  271. Since is not XHTML-compatible, you should use CSS. First of all, you need to define a class in your theme's
  272. CSS file, for instance;
  273. .underlined-text {text-decoration: underline;}
  274. As the above class exists, you can use it in your button content:
  275. %TEXT%
  276. Where %TEXT% will be replaced by the selected text in the textarea.