summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorScott Reynen2012-08-12 18:35:23 (GMT)
committer Scott Reynen2012-08-12 18:35:23 (GMT)
commit5208c826ed1e77f7fec811b70148ae98bb2f727e (patch)
tree373609753092713f3cd358542b2259a5da746761
parentae09add50e4d23e137a292c49e027a049418b260 (diff)
Issue #896024 by sreynen: Initial WYSIWYG integration
-rw-r--r--modules/fontyourface_wysiwyg/fontyourface_wysiwyg.info9
-rw-r--r--modules/fontyourface_wysiwyg/fontyourface_wysiwyg.install10
-rw-r--r--modules/fontyourface_wysiwyg/fontyourface_wysiwyg.module81
-rw-r--r--modules/fontyourface_wysiwyg/plugins/fontyourface.inc44
-rw-r--r--modules/fontyourface_wysiwyg/plugins/fontyourface/fontyourface.js98
-rw-r--r--modules/fontyourface_wysiwyg/plugins/fontyourface/images/fontyourface.jpgbin0 -> 7711 bytes
6 files changed, 242 insertions, 0 deletions
diff --git a/modules/fontyourface_wysiwyg/fontyourface_wysiwyg.info b/modules/fontyourface_wysiwyg/fontyourface_wysiwyg.info
new file mode 100644
index 0000000..a189b00
--- /dev/null
+++ b/modules/fontyourface_wysiwyg/fontyourface_wysiwyg.info
@@ -0,0 +1,9 @@
+; $Id$
+name = WYSIWYG for @font-your-face
+description = Adds list of enabled fonts to WYSIWYG.
+dependencies[] = fontyourface
+dependencies[] = wysiwyg
+package = @font-your-face
+core = 7.x
+
+files[] = fontyourface_wysiwyg.module
diff --git a/modules/fontyourface_wysiwyg/fontyourface_wysiwyg.install b/modules/fontyourface_wysiwyg/fontyourface_wysiwyg.install
new file mode 100644
index 0000000..b4d3cd7
--- /dev/null
+++ b/modules/fontyourface_wysiwyg/fontyourface_wysiwyg.install
@@ -0,0 +1,10 @@
+<?php
+
+/**
+ * Implements hook_uninstall().
+ */
+function fontyourface_wysiwyg_uninstall() {
+
+ variable_del('fontyourface_wysiwyg_css_md5');
+
+} // fontyourface_wysiwyg_uninstall
diff --git a/modules/fontyourface_wysiwyg/fontyourface_wysiwyg.module b/modules/fontyourface_wysiwyg/fontyourface_wysiwyg.module
new file mode 100644
index 0000000..b1f3944
--- /dev/null
+++ b/modules/fontyourface_wysiwyg/fontyourface_wysiwyg.module
@@ -0,0 +1,81 @@
+<?php
+// $Id$
+
+/**
+ * Implements template_preprocess_page().
+ */
+function fontyourface_wysiwyg_preprocess_page(&$vars) {
+
+ $fonts = fontyourface_get_fonts();
+
+ $css = fontyourface_wysiwyg_generate_css($fonts);
+ $css_md5 = md5($css);
+
+ if ($css_md5 != variable_get('fontyourface_wysiwyg_css_md5', '')) {
+
+ fontyourface_wysiwyg_rewrite_css($css);
+ variable_set('fontyourface_wysiwyg_css_md5', $css_md5);
+
+ } // if
+
+ if ($css != '') {
+ fontyourface_add_css_in_preprocess($vars, 'fontyourface/wysiwyg.css');
+ } // if
+
+} // fontyourface_wysiwyg_preprocess_page
+
+/**
+ * Generates CSS.
+ */
+function fontyourface_wysiwyg_generate_css($fonts = FALSE) {
+
+ // Get font list.
+
+ if (!$fonts) {
+ $fonts = fontyourface_get_fonts();
+ } // if
+
+ // Generate CSS.
+
+ $css = '';
+
+ foreach ($fonts as $font) {
+
+ $font_css = fontyourface_font_css($font);
+
+ if ($font_css != '') {
+ $css .= '.fontyourface-' . $font->fid . ' { ' . $font_css . ' }' . "\n";
+ } // if
+
+ } // foreach
+
+ return $css;
+
+} // fontyourface_wysiwyg_generate_css
+
+/**
+ * Re-writes wysiwyg.css file.
+ */
+function fontyourface_wysiwyg_rewrite_css($css) {
+
+ // Write CSS.
+
+ $destination = file_stream_wrapper_uri_normalize('public://fontyourface/wysiwyg.css');
+ $destination_directory = dirname($destination);
+
+ if (file_prepare_directory($destination_directory, FILE_CREATE_DIRECTORY)) {
+ file_unmanaged_save_data($css, $destination, FILE_EXISTS_REPLACE);
+ } // if
+
+} // fontyourface_wysiwyg_rewrite_css
+
+/**
+ * Implements hook_wysiwyg_include_directory().
+ */
+function fontyourface_wysiwyg_wysiwyg_include_directory($type) {
+
+ if ($type == 'plugins') {
+ return 'plugins';
+ } // if
+
+} // fontyourface_wysiwyg_wysiwyg_include_directory
diff --git a/modules/fontyourface_wysiwyg/plugins/fontyourface.inc b/modules/fontyourface_wysiwyg/plugins/fontyourface.inc
new file mode 100644
index 0000000..c0beb00
--- /dev/null
+++ b/modules/fontyourface_wysiwyg/plugins/fontyourface.inc
@@ -0,0 +1,44 @@
+<?php
+// $Id$
+
+/**
+ * @file
+ * Wysiwyg API integration for @font-your-face module.
+ */
+
+/**
+ * Implementation of hook_INCLUDE_plugin().
+ */
+function fontyourface_wysiwyg_fontyourface_plugin() {
+
+ $plugins = array();
+
+ $fonts = fontyourface_get_fonts();
+
+ $fonts_setting = array();
+
+ foreach ($fonts as $font) {
+
+ $fonts_setting[] = array(
+ 'fid' => $font->fid,
+ 'name' => $font->name,
+ );
+
+ } // foreach
+
+ $plugins['fontyourface'] = array(
+ 'title' => t('@font-your-face'),
+ 'vendor url' => 'http://drupal.org/project/fontyourface',
+ 'icon file' => 'fontyourface.jpg',
+ 'icon title' => t('Set font'),
+ 'css path' => 'sites/default/files/fontyourface',
+ 'css file' => 'wysiwyg.css',
+ 'settings' => array(
+ 'fonts' => $fonts_setting,
+ ),
+ );
+
+ return $plugins;
+
+} // fontyourface_wysiwyg_fontyourface_plugin
+
diff --git a/modules/fontyourface_wysiwyg/plugins/fontyourface/fontyourface.js b/modules/fontyourface_wysiwyg/plugins/fontyourface/fontyourface.js
new file mode 100644
index 0000000..c96ea5a
--- /dev/null
+++ b/modules/fontyourface_wysiwyg/plugins/fontyourface/fontyourface.js
@@ -0,0 +1,98 @@
+(function ($) {
+
+Drupal.wysiwyg.plugins.fontyourface = {
+
+ /**
+ * Returns whether the passed node belongs to this plugin.
+ */
+ isNode: function(node) {
+ return true;
+ }, // isNode
+
+ /**
+ * Execute the button.
+ */
+ invoke: function(data, settings, instanceId) {
+
+ var button = $('#cke_' + instanceId + ' .cke_button_fontyourface');
+ var position = button.offset();
+ var fontSelect = $('<div id="' + instanceId + '_fontyourface-select" class="fontyourface-select"><ul><li data-fid="0">-- NONE --</li></ul></div>');
+
+ fontSelect.data('instanceId', instanceId);
+ fontSelect.data('data', data);
+
+ for (i in settings.fonts) {
+
+ var font = settings.fonts[i];
+
+ $('<li data-fid="' + font.fid + '">' + font.name + '</li>').appendTo(fontSelect.find('ul'));
+
+ } // for
+
+ fontSelect.find('li').click(function() {
+
+ var li = $(this);
+ var div = li.parents('div.fontyourface-select');
+ var data = div.data('data');
+ var instanceId = div.data('instanceId');
+ var fid = li.attr('data-fid');
+
+ if (fid > 0) {
+
+ if (data.format == 'html') {
+ var content = '<span class="fontyourface-' + fid + '">' + data.content + '</span>';
+ } // if
+ else {
+ var content = '<span class="fontyourface-' + fid + '">' + data.content + '</span>';
+ } // else
+
+ if (typeof content != 'undefined') {
+ Drupal.wysiwyg.instances[instanceId].insert(content);
+ } // if
+
+ } // if
+
+ div.remove();
+
+ });
+
+ fontSelect.css({
+ 'position': 'absolute',
+ 'top': position.top + button.height(),
+ 'left': position.left,
+ 'border': '1px #999 solid',
+ 'background': '#fff'
+ });
+ fontSelect.find('ul').css({
+ 'list-style': 'none',
+ 'margin': '0'
+ });
+ fontSelect.find('li')
+ .css({
+ 'margin': '0',
+ 'padding': '5px'
+ })
+ .hover(
+ function() {
+ $(this).css('background', '#ccc');
+ },
+ function() {
+ $(this).css('background', '#fff');
+ }
+ );
+
+ fontSelect.appendTo('body');
+
+ }, // invoke
+
+ attach: function(content, settings, instanceId) {
+ return content;
+ }, // attach
+
+ detach: function(content, settings, instanceId) {
+ return content;
+ } // detach
+
+};
+
+})(jQuery);
diff --git a/modules/fontyourface_wysiwyg/plugins/fontyourface/images/fontyourface.jpg b/modules/fontyourface_wysiwyg/plugins/fontyourface/images/fontyourface.jpg
new file mode 100644
index 0000000..236dde3
--- /dev/null
+++ b/modules/fontyourface_wysiwyg/plugins/fontyourface/images/fontyourface.jpg
Binary files differ