[EXTENSION] TinyMCE using jQuery
#42
Posted 11 December 2009 - 03:30 AM
There is a problem with dynamic loading both "native" tinymce and lazy loading
with gzip compressor.
Saying "dynamic loading" I mean complete dynamic loading when tiny_mce.js or
tiny_mce_gzip.js also loaded into the page dynamically.
Here is my use case:
I have GUI builder which creates dynamically tabled views (for example, news
list) and edit forms where none or one or more textareas with tinyMCE can be used.
Forms are added to the page dynamically into jQuery / UI Dialog.
Forms is generated as a set of widget and I have a widget for tinyMCE.
Since this GUI builder is generic I do not want to include tinymce core script
to all pages, but load it dynamically when appropriate widget is rendered on the
form.
Now I get to work both loading tiny_mce.js or tiny_mce_gzip.js dynamically and
had to solve some problems.
1. Dynamic loading of tiny_mce.js.
We have here two major issues: first - tinyMCE._init fails to set correct baseURL so other scripts not
loaded and second - scriptLoader.loadScripts by default
loads scripts with document.write and this breaks the page (all page content is gone).
Both problems where solved with following approach:
if (!window.tinymce) {
//set base URL for tinymce
window.tinyMCEPreInit = {base : '$assets/tinymce', suffix : '', query : ''};
//load tinymce
jQuery.ajax({
type : 'GET',
url : '$assets/tinymce/tiny_mce.js',
async : false,
success : function(co) {
var w = window;
// Evaluate script
if (!w.execScript) {
try {
eval.call(w, co);
} catch (ex) {
eval(co, w); // Firefox 3.0a8
}
} else {
w.execScript(co); // IE
}
//load scripts with dom manipulation instead of document.write
w.tinymce.dom.Event.domLoaded = true;
}
});
}
// Init textarea with jquery plugin
jQuery("#{$id}").tinyMCE({$tinyOptions}, '{$jsMode}', {$jsUseCookies});
I add js code to the page to load core tinymce script dynamically and create
window.tinyMCEPreInit object before script is loaded to set correct baseURL to solve first problem
and set tinymce.dom.Event.domLoaded = true after script is loaded to solve second.
Full text of modified ETinyMCE::init() method:
2. Dynamic loading of tiny_mce_gzip.js
Here also two problems exist: first with base URL mentionad above and second -
with sequential calls of tinyMCE_GZ.init for more then one textareas.
I need to call tinyMCE_GZ.init more then once becuse when dialog with form is generated I
could not know how many tinymce widgets exists and each widget initializes
itself with such code:
function initTinyGZ_$id() {
// Init textarea with jquery plugin
jQuery("#{$id}").tinyMCE({$tinyOptions}, '{$jsMode}', {$jsUseCookies});
}
// this is for tinymce core when it will be loaded by tiny_mce_gzip.js
window.tinyMCEPreInit = {base : '$assets/tinymce', suffix : '', query : ''};
// init compressor and pass textarea initialization as callback
tinyMCE_GZ.init({$gzOptions}, function() { initTinyGZ_$id(); });
To solve problems I have with tiny_mce_gzip.js I had to modify its code.
To fix problem with base URL I added special setting to provide external base
URL through options and changed init() method to take that parameter.
To solve problem with sequential init() calls I changed init() function to
invoke callback even if core scripts are already loaded:
if (!t.coreLoaded)
t.loadScripts(1, s.themes, s.plugins, s.languages, cb, sc);
else
// SEB - scripts are loaded only once (loadScripts method sets t.coreLoaded to true)
// if we have two textareas on the page and provide tiniymce initialization in the
// callback function then second callback was never called
cb.call(sc || t, null);
and changed loadScripts to load core synchronously so second init() call will be
performed when scripts are actually loaded into the page:
//SEB - make syncronous call
x.open('GET', t.baseURL + '/' + s.page_name + '?' + q, false);
//x.setRequestHeader('Content-Type', 'text/javascript');
x.send('');
if (co)
t.coreLoaded = 1;
// SEB - Handle syncronous loading
if (cb && x.status == 200) {
t.loaded = 1;
t.eval(x.responseText);
tinymce.dom.Event.domLoaded = true;
cb.call(sc || t, x);
} else {
t.eval(x.responseText);
}
Modified text of tiny_mce_gzip.js:
#43
Posted 11 December 2009 - 09:27 AM
#44
Posted 10 January 2010 - 05:10 PM
alaevka, on 24 November 2009 - 05:05 AM, said:
My code is:
<?php $this->widget('application.extensions.tinymce.ETinyMce',
array(
'name'=>'Text1[data]',
'id'=>'Text1_text1_data',
'plugins' => array('filemanager','imagemanager','safari','pagebreak','style','layer','table','save','advhr','advimage','advlink','emotions','iespell','inlinepopups','insertdatetime','preview','media','searchreplace','print','contextmenu','paste','directionality','fullscreen','noneditable','visualchars','nonbreaking','xhtmlxtras','template'),
'options' => array(
'theme' => 'advanced',
'skin' => 'o2k7',
'theme_advanced_buttons1' => 'preview,bold,italic,underline,fontselect,fontsizeselect,link,justifyfull,justifyleft,justifycenter,justifyright,pasteword,pastetext,table,image,|,bullist,numlist,|,undo,redo,|,code,fullscreen',
'theme_advanced_buttons2' => '',
'theme_advanced_buttons3' => '',
),
'value' => $model->data,
));
?>
Hi I have the same problem with the image manager, did you ever get this to work? If so I would greatly appreciate some advice...
#45
Posted 10 February 2010 - 07:50 PM
How do you set "document_base_url" with this extension ?
Thanks!
#46
Posted 12 February 2010 - 02:21 PM
I have my own server with a site running this extension fine. I use the same exact code on a web host I don't own and I can't get this extension to load. The one thing I'm noticing is that on the one that doesn't work the compressed file doesn't get created in the assets directory (under the tiny_mce folder). Anyone have any ideas why or what I can do to debug it? I don't get any errors on the page, it just loads a text box with no TinyMCE.
#47
Posted 15 May 2010 - 09:59 AM
seb, on 11 December 2009 - 03:30 AM, said:
There is a problem with dynamic loading both "native" tinymce and lazy loading
with gzip compressor.
Saying "dynamic loading" I mean complete dynamic loading when tiny_mce.js or
tiny_mce_gzip.js also loaded into the page dynamically.
Here is my use case:
I have GUI builder which creates dynamically tabled views (for example, news
list) and edit forms where none or one or more textareas with tinyMCE can be used.
Forms are added to the page dynamically into jQuery / UI Dialog.
Forms is generated as a set of widget and I have a widget for tinyMCE.
Since this GUI builder is generic I do not want to include tinymce core script
to all pages, but load it dynamically when appropriate widget is rendered on the
form.
Now I get to work both loading tiny_mce.js or tiny_mce_gzip.js dynamically and
had to solve some problems.
1. Dynamic loading of tiny_mce.js.
We have here two major issues: first - tinyMCE._init fails to set correct baseURL so other scripts not
loaded and second - scriptLoader.loadScripts by default
loads scripts with document.write and this breaks the page (all page content is gone).
Both problems where solved with following approach:
if (!window.tinymce) {
//set base URL for tinymce
window.tinyMCEPreInit = {base : '$assets/tinymce', suffix : '', query : ''};
//load tinymce
jQuery.ajax({
type : 'GET',
url : '$assets/tinymce/tiny_mce.js',
async : false,
success : function(co) {
var w = window;
// Evaluate script
if (!w.execScript) {
try {
eval.call(w, co);
} catch (ex) {
eval(co, w); // Firefox 3.0a8
}
} else {
w.execScript(co); // IE
}
//load scripts with dom manipulation instead of document.write
w.tinymce.dom.Event.domLoaded = true;
}
});
}
// Init textarea with jquery plugin
jQuery("#{$id}").tinyMCE({$tinyOptions}, '{$jsMode}', {$jsUseCookies});
I add js code to the page to load core tinymce script dynamically and create
window.tinyMCEPreInit object before script is loaded to set correct baseURL to solve first problem
and set tinymce.dom.Event.domLoaded = true after script is loaded to solve second.
Full text of modified ETinyMCE::init() method:
2. Dynamic loading of tiny_mce_gzip.js
Here also two problems exist: first with base URL mentionad above and second -
with sequential calls of tinyMCE_GZ.init for more then one textareas.
I need to call tinyMCE_GZ.init more then once becuse when dialog with form is generated I
could not know how many tinymce widgets exists and each widget initializes
itself with such code:
function initTinyGZ_$id() {
// Init textarea with jquery plugin
jQuery("#{$id}").tinyMCE({$tinyOptions}, '{$jsMode}', {$jsUseCookies});
}
// this is for tinymce core when it will be loaded by tiny_mce_gzip.js
window.tinyMCEPreInit = {base : '$assets/tinymce', suffix : '', query : ''};
// init compressor and pass textarea initialization as callback
tinyMCE_GZ.init({$gzOptions}, function() { initTinyGZ_$id(); });
To solve problems I have with tiny_mce_gzip.js I had to modify its code.
To fix problem with base URL I added special setting to provide external base
URL through options and changed init() method to take that parameter.
To solve problem with sequential init() calls I changed init() function to
invoke callback even if core scripts are already loaded:
if (!t.coreLoaded)
t.loadScripts(1, s.themes, s.plugins, s.languages, cb, sc);
else
// SEB - scripts are loaded only once (loadScripts method sets t.coreLoaded to true)
// if we have two textareas on the page and provide tiniymce initialization in the
// callback function then second callback was never called
cb.call(sc || t, null);
and changed loadScripts to load core synchronously so second init() call will be
performed when scripts are actually loaded into the page:
//SEB - make syncronous call
x.open('GET', t.baseURL + '/' + s.page_name + '?' + q, false);
//x.setRequestHeader('Content-Type', 'text/javascript');
x.send('');
if (co)
t.coreLoaded = 1;
// SEB - Handle syncronous loading
if (cb && x.status == 200) {
t.loaded = 1;
t.eval(x.responseText);
tinymce.dom.Event.domLoaded = true;
cb.call(sc || t, x);
} else {
t.eval(x.responseText);
}
Modified text of tiny_mce_gzip.js:
I don't understand why for me this solution don't work. I open dialog so:
$('.update').live('click',(function(){
var id=$(this).attr('id');
$.ajax({
url: '".Yii::app()->createUrl("admin/offerte/update")."&id='+id,
success: function(data) {
$('#dialog').html(data);
var buttons = $( '#dialog' ).dialog( 'option', 'buttons' );
$('#dialog').dialog('open');
return false;
}});
}));
#48
Posted 26 June 2010 - 09:09 PM
Jaime, on 28 August 2009 - 10:04 PM, said:
error_reporting(E_ALL ^ E_NOTICE);
but.. I don't think this is the correct solution. It seems like a patch.
The line that causes the error is:
$tinyOptions = $this->makeOptions($tinymce);
That line calls
protected function makeOptions($url='')
so, $tinymce variable is a url. But, which URL is it?
Thanks
Jaime
Same here, why it wasn't solved yet?
What is the purpose of $tinymce variable?
1 - I don't want to change the core.
2 - I don't want do disable warning.
What is the best approach?
Thanks
#49
Posted 11 August 2010 - 11:35 PM
$this->widget('application.extensions.tinymce.ETinyMce',
array(
'name'=>'html',
'editorTemplate' => 'full',
'options' => array('plugins' => 'test1,test2'),
)
);
Then the list of plug-ins for tinyMCE_GZ remains not changed in page script:
tinyMCE_GZ.init({'plugins':'safari,pagebreak,style,...);
But:
window.onload=function() {
jQuery("#html").tinyMCE({...,'plugins':'test1,test2'}, 'html', true);
};
Is it correct?
#50
Posted 24 September 2010 - 02:30 PM
Ismael, on 26 June 2010 - 09:09 PM, said:
What is the purpose of $tinymce variable?
1 - I don't want to change the core.
2 - I don't want do disable warning.
What is the best approach?
Thanks
It appears the $tinymce variable should be the $assets variable as it is used by makeFullEditor(). I've changed this and it appears to be working correctly.
#51
Posted 11 October 2010 - 03:08 AM
I have integrated this extension and it works great.
I have a little problem with generated xhtml code. It is written in db as it should be but when I generate view to show the entered elements I see the tags and they are not interpreted by the browser (i see html code on my page, I mean tags).
What could be wrong ?
#52
Posted 12 October 2010 - 06:07 PM
I see some others have found the anomololy but I didn't read all posts to see if it was solved. This worked for me
// $tinyOptions = $this->makeOptions($tinymce); // broken in Wampp on Vista but works on Linux box ??
$tinyOptions = $this->makeOptions(); // this works on both It seems that $tinymce just evaluates to null on the linux box, wampp croaks.
dunno why!!
doodle
#53
Posted 12 October 2010 - 06:10 PM
kevinb, on 24 September 2010 - 02:30 PM, said:
Could you post your changes? Probably better than my approach
#54
Posted 22 October 2010 - 08:57 AM
got 2 doodle, on 12 October 2010 - 06:10 PM, said:
I believe this is what he did, but I've made several other modifications so I'm not 100% sure that this fixed it completely.
In protected/extensions/tinymce/ETinyMce.php, line 842:
find:
$tinyOptions = $this->makeOptions($tinymce);
change to:
$tinyOptions = $this->makeOptions($assets);
#55
Posted 29 October 2010 - 04:43 AM
"theme_advanced_path"=> false, removed "theme_advanced_statusbar_location" from list, but it steal showes me path bar, hm thats the problem i decided to dig a source ETinyMce.php and founded out that developers defined it for the user $options['theme_advanced_path_location'] = 'bottom'; twice at line 691 and 698, and other parameter that must be removed $options['theme_advanced_path_location'] at line 701 plugin version 1.1 no problems for developer greate thx for him o her just make a remark
#56
Posted 26 November 2010 - 05:26 PM
. Fixed $tinymce variable issue (replaced with $assets)
. Upgraded to latest version of tinymce, 3.3.9.2
. Fixed certain plugins from autoloading, due to the $this->plugins being hardcoded. Now looks to see if the plugins array is empty before applying default plugins.
I'd like to share these with the community, how should I go about doing that ?
Thanks
#57
Posted 26 November 2010 - 06:15 PM
I can see that the extension hasn't been updated since Aug 18, 2009.
And that means that the author wrote the extension, uploaded the initial version, and then made an update to it two months later.
And then left it behind.
I would create a new extension (page) and put the code up on a public repository.
Google code, Github, Bitbucket?
IMO, that's the best approach.
<edit>
Of course, you could ask 'someone' (moderator/team?) to allow you to take over the extension..
</edit>
#58
Posted 21 February 2011 - 05:19 AM
ianaré, on 26 November 2010 - 05:26 PM, said:
. Fixed $tinymce variable issue (replaced with $assets)
. Upgraded to latest version of tinymce, 3.3.9.2
. Fixed certain plugins from autoloading, due to the $this->plugins being hardcoded. Now looks to see if the plugins array is empty before applying default plugins.
I'd like to share these with the community, how should I go about doing that ?
Thanks
Can you or did you publish your changes somewhere?
#59
Posted 02 May 2011 - 06:14 PM
I used this extension and it works perfect on localhost, but when I upload it to my web server, it stops working.
After looking I found out that it's caused because the file tiny_mce_gzip.php could not be accessed because of its containing folder having permission of 777. If I change the permission of the whole folder (/assets/tiny_mce) to 755, then it works.
Why is this happening?
Thanks
#60
Posted 09 June 2011 - 07:07 AM
mime_type.diff.txt (1.95K)
Number of downloads: 19

Help
















