]> gitweb.fluxo.info Git - lorea/elgg.git/commitdiff
Refs #2538: Cleaned up custom tinymce code into elgg.tinymce.*.
authorewinslow <ewinslow@36083f99-b078-4883-b0ff-0f9b5a30f544>
Tue, 1 Mar 2011 08:00:53 +0000 (08:00 +0000)
committerewinslow <ewinslow@36083f99-b078-4883-b0ff-0f9b5a30f544>
Tue, 1 Mar 2011 08:00:53 +0000 (08:00 +0000)
Refs #2895: TinyMCE makes use of longtext menu

git-svn-id: http://code.elgg.org/elgg/trunk@8533 36083f99-b078-4883-b0ff-0f9b5a30f544

mod/tinymce/start.php
mod/tinymce/views/default/input/longtext.php [deleted file]
mod/tinymce/views/default/js/tinymce.php [new file with mode: 0644]
mod/tinymce/views/default/tinymce/init.php
views/default/input/longtext.php

index 9a33f03a33e2bed9e92ee1e1c358d29c01202579..89c378376eca226e503eb5cf52560b74bb3cdf33 100644 (file)
@@ -8,7 +8,24 @@
 function tinymce_init() {
        elgg_extend_view('css/elgg', 'tinymce/css');
        elgg_extend_view('css/admin', 'tinymce/css');
+       
+       elgg_extend_view('input/longtext', 'tinymce/init');
+       
        elgg_extend_view('embed/custom_insert_js', 'tinymce/embed_custom_insert_js');
+       
+       elgg_register_plugin_hook_handler('register', 'menu:longtext', 'tinymce_longtext_menu');
+}
+
+function tinymce_longtext_menu($hook, $type, $items, $vars) {
+       
+       $items[] = array(
+               'name' => 'tinymce_toggler',
+               'class' => 'tinymce-toggle-editor',
+               'href' => "javascript:elgg.tinymce.toggleEditor('{$vars['id']}');",
+               'text' => elgg_echo('tinymce:remove'),
+       );
+       
+       return $items;
 }
 
 elgg_register_event_handler('init', 'system', 'tinymce_init', 9999);
diff --git a/mod/tinymce/views/default/input/longtext.php b/mod/tinymce/views/default/input/longtext.php
deleted file mode 100644 (file)
index 9124a89..0000000
+++ /dev/null
@@ -1,32 +0,0 @@
-<?php
-/**
- * Long text input with the tinymce text editor
- *
- * @package ElggTinyMCE
- *
- * @uses $vars['value'] The current value, if any
- * @uses $vars['js']    Any Javascript to enter into the input tag
- * @uses $vars['name']  The name of the input field
- * @uses $vars['id']    The id of the input field
- *
- */
-
-elgg_register_js('mod/tinymce/vendor/tinymce/jscripts/tiny_mce/tiny_mce.js', 'tinymce');
-
-// make sure the init script is only loaded once
-elgg_unextend_view('footer/analytics', 'tinymce/init');
-elgg_extend_view('footer/analytics', 'tinymce/init');
-
-if (!isset($vars['id'])) {
-       $vars['id'] = 'tinymce-longtext-' . rand();
-}
-
-?>
-
-<a class="elgg-longtext-control tinymce-toggle-editor small" href="javascript:toggleEditor('<?php echo $vars['id']; ?>');">
-       <?php echo elgg_echo('tinymce:remove'); ?>
-</a>
-
-<textarea class="elgg-input-textarea mceEditor" name="<?php echo $vars['name']; ?>" id="<?php echo $vars['id']; ?>" <?php echo $vars['js']; ?>>
-<?php echo htmlspecialchars($vars['value'], null, 'UTF-8'); ?>
-</textarea>
diff --git a/mod/tinymce/views/default/js/tinymce.php b/mod/tinymce/views/default/js/tinymce.php
new file mode 100644 (file)
index 0000000..adff521
--- /dev/null
@@ -0,0 +1,59 @@
+elgg.tinymce.toggleEditor = function(id) {
+       if (!tinyMCE.get(id)) {
+               tinyMCE.execCommand('mceAddControl', false, id);
+               <?php //FIXME This changes all controls on the page!! ?>
+               $("a.tinymce-toggle-editor").html(elgg.echo('tinymce:remove'));
+       } else {
+               tinyMCE.execCommand('mceRemoveControl', false, id);
+               $("a.tinymce-toggle-editor").html(elgg.echo('tinymce:add'));
+       }
+}
+
+/**
+ * TinyMCE initialization script
+ *
+ * You can find configuration information here:
+ * http://tinymce.moxiecode.com/wiki.php/Configuration
+ */
+elgg.tinymce.init = function() {
+       tinyMCE.init({
+               mode : "specific_textareas",
+               editor_selector : "elgg-input-longtext",
+               theme : "advanced",
+               plugins : "spellchecker,autosave,fullscreen,paste",
+               relative_urls : false,
+               remove_script_host : false,
+               document_base_url : elgg.config.wwwroot,
+               theme_advanced_buttons1 : "bold,italic,underline,separator,strikethrough,bullist,numlist,undo,redo,link,unlink,image,blockquote,code,pastetext,pasteword,more,fullscreen",
+               theme_advanced_buttons2 : "",
+               theme_advanced_buttons3 : "",
+               theme_advanced_toolbar_location : "top",
+               theme_advanced_toolbar_align : "left",
+               theme_advanced_statusbar_location : "bottom",
+               theme_advanced_resizing : true,
+               theme_advanced_path : true,
+               extended_valid_elements : "a[name|href|target|title|onclick],img[class|src|border=0|alt|title|hspace|vspace|width|height|align|onmouseover|onmouseout|name|style],hr[class|width|size|noshade],font[face|size|color|style],span[class|align|style]",
+               setup : function(ed) {
+                       //show the number of words
+                       ed.onLoadContent.add(function(ed, o) {
+                               var strip = (tinyMCE.activeEditor.getContent()).replace(/(&lt;([^&gt;]+)&gt;)/ig,"");
+                               var text = " <?php echo elgg_echo('tinymce:word_count'); ?>" + strip.split(' ').length + ' ';
+                               tinymce.DOM.setHTML(tinymce.DOM.get(tinyMCE.activeEditor.id + '_path_row'), text);
+                       });
+       
+                       ed.onKeyUp.add(function(ed, e) {
+                               var strip = (tinyMCE.activeEditor.getContent()).replace(/(&lt;([^&gt;]+)&gt;)/ig,"");
+                               var text = " <?php echo elgg_echo('tinymce:word_count'); ?>" + strip.split(' ').length + ' ';
+                               tinymce.DOM.setHTML(tinymce.DOM.get(tinyMCE.activeEditor.id + '_path_row'), text);
+                       });
+               },
+               content_css: elgg.config.wwwroot + 'mod/tinymce/tinymce_content.css'
+       });
+
+       $('.elgg-input-longtext').parents('form').submit(function() {
+               tinyMCE.triggerSave();
+       });
+
+});
+
+elgg.register_event_handler('init', 'system', elgg.tinymce.init);
\ No newline at end of file
index 7064709d646b647332825dad6c069ef9ffd9c426..100a1a9878c0abe2a58b24a0cbdbb84da6598f70 100644 (file)
@@ -1,62 +1,4 @@
 <?php
