You are here

README.txt in Editor 5

Same filename and directory in other branches
  1. 7 README.txt
     
      Editor
      Provided by www.vision-media.ca
      Developed by Tj Holowaychuk [tj@vision-media.ca] 
      Icons provided www.famfamfam.com     
     
      ------------------------------------------------------------------------------- 
      INSTALLATION
      ------------------------------------------------------------------------------- 
      
      Simply enable the module, along with the 'plugins' and 'visibility_api' modules. 
      
      http://drupal.org/project/plugins
      http://drupal.org/project/visibility_api
      
      ------------------------------------------------------------------------------- 
      PLUGIN DEVELOPMENT
      ------------------------------------------------------------------------------- 
      
      To provide a plugin or several plugins simply invoke hook_editor_plugins(). This 
      hook expects you to return an array of 'editor plugin objects'. These objects
      can be created manually however editor_plugin_create() is available to assist in
      this process.
      
      /**
       * Implementation of hook_editor_plugins();
       */
      function editor_editor_plugins() {
        $plugins = array();
        
        $plugins[] = editor_plugin_create('link', t('Link'), 'button', t('Link selected text or content to a website or page.'), editor_plugin_link_options());
        
        return $plugins;
      }
      
      The editor_plugin_create() function allows you to provide form fields, which are
      presented as settings to the end-user. 
      
      /**
       * Link options.
       */
      function editor_plugin_link_options() {
        return '
            <input type="text" class="href click-clear" value="Location" /> 
            <select class="window">
              <option value="same">' . t('Open in same window') . '</option>
              <option value="_blank">' . t('Open in new window') . '</option>
            </select>
            <input type="button" class="submit" value="Go" />
          ';
      }
      
      In our JavaScript file we can now extend the Editor object with 
      Drupal.editor.prototype.[PIDInit] = function(){}; where [PIDInit] 
      is your plugin id (link, mailto, undo, etc).
      
      The plugins DOM node is passed into the method. We then listen or 
      bind to the linkMouseDown event. 
      
      From here we can show our options using this.showOptions(); where
      the value should be this.settings.plugins.[PID].options; 
      
      /**
       * Link plugin. Provides options for customizing anchor tags.
       */
      Drupal.editor.prototype.linkInit = function(plugin) {
        $(this).bind('linkMouseDown', function(e){  
          var ed = e.target;
          
          this.showOptions(this.settings.plugins.link.options);
                
          // Apply anchor tag
          $('.submit', this.options).click(function(){
            var uri = $('.href', this.options).val();
            var window = $('.window', this.options).val();
            
            // Validation
            if (uri == 'Location'){
              ed.setMessage('Enter a location.', 'error');
              return;
            }
            
            if (window == 'same'){
              ed.execCommand('createlink', uri);
            }
            else {
              var node = ed.createNode('a');
              $(node).attr('href', uri).attr('target', '_blank'); 
              ed.wrap(node);
            }
            
            ed.hideOptions();   
          });
        });
      };   
      
      -------------------------------------------------------------------------------
      PERMISSIONS
      ------------------------------------------------------------------------------- 
      
      access editor
      administer editor visibility
      administer editor profiles          



File

README.txt
View source
  1. Editor
  2. Provided by www.vision-media.ca
  3. Developed by Tj Holowaychuk [tj@vision-media.ca]
  4. Icons provided www.famfamfam.com
  5. -------------------------------------------------------------------------------
  6. INSTALLATION
  7. -------------------------------------------------------------------------------
  8. Simply enable the module, along with the 'plugins' and 'visibility_api' modules.
  9. http://drupal.org/project/plugins
  10. http://drupal.org/project/visibility_api
  11. -------------------------------------------------------------------------------
  12. PLUGIN DEVELOPMENT
  13. -------------------------------------------------------------------------------
  14. To provide a plugin or several plugins simply invoke hook_editor_plugins(). This
  15. hook expects you to return an array of 'editor plugin objects'. These objects
  16. can be created manually however editor_plugin_create() is available to assist in
  17. this process.
  18. /**
  19. * Implementation of hook_editor_plugins();
  20. */
  21. function editor_editor_plugins() {
  22. $plugins = array();
  23. $plugins[] = editor_plugin_create('link', t('Link'), 'button', t('Link selected text or content to a website or page.'), editor_plugin_link_options());
  24. return $plugins;
  25. }
  26. The editor_plugin_create() function allows you to provide form fields, which are
  27. presented as settings to the end-user.
  28. /**
  29. * Link options.
  30. */
  31. function editor_plugin_link_options() {
  32. return '
  33. ';
  34. }
  35. In our JavaScript file we can now extend the Editor object with
  36. Drupal.editor.prototype.[PIDInit] = function(){}; where [PIDInit]
  37. is your plugin id (link, mailto, undo, etc).
  38. The plugins DOM node is passed into the method. We then listen or
  39. bind to the linkMouseDown event.
  40. From here we can show our options using this.showOptions(); where
  41. the value should be this.settings.plugins.[PID].options;
  42. /**
  43. * Link plugin. Provides options for customizing anchor tags.
  44. */
  45. Drupal.editor.prototype.linkInit = function(plugin) {
  46. $(this).bind('linkMouseDown', function(e){
  47. var ed = e.target;
  48. this.showOptions(this.settings.plugins.link.options);
  49. // Apply anchor tag
  50. $('.submit', this.options).click(function(){
  51. var uri = $('.href', this.options).val();
  52. var window = $('.window', this.options).val();
  53. // Validation
  54. if (uri == 'Location'){
  55. ed.setMessage('Enter a location.', 'error');
  56. return;
  57. }
  58. if (window == 'same'){
  59. ed.execCommand('createlink', uri);
  60. }
  61. else {
  62. var node = ed.createNode('a');
  63. $(node).attr('href', uri).attr('target', '_blank');
  64. ed.wrap(node);
  65. }
  66. ed.hideOptions();
  67. });
  68. });
  69. };
  70. -------------------------------------------------------------------------------
  71. PERMISSIONS
  72. -------------------------------------------------------------------------------
  73. access editor
  74. administer editor visibility
  75. administer editor profiles