Change how init files are loaded
| Project: | Image Browser |
| Version: | 6.x-2.x-dev |
| Component: | Miscellaneous |
| Category: | bug report |
| Priority: | normal |
| Assigned: | Unassigned |
| Status: | active |
When activating the (sub)module "Image Browser Plugin - WYSIWYG API" the browser drop the folowing error:
IE V8.0.6: Drupal.wysiwyg.plugins is null or not an object.
Mozilla/5.0 (Firefox/3.5.4): Drupal.wysiwyg is undefined.
I went deep into the code and it appears to be that the file wysiwyg.init.js is not being included or the Drupal object is being overwritten, that's why when the IB module load the code "Drupal.wysiwyg.plugins.imagebrowser = {
/**
* Return whether the passed node belongs to this plugin.
*/
isNode: function(node) {
return ($(node).is('img.ibimage'));
},"
the browser dosent find a valid object.
I must say that when the module IB is enable but the (sub)module "Image Browser Plugin - WYSIWYG API" is disable the error is not present but i'm reporting this issue here becouse i think this module has more responsability for this error although i will let know to the developers of IB module.

#1
This situation can be seen in the same demo page of the IB module http://ib2.coredesigns.co.uk/
#2
I imagine it's more my problem. I'll take a peak when I can.
#3
Thanks!
#4
I also experience this problem. Additionally i get:
$("#ib_dialog").dialog is not a functionwhen I click on the Imagebrowser button. I enclose screenshot made with Firebug.
#5
Quick and dirty fix:
add several js lines at the begining of plugins/ib_wysiwyg/ib_wysiwyg_init.js file.
Drupal.wysiwyg = Drupal.wysiwyg || { 'instances': {} };
Drupal.wysiwyg.editor = Drupal.wysiwyg.editor || { 'init': {}, 'attach': {}, 'detach': {}, 'instance': {} };
Drupal.wysiwyg.plugins = Drupal.wysiwyg.plugins || {};
#6
That did not do it for me. Without the dirty fix I get the error:
Drupal.wysiwyg.plugins.imagebrowser = { drupal.wysiwyg is undefined on line 30
With the fix I get:
uncaught exception: [Exception... "Could not convert JavaScript argument arg 0" nsresult: "0x80570009 (NS_ERROR_XPC_BAD_CONVERT_JS)" location: "JS frame :: https://portal7.edreslib.org/sandbox2/misc/jquery.js?t :: anonymous :: line 13" data: no]
Line 0
Note: The wysiwyg_init.js is inserted, but it is in head of the page, but it is missing in the head of the editor's iframe! Shouldn't it be inserted there? And when I think of it, may be both should be inserted there?
#7
Hey everyone. Sorry for the lack of response. Had an unexpected spell in hospital, but I'm back now.
Is this JS error only seen in IE8 or earlier? I'm not seeing it in Safari or Firefox.
Please let me know your browser, version and operating system. Cheers
#8
I see this error in Safari 4.0.4 and Firefox 3.5.5 both on Mac OS X.
Modifying the
ib_wysiwyg_init()function inimagebrowser/plugins/ib_wysiwyg/ib_wysiwyg.moduleso that theib_wysiwyg_init.jsJavaScript file is included in the footer rather than the head as per default makes the error go away:<?phpfunction ib_wysiwyg_init() {
drupal_add_js(drupal_get_path('module', 'ib_wysiwyg') . "/ib_wysiwyg_init.js", 'module', 'footer');
drupal_add_css(drupal_get_path('module', 'ib_wysiwyg') . "/ib_wysiwyg_init.css");
if(module_exists('jquery_ui')){ jquery_ui_add('ui.dialog'); };
}
?>
This suggests that this is due to the JavaScript being loaded before something it depends on.
#9
Ah I thought the error was causing something not to work. It still works fine, you just get that JS error. It's due to the fact that those files shouldn't even be loaded in the imagebrowser window.
The quickfix is to change this function in ib_wysiwyg.module
function ib_wysiwyg_init() {if (arg(0) != 'imagebrowser') {
drupal_add_js(drupal_get_path('module', 'ib_wysiwyg') . "/ib_wysiwyg_init.js");
drupal_add_css(drupal_get_path('module', 'ib_wysiwyg') . "/ib_wysiwyg_init.css");
if(module_exists('jquery_ui')){ jquery_ui_add('ui.dialog'); };
}
}
A better fix is needed however to intelligently load the ib_wysiwyg_init.js file on any page which has a wysiwyg editor loaded.
#10
Neither my modification in comment 8 above, not that in comment 9 fixes this issue in all cases. I still get the
ib_wysiwyg_init.jsincluded incorrectly (on the front page, for example).wysiwyg.modulecontains the following comment:<?php// Collect native plugins for this editor provided via hook_wysiwyg_plugin()
// and Drupal plugins provided via hook_wysiwyg_include_directory().
?>
This suggests that both these hooks are only called when the WYSIWYG module is actually being used in a form. I've traced through the code and this seems to be the case.
I moved the three lines in
ib_wysiwyg_init()intoib_wysiwyg_wysiwyg_include_directory()instead, and this seems to have fixed the issue:ib_wysiwyg_init.jsis included on only those pages that use the WYSIWYG module and the JavaScript error is no more.#11
awesome work. I'll roll that in :)
#12
sub +1 (feel ashamed everytime I do this)
#13
Hi just stumbled upon this bug as well, it appears in every browsers and is due to the fact that the javascript for the wysiwyg plugin is included in each and every page whereas the wysiwyg javascript (upon which it depends) is only included when necessary.
To correct this I moved the drupal_add_js calls from the ib_wysiwyg_init() to the ib_wysiwyg_imagebrowser_plugin(), it looked more logical than other proposed solutions :)