 collapse_text.module        |  19 +++++++++
 wysiwyg/ckeditor/button.png | Bin 0 -> 520 bytes
 wysiwyg/ckeditor/plugin.js  | 100 ++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 119 insertions(+)

diff --git a/collapse_text.module b/collapse_text.module
index 77ee90d..d88ae9a 100644
--- a/collapse_text.module
+++ b/collapse_text.module
@@ -909,3 +909,22 @@ function _collapse_text_html_to_xml_entities ($text) {
   
   return $text;
 }
+
+/**
+* Implementation of hook_wysiwyg_plugin().
+*/
+function collapse_text_wysiwyg_plugin($editor) {
+  if ($editor == 'ckeditor') {
+    return array(
+      'collapse_text' => array(
+        'name' => 'collapse_text',
+        'description' => 'Collapse Text - ' . t('Inserts [collapsed][/collapsed] tags'),
+        'path' => drupal_get_path('module', 'collapse_text') . '/wysiwyg/ckeditor/',
+        'load' => TRUE,
+        'buttons' => array(
+          'collapse_text' => 'Insert Collapsible Text',
+        ),
+      ),
+    );
+  }
+}
diff --git a/wysiwyg/ckeditor/button.png b/wysiwyg/ckeditor/button.png
new file mode 100644
index 0000000..14bb535
Binary files /dev/null and b/wysiwyg/ckeditor/button.png differ
diff --git a/wysiwyg/ckeditor/plugin.js b/wysiwyg/ckeditor/plugin.js
new file mode 100644
index 0000000..b6ad9a3
--- /dev/null
+++ b/wysiwyg/ckeditor/plugin.js
@@ -0,0 +1,100 @@
+CKEDITOR.plugins.add( 'collapse_text',
+{
+  init: function( editor )
+  {
+    /* COMMAND */
+    editor.addCommand( 'cmdCollapseTextDialog', new CKEDITOR.dialogCommand( 'collapseTextDialog' ) );
+    
+    /* BUTTON */
+    editor.ui.addButton( 'collapse_text',
+    {
+      label: 'Insert collapsible text',
+      command: 'cmdCollapseTextDialog',
+      icon: this.path + 'button.png'
+    } );
+
+    /* DIALOG */
+    CKEDITOR.dialog.add( 'collapseTextDialog', function ( editor )
+    {
+      return {
+        title : 'Collapsible text settings',
+        minWidth : 300,
+        minHeight : 200,
+        contents :
+        [{
+          id : 'tab1',
+          label : 'Settings',
+          elements :
+          [{
+            type : 'text',
+            id : 'title',
+            label : 'Collapsible text title',
+            validate : CKEDITOR.dialog.validate.notEmpty( "Collapsible text title should be provided" )
+          }, {
+            type : 'textarea',
+            id : 'content',
+            label : 'Collapsible text content',
+            validate : CKEDITOR.dialog.validate.notEmpty( "Collapsible text content should be provided" )
+          }, {
+            type : 'checkbox',
+            id : 'state',
+            label : 'Initially expanded (not collapsed)'
+          },{
+            type : 'text',
+            id : 'classes',
+            label : 'Optional class'
+          }]
+        }],
+        onOk : function()
+               {
+                 var dialog = this;
+                 var title = dialog.getValueOf( 'tab1', 'title' );
+                 var content = dialog.getValueOf( 'tab1', 'content' );
+                 var classes = dialog.getValueOf( 'tab1', 'classes' );
+				 var state = !dialog.getValueOf( 'tab1', 'state' ) ? 'collapsed' : 'collapse';
+
+                 var openTag = '[' + state + ' title="' + title + '"' + ((classes!="") ? ' class="' + classes + '"' : "" ) + ']';
+                 var closeTag = '[/' + state + ']';
+                 var inplaceTag = ' ' + openTag + content + closeTag + ' ';
+
+                 var S = editor.getSelection();
+
+                 if( S == null)
+                 {
+                   editor.insertHtml(inplaceTag);
+                   return;
+                 }
+
+                 var R = S.getRanges();
+                 R = R[0];
+      
+                 if( R == null)
+                 {
+                   editor.insertHtml(inplaceTag);
+                   return;
+                 }
+
+
+                 var startPos = Math.min(R.startOffset, R.endOffset);
+                 var endPos = Math.max(R.startOffset, R.endOffset);
+                  
+                 //console.log(R);
+                 if( startPos == endPos )
+                 {
+                   editor.insertHtml(inplaceTag);
+                   return;
+                 }
+
+                 var container = new CKEDITOR.dom.element('p');
+                 var fragment = R.extractContents();
+                  
+                 container.appendText(openTag);                  
+                 fragment.appendTo(container);  
+                 container.appendText(closeTag);
+
+                 editor.insertElement(container);
+               }
+      };
+    });//dialog.add
+  }//init:
+});//plugin.add
