Change how init files are loaded

neoglez - November 10, 2009 - 12:52
Project:Image Browser
Version:6.x-2.x-dev
Component:Miscellaneous
Category:bug report
Priority:normal
Assigned:Unassigned
Status:active
Description

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

neoglez - November 10, 2009 - 13:25

This situation can be seen in the same demo page of the IB module http://ib2.coredesigns.co.uk/

AttachmentSize
error.JPG 84.44 KB

#2

Starnox - November 10, 2009 - 19:13
Project:Wysiwyg» Image Browser
Version:6.x-2.x-dev» 6.x-2.x-dev

I imagine it's more my problem. I'll take a peak when I can.

#3

neoglez - November 11, 2009 - 08:10

Thanks!

#4

milos.kroulik - November 22, 2009 - 20:59
Priority:normal» critical

I also experience this problem. Additionally i get:

$("#ib_dialog").dialog is not a function

when I click on the Imagebrowser button. I enclose screenshot made with Firebug.

AttachmentSize
imagebrowser_error.png 24.95 KB

#5

ihanick - November 29, 2009 - 23:15

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

com2 - December 2, 2009 - 13:10

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

Starnox - December 5, 2009 - 21:47

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

thsutton - December 9, 2009 - 07:47

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 in imagebrowser/plugins/ib_wysiwyg/ib_wysiwyg.module so that the ib_wysiwyg_init.js JavaScript file is included in the footer rather than the head as per default makes the error go away:

<?php
function 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

Starnox - December 9, 2009 - 09:12
Title:JavaScript error: Drupal.wysiwyg.plugins is null or not an object» Change how init files are loaded
Priority:critical» normal

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

thsutton - December 10, 2009 - 03:08

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.js included incorrectly (on the front page, for example).

wysiwyg.module contains 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() into ib_wysiwyg_wysiwyg_include_directory() instead, and this seems to have fixed the issue: ib_wysiwyg_init.js is included on only those pages that use the WYSIWYG module and the JavaScript error is no more.

#11

Starnox - December 10, 2009 - 07:57

awesome work. I'll roll that in :)

#12

perandre - December 16, 2009 - 10:49

sub +1 (feel ashamed everytime I do this)

#13

cvedovini - December 20, 2009 - 22:03

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 :)

AttachmentSize
imagebrowser_patch.txt 1.16 KB
 
 

Drupal is a registered trademark of Dries Buytaert.