-/**
- * TinyMCE initialization script
- *
- * You can find configuration information here:
- * http://tinymce.moxiecode.com/wiki.php/Configuration
- */
-?>
-<?php //@todo JS 1.8: no ?>
-<script type="text/javascript">
-tinyMCE.init({
-       mode : "specific_textareas",
-       editor_selector : "mceEditor",
-       theme : "advanced",
-       plugins : "spellchecker,autosave,fullscreen,paste",
-       relative_urls : false,
-       remove_script_host : false,
-       document_base_url : "<?php echo elgg_get_site_url(); ?>",
-       theme_advanced_buttons1 : "bold,italic,underline,separator,strikethrough,bullist,numlist,undo,redo,link,unlink,image,blockquote,code,pastetext,pasteword,more,fullscreen",
-       theme_advanced_buttons2 : "",
-       theme_advanced_buttons3 : "",
-       theme_advanced_toolbar_location : "top",
-       theme_advanced_toolbar_align : "left",
-       theme_advanced_statusbar_location : "bottom",
-       theme_advanced_resizing : true,
-       theme_advanced_path : true,
-       extended_valid_elements : "a[name|href|target|title|onclick],img[class|src|border=0|alt|title|hspace|vspace|width|height|align|onmouseover|onmouseout|name|style],hr[class|width|size|noshade],font[face|size|color|style],span[class|align|style]",
-       setup : function(ed) {
-               //show the number of words
-               ed.onLoadContent.add(function(ed, o) {
-                       var strip = (tinyMCE.activeEditor.getContent()).replace(/(&lt;([^&gt;]+)&gt;)/ig,"");
-                       var text = " <?php echo elgg_echo('tinymce:word_count'); ?>" + strip.split(' ').length + ' ';
-                       tinymce.DOM.setHTML(tinymce.DOM.get(tinyMCE.activeEditor.id + '_path_row'), text);
-               });
 
-               ed.onKeyUp.add(function(ed, e) {
-                       var strip = (tinyMCE.activeEditor.getContent()).replace(/(&lt;([^&gt;]+)&gt;)/ig,"");
-                       var text = " <?php echo elgg_echo('tinymce:word_count'); ?>" + strip.split(' ').length + ' ';
-                       tinymce.DOM.setHTML(tinymce.DOM.get(tinyMCE.activeEditor.id + '_path_row'), text);
-               });
-       },
-       content_css: '<?php echo elgg_get_site_url(); ?>mod/tinymce/tinymce_content.css'
-});
-
-function toggleEditor(id) {
-       if (!tinyMCE.get(id)) {
-               tinyMCE.execCommand('mceAddControl', false, id);
-               <?php $toggleEditor_linktext = elgg_echo('tinymce:remove'); ?>
-               $("a.tinymce-toggle-editor").html('<?php echo $toggleEditor_linktext ?>');
-       } else {
-               tinyMCE.execCommand('mceRemoveControl', false, id);
-               <?php $toggleEditor_linktext = elgg_echo('tinymce:add'); ?>
-               $("a.tinymce-toggle-editor").html('<?php echo $toggleEditor_linktext ?>');
-       }
-}
-
-$(document).ready(function() {
-       $('textarea').parents('form').submit(function() {
-               tinyMCE.triggerSave();
-       });
-});
-</script>
+elgg_register_js('mod/tinymce/vendor/tinymce/jscripts/tiny_mce/tiny_mce.js', 'tinymce');
+elgg_register_js(elgg_get_simplecache_url('js', 'tinymce'), 'elgg.tinymce');
\ No newline at end of file
index ada419f13fe6d612e1153868265f657af07163e2..edff2da8710f10519396e82b37830e3ae78c2986 100644 (file)
@@ -12,6 +12,7 @@
 
 $defaults = array(
        'class' => 'elgg-input-longtext',
+       'id' => 'elgg-input-' . rand(), //@todo make this more robust
 );
 
 // work around for deprecation code in elgg_views()
@@ -20,4 +21,5 @@ unset($vars['internalid']);
 
 $vars = array_merge($defaults, $vars);
 
+echo elgg_view_menu('longtext', array('sort_by' => 'weight'));
 echo elgg_view('input/plaintext', $vars);