From 73428f33492d7769dfdec3f33cfaa2e08c36c46b Mon Sep 17 00:00:00 2001
From: Daniel Boulet <dboulet@139316.no-reply.drupal.org>
Date: Mon, 20 Jun 2011 14:54:44 -0500
Subject: [PATCH] Adding new feature: section breaks.

---
 columns_filter.module                           |   38 +++++---
 plugins/columnbreak.inc                         |   22 +++++-
 plugins/columnbreak/columnbreak.css             |   12 +++-
 plugins/columnbreak/columnbreak.js              |  103 +++++++++++++----------
 plugins/columnbreak/images/colbreaktext.png     |  Bin 0 -> 285 bytes
 plugins/columnbreak/images/columnbreak.png      |  Bin 0 -> 133 bytes
 plugins/columnbreak/images/sectionbreak.png     |  Bin 0 -> 143 bytes
 plugins/columnbreak/images/sectionbreaktext.png |  Bin 0 -> 337 bytes
 plugins/columnbreak/langs/en.js                 |    4 +
 9 files changed, 119 insertions(+), 60 deletions(-)
 create mode 100644 plugins/columnbreak/images/colbreaktext.png
 create mode 100644 plugins/columnbreak/images/columnbreak.png
 create mode 100644 plugins/columnbreak/images/sectionbreak.png
 create mode 100644 plugins/columnbreak/images/sectionbreaktext.png

diff --git a/columns_filter.module b/columns_filter.module
index 7c16f8c..f0e3d4b 100644
--- a/columns_filter.module
+++ b/columns_filter.module
@@ -1,8 +1,15 @@
 <?php
 
