diff --git a/wysiwygcck.info b/wysiwygcck.info index d05a0cc..52ad7a8 100644 --- a/wysiwygcck.info +++ b/wysiwygcck.info @@ -3,5 +3,5 @@ description = Fixes some integration issues when using a wysiwyg enabled multi-v core = 6.x package = User interface dependencies[] = wysiwyg +dependencies[] = jquery_update dependencies[] = jquery_aop -dependencies[] = jquery_form_update diff --git a/wysiwygcck.install b/wysiwygcck.install index 3dd9b98..cb54d15 100644 --- a/wysiwygcck.install +++ b/wysiwygcck.install @@ -7,3 +7,59 @@ function wysiwygcck_install() { // We need our hook_form_alter() to run after wysiwyg.module's hook_form_alter(). db_query("UPDATE {system} SET weight = %d WHERE name = '%s' AND type = '%s'", 1, 'wysiwygcck', 'module'); } + +function wysiwygcck_requirements($phase) { + $requirements = array(); + $t = get_t(); + + // NOTE: We can assume that some version of jquery_update is installed + // since it's listed as a dependency of this module. We just need to check + // that the version number of jquery.form.js is >= 2.16 + $requirements['wysiwygcck']['title'] = $t('jQuery Form version'); + $version = explode('.', _wysiwygcck_get_js_form_version()); + if (count($version) >= 2 && $version[0] >= 2 && $version[1] >= 16) { + // Everything looks good; display the current jQuery UI version. + $requirements['wysiwygcck']['value'] = implode('.', $version); + $requirements['wysiwygcck']['severity'] = REQUIREMENT_OK; + } + else { + // Required library wasn't found. Abort installation. + $requirements['wysiwygcck']['value'] = implode('.', $version); + $requirements['wysiwygcck']['description'] = $t( + 'The Wysiwyg CCK Integration modele requires a version of jquery.form.js + greater or equal 2.16. This is best done by installing !jq_up 2.x or greater.', + array( + '!jq_up' => l('jQuery Update', 'http://drupal.org/project/jquery_update'), + ) + ); + $requirements['wysiwygcck']['severity'] = REQUIREMENT_ERROR; + } + + return $requirements; + +} + +/** + * Function to grab the version number from jquery_update's copy of jquery.form.js + * @see jquery_update_get_version + */ +function _wysiwygcck_get_js_form_version() { + $version = 0; + $pattern = '#\* version: ([0-9\.a-z]+) #'; + + // Load jquery_update_jquery_path() code as needed. + if (!is_callable('jquery_update_jquery_path')) { + include_once drupal_get_path('module', 'jquery_update') . '/jquery_update.module'; + } + + // jquery.form.js is in the same directory as jquery.js + $path = dirname(jquery_update_jquery_path()); + + // Return the version. + $jquery_form = file_get_contents("$path/jquery.form.js"); + if (preg_match($pattern, $jquery_form, $matches)) { + $version = $matches[1]; + } + + return $version; +} diff --git a/wysiwygcck.js b/wysiwygcck.js index 635e0e2..7b83c0f 100644 --- a/wysiwygcck.js +++ b/wysiwygcck.js @@ -1,7 +1,7 @@ /** * This module proposes that we add another method to the API for the editors used - * in the wysiwyg module (wysiwyg/editors/js/*.js). Until we can count on those js + * in the wysiwyg module (wysiwyg/editors/js/*.js). Until we can count on those js * files implementing it, we place some default implementations here. */ Drupal.wysiwyg.editor.triggerSave.tinymce = Drupal.wysiwyg.editor.triggerSave.tinymce || function(context, params) { @@ -16,7 +16,7 @@ Drupal.wysiwyg.editor.triggerSave.fckeditor = Drupal.wysiwyg.editor.triggerSave. * Attach behavior to forms, so that prior to serializing during AJAX submit, * there's an opportunity to save editor content to the target element. * The form-pre-serialize event is only available with jquery.form.js 2.16 or later, - * which is why this module has jquery_form_update as a dependency. + * which is why this module has jquery_update as a dependency. */ Drupal.behaviors.wysiwygcck = function(context) { $('form:not(.wysiwygcck-processed)').each(function() { @@ -47,25 +47,25 @@ Drupal.wysiwygcck.triggerSave = function(context) { */ Drupal.wysiwygcck.getInstances = function(context) { var result = null; - + if (Drupal.wysiwyg && Drupal.wysiwyg.instances) { for (var id in Drupal.wysiwyg.instances) { var instance = Drupal.wysiwyg.instances[id]; if (instance.status && jQuery('#' + id, context).length) { if (!result) { result = {}; - } + } result[id] = {}; // Params should not include complex data types. for (var i in instance) { - if (jQuery.inArray(typeof(instance[i]), ['object', 'array', 'function']) == -1) { + if (jQuery.inArray(typeof(instance[i]), ['object', 'array', 'function']) == -1) { result[id][i] = instance[i]; } } } } } - + return result; } @@ -81,7 +81,7 @@ if (Drupal.tableDrag) { if (this.group.length > 1) { return invocation.proceed(); } - + // Get the editor instances in the row being dragged. If there aren't any, let tabledrag's // default implementation proceed. var position = invocation.arguments[0]; @@ -91,16 +91,16 @@ if (Drupal.tableDrag) { if (!instances) { return invocation.proceed(); } - + // If thisRow is the same as referenceRow, then nothing will happen during a swap. // However, letting the default swap behavior run will result in the editors' iframes // being reloaded and messed up, so instead, we just force nothing to happen. if (thisRow == referenceRow) { return; } - + // If we reached here, it means we need to let tabledrag swap the rows. However, - // if the editors have iframes, they'll probably get messed up by the swap, + // if the editors have iframes, they'll probably get messed up by the swap, // so we want to detach the editors before the swap, and reattach them after the swap. for (var id in instances) { Drupal.wysiwygDetach(thisRow, instances[id]); @@ -109,7 +109,7 @@ if (Drupal.tableDrag) { for (var id in instances) { Drupal.wysiwygAttach(thisRow, instances[id]); }; - + return result; }); }