Answers.Body: <p>You need to alter your <code>properties.js</code> and <code>table.js</code> files. Instead of assigning the plugin function to <code>$.Redactor.prototype</code> you should assign it to the <code>RedactorPlugins</code> object. </p>
  
  <p>Standard Redactor Plugin setup:</p>
  
  <pre><code>$.Redactor.prototype.myplugin = function() {
      return {
      // Plugin code here...
      }
  }
  </code></pre>
  
  <p>Craft CMS Redactor Plugin setup:</p>
  
  <pre><code>// Initialize the RedactorPlugins object if it doesn't exist
  if ( !RedactorPlugins ) { var RedactorPlugins = {}; }
  
  // Assign the redactor plugin function
  RedactorPlugins.myplugin = function() {
      return {
      // Plugin code here...
      }
  }
  </code></pre>
  
  <p>I'm not sure where the documentation on this is, but you can see it in Pixel &amp; Tonic's own RedactorClips plugin here:  <a href="https://github.com/pixelandtonic/RedactorClips/blob/master/redactorclips/RedactorClipsPlugin.php" rel="nofollow">https://github.com/pixelandtonic/RedactorClips/blob/master/redactorclips/RedactorClipsPlugin.php</a></p>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-12-09T14:09:15.850Z
Answers.Text: I have tried your solution and it no longer throws the exception, thanks, but the plugins are still not being loaded.
  
  I modified standard.json to
  
  {
    "buttons": ["format","bold","italic","lists","link","file","horizontalrule","table","properties"],
    "plugins":["source","fullscreen", "table","properties"]
  }
  
  I checked the RedactorPlugins object and my two redactor plugins are there.
  
  What could I be missing?
  [Note: I am simply trying to implement the https://imperavi.com/redactor/plugins/table/ and https://imperavi.com/redactor/plugins/properties/ plugins, but within Craft 2.5.2753.]
Answers.UserDisplayName: graney
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-12-09T14:37:27.373Z
Answers.Text: Ok, I was being stupid. I had picked an entry type that had the rich text field set to use the default and not the standard config, and that was why it was not showing up.
  
  Everything works fine now, thanks a lot on the pointers.
Answers.UserDisplayName: graney
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-12-08T19:48:09.440Z
Answers.LastActivityDate: 2015-12-08T19:48:09.440Z
Answers.UserDisplayName: jpolete
Body: <p>As I want to use two different Redactor plugins, <code>table.js</code> and <code>properties.js</code>, I decided to write a simple Craft Plugin to load the JS using <code>includeJsResouce</code> in the <code>init()</code> function, as so;</p>
  
  <pre><code>function init() {
  
      if ( craft()-&gt;request-&gt;isCpRequest() &amp;&amp; craft()-&gt;userSession-&gt;isLoggedIn() )
      {
          craft()-&gt;templates-&gt;includeJsResource('myextensions/js/properties.js');
          craft()-&gt;templates-&gt;includeJsResource('myextensions/js/table.js');
      }
  
  }
  </code></pre>
  
  <p>However, I have found that these JS files are being loaded in the HTML <em>before</em> the Redactor.js file, so I get a JS error in the console, as Redactor is undefined. [<code>Uncaught TypeError: Cannot read property 'prototype' of undefined</code>]</p>
  
  <p>Is there a way to ensure that my plugin JS is loaded <em>after</em> Redactor that does not entail hacking the core of Craft?</p>
  
  <p>The version of Craft I am using is the current, Craft Pro 2.5.2753.</p>
  
Tags: <plugin-development><redactor>
Title: Redactor extension plugin loading JS before Redactor.js
ThreadText: # Redactor extension plugin loading JS before Redactor.js
  
  (Asked by: username_0 on 2015-12-08)
  
  As I want to use two different Redactor plugins, `table.js` and `properties.js`, I decided to write a simple Craft Plugin to load the JS using `includeJsResouce` in the `init()` function, as so;
  
  ```
  function init() {
  
      if ( craft()->request->isCpRequest() && craft()->userSession->isLoggedIn() )
      {
          craft()->templates->includeJsResource('myextensions/js/properties.js');
          craft()->templates->includeJsResource('myextensions/js/table.js');
      }
  
  }
  
  ```
  
  However, I have found that these JS files are being loaded in the HTML *before* the Redactor.js file, so I get a JS error in the console, as Redactor is undefined. [`Uncaught TypeError: Cannot read property 'prototype' of undefined`]
  
  Is there a way to ensure that my plugin JS is loaded *after* Redactor that does not entail hacking the core of Craft?
  
  The version of Craft I am using is the current, Craft Pro 2.5.2753.
  
  **Tags:** plugin-development, redactor
  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_1 on 2015-12-08. Score: 1 | Accepted answer
  
  You need to alter your `properties.js` and `table.js` files. Instead of assigning the plugin function to `$.Redactor.prototype` you should assign it to the `RedactorPlugins` object.
  
  Standard Redactor Plugin setup:
  
  ```
  $.Redactor.prototype.myplugin = function() {
      return {
      // Plugin code here...
      }
  }
  
  ```
  
  Craft CMS Redactor Plugin setup:
  
  ```
  // Initialize the RedactorPlugins object if it doesn't exist
  if ( !RedactorPlugins ) { var RedactorPlugins = {}; }
  
  // Assign the redactor plugin function
  RedactorPlugins.myplugin = function() {
      return {
      // Plugin code here...
      }
  }
  
  ```
  
  I'm not sure where the documentation on this is, but you can see it in Pixel & Tonic's own RedactorClips plugin here: <https://github.com/pixelandtonic/RedactorClips/blob/master/redactorclips/RedactorClipsPlugin.php>
  
  > **Comments:**
  > **username_0**: I have tried your solution and it no longer throws the exception, thanks, but the plugins are still not being loaded.  I modified standard.json to  {   "buttons": ["format","bold","italic","lists","link","file","horizontalrule","table","properties"],   "plugins":["source","fullscreen", "table","properties"] }  I checked the RedactorPlugins object and my two redactor plugins are there.  What could I be missing? [Note: I am simply trying to implement the https://imperavi.com/redactor/plugins/table/ and https://imperavi.com/redactor/plugins/properties/ plugins, but within Craft 2.5.2753.]  
  > **username_0**: Ok, I was being stupid. I had picked an entry type that had the rich text field set to use the default and not the standard config, and that was why it was not showing up.  Everything works fine now, thanks a lot on the pointers.  
  
  ---
  
  