title: CKEditor Loading Content in Dialog window
body: <p>I am working on a file manager plugin for <code>CKEditor &amp; Yii 1</code>. I have created a button on the editor toolbar and on clicking that button i am opening a dialog window. For loading the content / html of the window i am making an ajax call to my controller action i.e <code>filemanager/index</code> which loads the view. Inside that view i have a <code>javascript</code> call which initiates the file manager plugin, and populates all the files in the upload directory to the main div with <code>id="fileview"</code>, now my problem is that the <code>javascript</code> call inside the view is never executed no matter i used <code>renderPartial('viewname',[],false,true)</code> inside my index action. </p>
  
  <p>I have the plugin working for <code>tinyMCE</code> and currently i am trying to reuse the file manager script to work with CKEditor my file manager script is in <code>idows-file-browser.min.js</code> and i call <code>idowsFileBrowser.init()</code> to initialize it, but in <code>tinyMCE</code> plugin i am using <code>windowmanager.open()</code> which is definitely not an ajax call infect it opens a window and load the content returned from the controller action.</p>
  
  <p>I am trying to look for a way that i do not have to change anything for the existing plugin script file or the views, but it seems like that for <code>CKEditor</code> i might need to move the <code>idowsFileBrowser.init()</code> call inside the <code>idowsfilemanagerdialog.js</code> file after receiving the response from the ajax call.</p>
  
  <p>Can anyone help me out to make it work without changing the flow.</p>
  
  <p><strong><em>idowsfilemanagerdialog.js</em></strong></p>
  
  <pre><code>CKEDITOR.dialog.add('idowsfilemanagerDialog', function(editor) {
      return {
          title: 'Tinyii Filemanager By IDOWS',
          minWidth: 850,
          minHeight: 600,
          contents: [{
              id: "File list",
              elements: [{
                  type: 'html',
                  id: 'foo',
                  html: '&lt;div id="main-container"&gt;&lt;/div&gt;',
              }]
          }],
          onLoad: function() {
              var document = this.getElement().getDocument();
              var element = document.getById('main-container');
  
              $.ajax({
                  url: '/filemanager/index',
                  method: 'get',
                  dataType: 'html',
                  data: {
                      editor: '_CK'
                  }
              }).done(function(res) {
                  if (element) {
                      element.setHtml(res);
                  }
              });
  
          },
      };
  });
  </code></pre>
  
  <p><strong><em>index action inside the FilemanagerController</em></strong></p>
  
  <pre><code>/**
       * Index main Entry Action for filemanager
       * Opens Main modal window for the file manager
       */
      public function actionIndex() {
          $model = new TinyiiAssetUploadForm();
          $uploadDir = str_replace ( "\\" , "/" , Yii::app ()-&gt;basePath . '/..' . Yii::app ()-&gt;params['UPLOAD_DIR'] );
          $uploadDirExists = is_dir ( realpath ( $uploadDir ) );
  
          if ( !$uploadDirExists ) {
              throw new Exception ( 'The upload directory you specified in your param file does not exist.' . $uploadDir );
          }
          $this-&gt;renderPartial ( 'dialog' , array( 'model' =&gt; $model ) , false , true );
      }
  </code></pre>
  
  <p><strong><em>View file</em></strong> </p>
  
  <pre><code>    $cs-&gt;registerScriptFile ( Yii::app ()-&gt;params['PLUGIN_DIR'.$this-&gt;editorType] . '/js/idows-file-browser.min.js' );
      $cs-&gt;registerScript ( 'loadtree' , 'idowsFileBrowser.init();',CClientScript::POS_LOAD );
      ?&gt;
      &lt;?php echo $this-&gt;renderPartial ( 'alerts' ); ?&gt;
      &lt;div class="idows-container-body"&gt;
  
          &lt;div class="idows-abs-end"&gt;&lt;/div&gt;
          &lt;div class="idows-container idows-first idows-last" &gt;
              &lt;div class="idows-container-body " style="width:100%;"&gt;
  
                  &lt;div class="idows-abs-end"&gt;&lt;/div&gt;
                  &lt;div class="idows-container idows-first" style="border-width: 0px 0px 1px; left: 0px; top: 0px; height: 38px;"&gt;
  
                      &lt;!--UPLOAD PROGRESS INFO BAR--&gt;
                      &lt;div id="upload_in_progress" class="upload_infobar"&gt;
                          &lt;img src="&lt;?= Yii::app ()-&gt;params['PLUGIN_DIR'.$this-&gt;editorType] ?&gt;/skin/img/loader.gif" width="16" height="16" class="spinner"&gt;
                          Upload in progress&amp;hellip; 
                          &lt;div id="upload_additional_info"&gt;&lt;/div&gt;
                      &lt;/div&gt;
                      &lt;div id="upload_infobar" class="upload_infobar"&gt;&lt;/div&gt;
  
                      &lt;!--CONTROLS CONTAINER--&gt;
                      &lt;div class="idows-container-body idows-menubar idows-panel" style="width: 100%;"&gt;
                          &lt;div class="idows-abs-end"&gt;&lt;/div&gt;
                          &lt;?php echo $this-&gt;renderPartial ( 'controls' , [ 'model' =&gt; $model ] ); ?&gt;
                      &lt;/div&gt;
                      &lt;!-- FILE BROWSER  --&gt;
                      &lt;div class="idows-container idows-float-panel idows-last" role="group" style="position: relative;"&gt;
                          &lt;div class="idows-thumbnailview" id="file_container"&gt;
      &lt;div class="idows-container-body idows-flow-layout" id="fileview"&gt;
      &lt;/div&gt;
  &lt;/div&gt;
                      &lt;/div&gt;
                      &lt;?= CHtml::hiddenField ( 'current_template' , 'thumbview' , [ 'id' =&gt; 'current_template' ] ); ?&gt;
                  &lt;/div&gt;
              &lt;/div&gt;
          &lt;/div&gt;
      &lt;/div&gt;
      &lt;!-- IFRAME FOR FILE UPLOAD --&gt;
      &lt;iframe id="upload_target" name="upload_target" src="&lt;?= Yii::app ()-&gt;getBaseUrl ( true ) ?&gt;/index.php?r=filemanager/blank"&gt;&lt;/iframe&gt;
  
      &lt;!-- THICK BOX CONTAINER AND MASK --&gt;
      &lt;div id="dialog" class="window"&gt;
          &lt;a href="#." class="close-preview"/&gt;x&lt;/a&gt;
      &lt;/div&gt;
      &lt;div id="overlay"&gt;&lt;/div&gt;
      &lt;?=
      $this-&gt;renderPartial ( 'bootstrap-modals' )?&gt;
  </code></pre>