PageRenderTime 40ms CodeModel.GetById 12ms RepoModel.GetById 0ms app.codeStats 0ms

/plugins/editors/none/none.php

https://github.com/joebushi/joomla
PHP | 176 lines | 98 code | 19 blank | 59 comment | 14 complexity | a103fb9f8fa4a5beb2c83d04cd1c7141 MD5 | raw file
Possible License(s): LGPL-2.1, Apache-2.0
  1. <?php
  2. /**
  3. * @version $Id$
  4. * @package Joomla
  5. * @copyright Copyright (C) 2005 - 2010 Open Source Matters, Inc. All rights reserved.
  6. * @license GNU General Public License version 2 or later; see LICENSE.txt
  7. */
  8. // no direct access
  9. defined('_JEXEC') or die;
  10. jimport('joomla.plugin.plugin');
  11. /**
  12. * Plain Textarea Editor Plugin
  13. *
  14. * @package Joomla
  15. * @subpackage Editors
  16. * @since 1.5
  17. */
  18. class plgEditorNone extends JPlugin
  19. {
  20. /**
  21. * Method to handle the onInitEditor event.
  22. * - Initialises the Editor
  23. *
  24. * @access public
  25. * @return string JavaScript Initialization string
  26. * @since 1.5
  27. */
  28. function onInit()
  29. {
  30. $txt = "<script type=\"text/javascript\">
  31. function insertAtCursor(myField, myValue) {
  32. if (document.selection) {
  33. // IE support
  34. myField.focus();
  35. sel = document.selection.createRange();
  36. sel.text = myValue;
  37. } else if (myField.selectionStart || myField.selectionStart == '0') {
  38. // MOZILLA/NETSCAPE support
  39. var startPos = myField.selectionStart;
  40. var endPos = myField.selectionEnd;
  41. myField.value = myField.value.substring(0, startPos)
  42. + myValue
  43. + myField.value.substring(endPos, myField.value.length);
  44. } else {
  45. myField.value += myValue;
  46. }
  47. }
  48. </script>";
  49. return $txt;
  50. }
  51. /**
  52. * Copy editor content to form field.
  53. *
  54. * Not applicable in this editor.
  55. */
  56. function onSave()
  57. {
  58. return;
  59. }
  60. /**
  61. * Get the editor content.
  62. *
  63. * @param string The id of the editor field.
  64. */
  65. function onGetContent($id)
  66. {
  67. return "document.getElementById('$id').value;\n";
  68. }
  69. /**
  70. * Set the editor content.
  71. *
  72. * @param string The id of the editor field.
  73. * @param string The content to set.
  74. */
  75. function onSetContent($id, $html)
  76. {
  77. return "document.getElementById('$id').value = $html;\n";
  78. }
  79. /**
  80. */
  81. function onGetInsertMethod($id)
  82. {
  83. static $done = false;
  84. // Do this only once.
  85. if (!$done)
  86. {
  87. $doc = JFactory::getDocument();
  88. $js = "\tfunction jInsertEditorText(text, editor) {
  89. insertAtCursor(document.getElementById(editor), text);
  90. }";
  91. $doc->addScriptDeclaration($js);
  92. }
  93. return true;
  94. }
  95. /**
  96. * Display the editor area.
  97. *
  98. * @param string The name of the editor area.
  99. * @param string The content of the field.
  100. * @param string The width of the editor area.
  101. * @param string The height of the editor area.
  102. * @param int The number of columns for the editor area.
  103. * @param int The number of rows for the editor area.
  104. * @param boolean True and the editor buttons will be displayed.
  105. * @param string An optional ID for the textarea (note: since 1.6). If not supplied the name is used.
  106. */
  107. function onDisplay($name, $content, $width, $height, $col, $row, $buttons = true, $id = null)
  108. {
  109. if (empty($id)) {
  110. $id = $name;
  111. }
  112. // Only add "px" to width and height if they are not given as a percentage
  113. if (is_numeric($width)) {
  114. $width .= 'px';
  115. }
  116. if (is_numeric($height)) {
  117. $height .= 'px';
  118. }
  119. $buttons = $this->_displayButtons($id, $buttons);
  120. $editor = "<textarea name=\"$name\" id=\"$id\" cols=\"$col\" rows=\"$row\" style=\"width: $width; height: $height;\">$content</textarea>" . $buttons;
  121. return $editor;
  122. }
  123. function _displayButtons($name, $buttons)
  124. {
  125. // Load modal popup behavior
  126. JHtml::_('behavior.modal', 'a.modal-button');
  127. $args['name'] = $name;
  128. $args['event'] = 'onGetInsertMethod';
  129. $return = '';
  130. $results[] = $this->update($args);
  131. foreach ($results as $result)
  132. {
  133. if (is_string($result) && trim($result)) {
  134. $return .= $result;
  135. }
  136. }
  137. if (!empty($buttons))
  138. {
  139. $results = $this->_subject->getButtons($name, $buttons);
  140. // This will allow plugins to attach buttons or change the behavior on the fly using AJAX
  141. $return .= "\n<div id=\"editor-xtd-buttons\">\n";
  142. foreach ($results as $button)
  143. {
  144. // Results should be an object
  145. if ($button->get('name'))
  146. {
  147. $modal = ($button->get('modal')) ? 'class="modal-button"' : null;
  148. $href = ($button->get('link')) ? 'href="'.$button->get('link').'"' : null;
  149. $onclick = ($button->get('onclick')) ? 'onclick="'.$button->get('onclick').'"' : null;
  150. $return .= "<div class=\"button2-left\"><div class=\"".$button->get('name')."\"><a ".$modal." title=\"".$button->get('text')."\" ".$href." ".$onclick." rel=\"".$button->get('options')."\">".$button->get('text')."</a></div></div>\n";
  151. }
  152. }
  153. $return .= "</div>\n";
  154. }
  155. return $return;
  156. }
  157. }