From 83476bf19fb850af7558a4a6f092641d04238ca9 Mon Sep 17 00:00:00 2001
From: sun <sun@unleashedmind.com>
Date: Wed, 29 Aug 2012 15:28:47 +0200
Subject: [PATCH] - #1732880 by loominade, yannickoo, sun: Added EpicEditor
 support.

---
 editors/epiceditor.inc   | 102 +++++++++++++++++++++++++++++++++++++++++++++++
 editors/js/epiceditor.js |  38 ++++++++++++++++++
 2 files changed, 140 insertions(+)
 create mode 100644 editors/epiceditor.inc
 create mode 100644 editors/js/epiceditor.js

diff --git a/editors/epiceditor.inc b/editors/epiceditor.inc
new file mode 100644
index 0000000..7c89768
--- /dev/null
+++ b/editors/epiceditor.inc
@@ -0,0 +1,102 @@
+<?php
+
+/**
+ * @file
+ * Editor integration functions for EpicEditor.
+ */
+
+/**
+ * Plugin implementation of hook_editor().
+ */
+function wysiwyg_epiceditor_editor() {
+  $editor['epiceditor'] = array(
+    'title' => 'EpicEditor',
+    'vendor url' => 'http://oscargodson.github.com/EpicEditor',
+    'download url' => 'http://oscargodson.github.com/EpicEditor/docs/downloads/EpicEditor-v0.1.1.zip',
+    'libraries' => array(
+      '' => array(
+        'title' => 'Minified',
+        'files' => array('js/epiceditor.min.js'),
+      ),
+      'src' => array(
+        'title' => 'Source',
+        'files' => array('js/epiceditor.js'),
+      ),
+    ),
+    'version callback' => 'wysiwyg_epiceditor_version',
+    'themes callback' => 'wysiwyg_epiceditor_themes',
+    'settings callback' => 'wysiwyg_epiceditor_settings',
+    'versions' => array(
+      '0.1.1' => array(
+        'js files' => array('epiceditor.js'),
+      ),
+    ),
+  );
+  return $editor;
+}
+
+/**
+ * Detect editor version.
+ *
+ * @param $editor
+ *   An array containing editor properties as returned from hook_editor().
+ *
+ * @return
+ *   The installed editor version.
+ */
+function wysiwyg_epiceditor_version($editor) {
+  $library = $editor['library path'] . '/js/epiceditor.js';
+  if (!file_exists($library)) {
+    return;
+  }
+  // @todo Do not load the entire file; use fgets() instead.
+  $library = file_get_contents($library, 'r');
+  $version = preg_match('%EpicEditor\.version = \'(.*)\'\;%', $library, $matches);
+  if (!isset($matches[1])) {
+    return;
+  }
+  return $matches[1];
+}
+
+/**
+ * Determine available editor themes or check/reset a given one.
+ *
+ * @param $editor
+ *   A processed hook_editor() array of editor properties.
+ * @param $profile
+ *   A wysiwyg editor profile.
+ *
+ * @return
+ *   An array of theme names. The first returned name should be the default
+ *   theme name.
+ */
+function wysiwyg_epiceditor_themes($editor, $profile) {
+  return array('epic-dark', 'epic-light');
+  // @todo Use the preview themes somewhere.
+  //return array('preview-dark', 'github');
+}
+
+/**
+ * Return runtime editor settings for a given wysiwyg profile.
+ *
+ * @param $editor
+ *   A processed hook_editor() array of editor properties.
+ * @param $config
+ *   An array containing wysiwyg editor profile settings.
+ * @param $theme
+ *   The name of a theme/GUI/skin to use.
+ *
+ * @return
+ *   A settings array to be populated in
+ *   Drupal.settings.wysiwyg.configs.{editor}
+ */
+function wysiwyg_epiceditor_settings($editor, $config, $theme) {
+  $settings = array(
+    'basePath' => base_path() . $editor['library path'],
+    'clientSideStorage' => FALSE,
+    'theme' => $theme,
+    //'preview_theme' => '',
+  );
+  return $settings;
+}
+
diff --git a/editors/js/epiceditor.js b/editors/js/epiceditor.js
new file mode 100644
index 0000000..03c4801
--- /dev/null
+++ b/editors/js/epiceditor.js
@@ -0,0 +1,38 @@
+(function($) {
+
+/**
+ * Attach this editor to a target element.
+ */
+Drupal.wysiwyg.editor.attach.epiceditor = function (context, params, settings) {
+  var $target = $('#' + params.field);
+  var containerId = params.field + '-epiceditor';
+  var defaultContent = $target.val();
+  $target.hide().after('<div id="' + containerId + '" />');
+
+  settings.container = containerId;
+  settings.file = {
+    defaultContent: defaultContent
+  };
+  settings.theme = {
+    preview: '/themes/preview/preview-dark.css',
+    editor: '/themes/editor/' + settings.theme + '.css'
+  }
+  var editor = new EpicEditor(settings).load();
+  $target.data('epiceditor', editor);
+};
+
+/**
+ * Detach a single or all editors.
+ */
+Drupal.wysiwyg.editor.detach.epiceditor = function (context, params, trigger) {
+  var $target = $('#' + params.field);
+  var editor = $target.data('epiceditor');
+
+  $target.val(editor.exportFile());
+
+  editor.unload(function () {
+    $target.show();
+  });
+};
+
+})(jQuery);
-- 
1.7.11.msysgit.1

