Source for file none.php

Documentation is available at none.php

  1. <?php
  2. /**
  3.  * @package     Joomla.Plugin
  4.  * @subpackage  Editors.none
  5.  *
  6.  * @copyright   Copyright (C) 2005 - 2013 Open Source Matters, Inc. All rights reserved.
  7.  * @license     GNU General Public License version 2 or later; see LICENSE.txt
  8.  */
  9.  
  10. defined('_JEXEC'or die;
  11.  
  12. /**
  13.  * Plain Textarea Editor Plugin
  14.  *
  15.  * @package     Joomla.Plugin
  16.  * @subpackage  Editors.none
  17.  * @since       1.5
  18.  */
  19. class PlgEditorNone extends JPlugin
  20. {
  21.     /**
  22.      * Method to handle the onInitEditor event.
  23.      *  - Initialises the Editor
  24.      *
  25.      * @return  string    JavaScript Initialization string
  26.      *
  27.      * @since 1.5
  28.      */
  29.     public function onInit()
  30.     {
  31.         $txt =    "<script type=\"text/javascript\">
  32.                     function insertAtCursor(myField, myValue)
  33.                     {
  34.                         if (document.selection)
  35.                         {
  36.                             // IE support
  37.                             myField.focus();
  38.                             sel = document.selection.createRange();
  39.                             sel.text = myValue;
  40.                         } else if (myField.selectionStart || myField.selectionStart == '0')
  41.                         {
  42.                             // MOZILLA/NETSCAPE support
  43.                             var startPos = myField.selectionStart;
  44.                             var endPos = myField.selectionEnd;
  45.                             myField.value = myField.value.substring(0, startPos)
  46.                                 + myValue
  47.                                 + myField.value.substring(endPos, myField.value.length);
  48.                         } else {
  49.                             myField.value += myValue;
  50.                         }
  51.                     }
  52.                 </script>";
  53.  
  54.         return $txt;
  55.     }
  56.  
  57.     /**
  58.      * Copy editor content to form field.
  59.      *
  60.      * Not applicable in this editor.
  61.      *
  62.      * @return  void 
  63.      */
  64.     public function onSave()
  65.     {
  66.         return;
  67.     }
  68.  
  69.     /**
  70.      * Get the editor content.
  71.      *
  72.      * @param   string  $id  The id of the editor field.
  73.      *
  74.      * @return  string 
  75.      */
  76.     public function onGetContent($id)
  77.     {
  78.         return "document.getElementById('$id').value;\n";
  79.     }
  80.  
  81.     /**
  82.      * Set the editor content.
  83.      *
  84.      * @param   string  $id    The id of the editor field.
  85.      * @param   string  $html  The content to set.
  86.      *
  87.      * @return  string 
  88.      */
  89.     public function onSetContent($id$html)
  90.     {
  91.         return "document.getElementById('$id').value = $html;\n";
  92.     }
  93.  
  94.     /**
  95.      * @param   string  $id  The id of the editor field
  96.      *
  97.      * @return  boolean  returns true when complete
  98.      */
  99.     public function onGetInsertMethod($id)
  100.     {
  101.         static $done false;
  102.  
  103.         // Do this only once.
  104.         if (!$done)
  105.         {
  106.             $doc JFactory::getDocument();
  107.             $js "\tfunction jInsertEditorText(text, editor)
  108.             {
  109.                 insertAtCursor(document.getElementById(editor), text);
  110.             }";
  111.             $doc->addScriptDeclaration($js);
  112.         }
  113.  
  114.         return true;
  115.     }
  116.  
  117.     /**
  118.      * Display the editor area.
  119.      *
  120.      * @param   string   $name     The control name.
  121.      * @param   string   $content  The contents of the text area.
  122.      * @param   string   $width    The width of the text area (px or %).
  123.      * @param   string   $height   The height of the text area (px or %).
  124.      * @param   integer  $col      The number of columns for the textarea.
  125.      * @param   integer  $row      The number of rows for the textarea.
  126.      * @param   boolean  $buttons  True and the editor buttons will be displayed.
  127.      * @param   string   $id       An optional ID for the textarea (note: since 1.6). If not supplied the name is used.
  128.      * @param   string   $asset    The object asset
  129.      * @param   object   $author   The author.
  130.      * @param   array    $params   Associative array of editor parameters.
  131.      *
  132.      * @return  string 
  133.      */
  134.     public function onDisplay($name$content$width$height$col$row$buttons true$id null$asset null$author null$params array())
  135.     {
  136.         if (empty($id))
  137.         {
  138.             $id $name;
  139.         }
  140.  
  141.         // Only add "px" to width and height if they are not given as a percentage
  142.         if (is_numeric($width))
  143.         {
  144.             $width .= 'px';
  145.         }
  146.  
  147.         if (is_numeric($height))
  148.         {
  149.             $height .= 'px';
  150.         }
  151.  
  152.         $buttons $this->_displayButtons($id$buttons$asset$author);
  153.         $editor  "<textarea name=\"$name\" id=\"$id\" cols=\"$col\" rows=\"$row\" style=\"width: $width; height: $height;\">$content</textarea>$buttons;
  154.  
  155.         return $editor;
  156.     }
  157.  
  158.     /**
  159.      * Displays the editor buttons.
  160.      *
  161.      * @param   string  $name     The control name.
  162.      * @param   mixed   $buttons  [array with button objects | boolean true to display buttons]
  163.      * @param   string  $asset    The object asset
  164.      * @param   object  $author   The author.
  165.      *
  166.      * @return  string HTML
  167.      */
  168.     public function _displayButtons($name$buttons$asset$author)
  169.     {
  170.         // Load modal popup behavior
  171.         JHtml::_('behavior.modal''a.modal-button');
  172.  
  173.         $args['name'$name;
  174.         $args['event''onGetInsertMethod';
  175.  
  176.         $return '';
  177.         $results[$this->update($args);
  178.  
  179.         foreach ($results as $result)
  180.         {
  181.             if (is_string($result&& trim($result))
  182.             {
  183.                 $return .= $result;
  184.             }
  185.         }
  186.  
  187.         if (is_array($buttons|| (is_bool($buttons&& $buttons))
  188.         {
  189.             $results $this->_subject->getButtons($name$buttons$asset$author);
  190.  
  191.             // This will allow plugins to attach buttons or change the behavior on the fly using AJAX
  192.             $return .= "\n<div id=\"editor-xtd-buttons\" class=\"btn-toolbar pull-left\">\n";
  193.             $return .= "\n<div class=\"btn-toolbar\">\n";
  194.  
  195.             foreach ($results as $button)
  196.             {
  197.                 // Results should be an object
  198.                 if ($button->get('name'))
  199.                 {
  200.                     $modal        ($button->get('modal')) 'class="modal-button btn"' null;
  201.                     $href        ($button->get('link')) 'class="btn" href="' JUri::base($button->get('link''"' null;
  202.                     $onclick    ($button->get('onclick')) 'onclick="' $button->get('onclick''"' null;
  203.                     $title      ($button->get('title')) $button->get('title'$button->get('text');
  204.                     $return .= "<a " $modal " title=\"" $title "\" " $href " " $onclick " rel=\"" $button->get('options'"\"><i class=\"icon-" $button->get('name'"\"></i> " $button->get('text'"</a>\n";
  205.                 }
  206.             }
  207.  
  208.             $return .= "</div>\n";
  209.             $return .= "</div>\n";
  210.             $return .= "<div class=\"clearfix\"></div>\n";
  211.         }
  212.  
  213.         return $return;
  214.     }
  215. }

Documentation generated on Tue, 19 Nov 2013 15:09:34 +0100 by phpDocumentor 1.4.3