+define('COLUMNS_FILTER_SECTION_MARKER', '<!--section-->');
+define('COLUMNS_FILTER_COLUMN_MARKER', '<!--column-->');
+define('COLUMNS_FILTER_SECTION_PLACEHOLDER', '####COLUMNS_FILTER_SECTION####');
+define('COLUMNS_FILTER_COLUMN_PLACEHOLDER', '####COLUMNS_FILTER_COLUMN####');
+
 /**
  * @file
- * Columns input filter: use <!--column--> to create a column break.
+ * Columns input filter:
+ * - use <!--column--> to create a column break
+ * - use <!--section--> to create a section break
  * Must be placed after the HTML filter and above the line break converter filter:
  *  - HTML filter
  *  - Columns filter
@@ -16,8 +23,7 @@
  */
 function columns_filter_filter_info() {
   $filters['columns_filter'] = array(
-    'title' => t('Columns Filter'),
-    'description' => t('Create column breaks with &lt;!--column-->.'),
+    'title' => t('Separate content into columns'),
     'prepare callback' => 'columns_filter_filter_prepare',
     'process callback' => 'columns_filter_filter_process',
     'tips callback'  => 'columns_filter_filter_tips'
@@ -34,8 +40,9 @@ function columns_filter_filter_info() {
  * @see hook_filter_FILTER_prepare()
  */
 function columns_filter_filter_prepare($text, $filter, $format, $langcode, $cache, $cache_id) {
-  $column_marker = '<!--column-->';
-  return str_replace($column_marker, '####COLUMN_FILTER_COLUMN####', $text);
+  $search = array(COLUMNS_FILTER_SECTION_MARKER, COLUMNS_FILTER_COLUMN_MARKER);
+  $replace = array(COLUMNS_FILTER_SECTION_PLACEHOLDER, COLUMNS_FILTER_COLUMN_PLACEHOLDER);
+  return str_replace($search, $replace, $text);
 }
 
 /**
@@ -46,17 +53,20 @@ function columns_filter_filter_prepare($text, $filter, $format, $langcode, $cach
  * @see hook_filter_FILTER_process()
  */
 function columns_filter_filter_process($text, $filter, $format, $langcode, $cache, $cache_id) {
-  $column_marker = '####COLUMN_FILTER_COLUMN####';
-
-  $pieces = explode($column_marker, $text);
-  $columns = count($pieces);
+  $sections = explode(COLUMNS_FILTER_SECTION_PLACEHOLDER, $text);
 
-  // Only one column.
-  if ($columns < 2) {
-    return theme('columns_filter_single_column', array('text' => $text));
+  $output = '';
+  foreach ($sections as $section) {
+    $columns = explode(COLUMNS_FILTER_COLUMN_PLACEHOLDER, $section);
+    if (count($columns) < 2) {
+      $output .= theme('columns_filter_single_column', array('text' => $section));
+    }
+    else {
+      $output .= theme('columns_filter_columns', array('cols' => $columns));
+    }
   }
 
-  return theme('columns_filter_columns', array('cols' => $pieces));
+  return $output;
 }
 
 /**
@@ -65,7 +75,7 @@ function columns_filter_filter_process($text, $filter, $format, $langcode, $cach
  * @see hook_filter_FILTER_tips()
  */
 function columns_filter_filter_tips($filter, $format, $long) {
-  return t("&lt;!--column--> creates a column break.");
+  return t("&lt;!--column--&gt; creates a column break. &lt;!--section--&gt; creates a section break.");
 }
 
 /**
diff --git a/plugins/columnbreak.inc b/plugins/columnbreak.inc
index 35b9643..80a829e 100644
--- a/plugins/columnbreak.inc
+++ b/plugins/columnbreak.inc
@@ -9,12 +9,30 @@
  * Implements hook_wysiwyg_plugin().
  */
 function columns_filter_columnbreak_plugin() {
+  $module_path = drupal_get_path('module', 'columns_filter');
   $plugins['columnbreak'] = array(
     'title' => t('Column break'),
     'vendor url' => 'http://drupal.org/project/columns_filter',
-    'icon file' => 'columnbreak.gif',
+    'icon path' => $module_path . '/plugins/columnbreak/images',
+    'icon file' => 'columnbreak.png',
     'icon title' => t('Insert a column break'),
-    'settings' => array(),
+    'settings' => array(
+      'text' => 'column',
+      'class' => 'wysiwyg-columnbreak',
+      'path' => $module_path . '/plugins/columnbreak',
+    ),
+  );
+  $plugins['sectionbreak'] = array(
+    'title' => t('Section break'),
+    'vendor url' => 'http://drupal.org/project/columns_filter',
+    'icon path' => $module_path . '/plugins/columnbreak/images',
+    'icon file' => 'sectionbreak.png',
+    'icon title' => t('Insert a section break'),
+    'settings' => array(
+      'text' => 'section',
+      'class' => 'wysiwyg-sectionbreak',
+      'path' => $module_path . '/plugins/columnbreak',
+    ),
   );
   return $plugins;
 }
diff --git a/plugins/columnbreak/columnbreak.css b/plugins/columnbreak/columnbreak.css
index ef1c205..91b6e43 100644
--- a/plugins/columnbreak/columnbreak.css
+++ b/plugins/columnbreak/columnbreak.css
@@ -6,5 +6,15 @@
   margin-top: 1em;
   width: 100%;
   height: 12px;
-  background: transparent url(images/colbreaktext.gif) no-repeat center top;
+  background: transparent url(images/colbreaktext.png) no-repeat center top;
+}
+
+.wysiwyg-sectionbreak {
+  display: block;
+  border: 0;
+  border-top: 1px dotted #ccc;
+  margin-top: 1em;
+  width: 100%;
+  height: 12px;
+  background: transparent url(images/sectionbreaktext.png) no-repeat center top;
 }
diff --git a/plugins/columnbreak/columnbreak.js b/plugins/columnbreak/columnbreak.js
index 9c0c23b..23e6d96 100644
--- a/plugins/columnbreak/columnbreak.js
+++ b/plugins/columnbreak/columnbreak.js
@@ -1,56 +1,73 @@
 (function ($) {
-  Drupal.wysiwyg.plugins['columnbreak'] = {
 
-    /**
-     * Return whether the passed node belongs to this plugin.
-     */
-    isNode: function(node) {
-      return ($(node).is('img.wysiwyg-columnbreak'));
-    },
+  /**
+   * Execute the button.
+   */
+  var invoke = function (data, settings, instanceId) {
+    if (data.format == 'html') {
+      var content = _getPlaceholder(settings);
+    }
+    else {
+      var content = '<!--' + settings.text + '-->';
+    }
+    if (typeof content != 'undefined') {
+      Drupal.wysiwyg.instances[instanceId].insert(content);
+    }
+  };
 
-    /**
-     * Execute the button.
-     */
-    invoke: function(data, settings, instanceId) {
-      if (data.format == 'html') {
-        var content = this._getPlaceholder(settings);
-      }
-      else {
-        var content = '<!--column-->';
-      }
-      if (typeof content != 'undefined') {
-        Drupal.wysiwyg.instances[instanceId].insert(content);
-      }
-    },
+  /**
+   * Replace all marker tags with images.
+   */
+  var attach = function (content, settings, instanceId) {
+    content = content.replace(new RegExp('<!--' + settings.text + '-->', "g"), _getPlaceholder(settings));
+    return content;
+  };
 
-    /**
-     * Replace all <!--column--> tags with images.
-     */
-    attach: function(content, settings, instanceId) {
-      content = content.replace(/<!--column-->/g, this._getPlaceholder(settings));
-      return content;
-    },
+  /**
+   * Replace images with comment tags in content upon detaching editor.
+   */
+  var detach = function (content, settings, instanceId) {
+    var $content = $('<div>' + content + '</div>'); // No .outerHTML() in jQuery :(
+    // #404532: document.createComment() required or IE will strip the comment.
+    // #474908: IE 8 breaks when using jQuery methods to replace the elements.
+    // @todo Add a generic implementation for all Drupal plugins for this.
+    $.each($('img.' + settings.class, $content), function (i, elem) {
+      elem.parentNode.insertBefore(document.createComment(settings.text), elem);
+      elem.parentNode.removeChild(elem);
+    });
+    return $content.html();
+  };
 
+  /**
+   * Helper function to return a HTML placeholder.
+   */
+  function _getPlaceholder(settings) {
+    var text = '&lt;--' + settings.text + '--&gt;';
+    return '<img src="' + settings.path + '/images/spacer.gif" alt="' + text + '" title="' + text + '" class="' + settings.class + ' drupal-content" />';
+  };
+
+  Drupal.wysiwyg.plugins['columnbreak'] = {
     /**
-     * Replace images with <!--column--> tags in content upon detaching editor.
+     * Return whether the passed node belongs to this plugin.
      */
-    detach: function(content, settings, instanceId) {
-      var $content = $('<div>' + content + '</div>'); // No .outerHTML() in jQuery :(
-      // #404532: document.createComment() required or IE will strip the comment.
-      // #474908: IE 8 breaks when using jQuery methods to replace the elements.
-      // @todo Add a generic implementation for all Drupal plugins for this.
-      $.each($('img.wysiwyg-columnbreak', $content), function (i, elem) {
-        elem.parentNode.insertBefore(document.createComment('column'), elem);
-        elem.parentNode.removeChild(elem);
-      });
-      return $content.html();
+    isNode: function (node) {
+      return ($(node).is('img.wysiwyg-columnbreak'));
     },
+    invoke: invoke,
+    attach: attach,
+    detach: detach
+  };
 
+  Drupal.wysiwyg.plugins['sectionbreak'] = {
     /**
-     * Helper function to return a HTML placeholder.
+     * Return whether the passed node belongs to this plugin.
      */
-    _getPlaceholder: function (settings) {
-      return '<img src="' + settings.path + '/images/spacer.gif" alt="&lt;--column-&gt;" title="&lt;--column--&gt;" class="wysiwyg-columnbreak drupal-content" />';
-    }
+    isNode: function (node) {
+      return ($(node).is('img.wysiwyg-sectionbreak'));
+    },
+    invoke: invoke,
+    attach: attach,
+    detach: detach
   };
+
 })(jQuery);
diff --git a/plugins/columnbreak/images/colbreaktext.png b/plugins/columnbreak/images/colbreaktext.png
new file mode 100644
index 0000000000000000000000000000000000000000..3d42988abe33ea3a8182207048e574ae99cb1d02
GIT binary patch
literal 285
zcmV+&0pk9NP)<h;3K|Lk000e1NJLTq002z@000aG0{{R3)gvuR0000mP)t-s00030
z(#-#_rvI6Y|GKjOVN3s`ng4-u|955o^YZ`P+5g7B|BZkD=;r@cJ^yQ1!WJ~%00001
zbW%=J06^y0W&i*Hn@L1LR2b7^V4yj$dw^YBV*?)wpBGIX?>8`|Z^-~tH{;!J`F9Gu
z57;04^Ly8qAMp$#%oGMBcwRCv@I%#^^L`293Iv+>fL~m#@b9a8P;veMh<OYQe(#?A
zd-vfZ$W9Z8Iw!-wANcOSdk>UhgIKKL05^~8BgDLiS0U;yfZZ1ab16UEeF;GK0S&hM
j|L&R9|HpO(3<C`SK8-zwuRMk700000NkvXXu0mjf?Nof<

literal 0
HcmV?d00001

diff --git a/plugins/columnbreak/images/columnbreak.png b/plugins/columnbreak/images/columnbreak.png
new file mode 100644
index 0000000000000000000000000000000000000000..ab0a0e68fba84b7bdc1968819c5e9a6337776863
GIT binary patch
literal 133
zcmeAS@N?(olHy`uVBq!ia0vp^A|TAf3?x51|2hvy@dWsUxB}_4w6y>K|JN)#8GN&K
zDUi=t666=m;PC858jz#z>Eal|5uKcnV33fI&@f@q!k&eUJVDyL;l2mFjFLJ8w7Cr>
bPwFwOf3L_Y6)5cl)WYED>gTe~DWM4fO$R0S

literal 0
HcmV?d00001

diff --git a/plugins/columnbreak/images/sectionbreak.png b/plugins/columnbreak/images/sectionbreak.png
new file mode 100644
index 0000000000000000000000000000000000000000..386ec243952b07129bac6330c47b69f23827fd99
GIT binary patch
literal 143
zcmeAS@N?(olHy`uVBq!ia0vp^A|TAf3?x51|2hvy@dWsUxYjH?nU<FJ9}HG_pLz=v
zXDJEt3kC`>IB2c>0_5v?x;Tb#$R_{bXX1%>c6NR&xo>UM)+{?ep+#(q=C#j!*uco_
hldl^AMEVm|80-aI6yG<By#(rH@O1TaS?83{1OV2!Fcbg)

literal 0
HcmV?d00001

diff --git a/plugins/columnbreak/images/sectionbreaktext.png b/plugins/columnbreak/images/sectionbreaktext.png
new file mode 100644
index 0000000000000000000000000000000000000000..ab4292df80f866b893b9e82145ef4e5361bf56ec
GIT binary patch
literal 337
zcmeAS@N?(olHy`uVBq!ia0vp^Ak4$T3?z@0N$CM8g8-ip*Z+-0|Fa|huV426#k2p3
z-v4Lz{NJ_d|DBuv%TxbfI`e<=%>SQ1{Xe$<e{cQ&Fx&tC|2rA>^8xh=lmz(&1G&h6
z;em3jBv9^vr;B4q#jUH8?q;zXa<E;U@!$6G@BO*j)h{;5WK>@avJ&Uw<datuvOjlU
z%i3D{tF@Q3J4?K#x~kpM7gbumulvMP<sD{nX>TfGc)?<+zgqD^p7S&9sr+RsRpDXp
z=e{%Db-Vhm%=syyN+F*jw#+y#`&B#j62mMeDc1xUmAYMesflUg-EJBSo~P)<%J0t6
z*K}7i)+wJ7dTq({jX^tYgVzOD2Hwfj|F?)G#h*2*SVEP>g+ZnKr$L6o{tx>9SAOD+
X@ilfx@&3sM^b3QhtDnm{r-UW|DA1E1

literal 0
HcmV?d00001

diff --git a/plugins/columnbreak/langs/en.js b/plugins/columnbreak/langs/en.js
index b36f97f..acf2131 100644
--- a/plugins/columnbreak/langs/en.js
+++ b/plugins/columnbreak/langs/en.js
@@ -3,4 +3,8 @@
     title: 'Insert column break',
     desc: 'Separate this content into columns'
   });
+  tinyMCE.addToLang('sectionbreak', {
+    title: 'Insert section break',
+    desc: 'Separate this content into sections'
+  });
 })(jQuery);
-- 
1.7.2

