Load tinyMCE on post editor only if needed.

This commit is contained in:
Fabio Comuni 2011-07-20 11:08:42 +02:00
parent 11d1d309c2
commit 7a069c1438
5 changed files with 98 additions and 67 deletions

View File

@ -80,7 +80,9 @@ function editpost_content(&$a) {
call_hooks('jot_tool', $jotplugins); call_hooks('jot_tool', $jotplugins);
call_hooks('jot_networks', $jotnets); call_hooks('jot_networks', $jotnets);
$tpl = replace_macros($tpl,array('$jotplugins' => $jotplugins));
//$tpl = replace_macros($tpl,array('$jotplugins' => $jotplugins));
$o .= replace_macros($tpl,array( $o .= replace_macros($tpl,array(
'$return_path' => $_SESSION['return_url'], '$return_path' => $_SESSION['return_url'],
@ -110,10 +112,10 @@ function editpost_content(&$a) {
'$lockstate' => $lockstate, '$lockstate' => $lockstate,
'$acl' => '', // populate_acl((($group) ? $group_acl : $a->user), $celeb), '$acl' => '', // populate_acl((($group) ? $group_acl : $a->user), $celeb),
'$bang' => (($group) ? '!' : ''), '$bang' => (($group) ? '!' : ''),
'$profile_uid' => $_SESSION['uid'] '$profile_uid' => $_SESSION['uid'],
'$jotplugins' => $jotplugins,
)); ));
return $o; return $o;
} }

View File

@ -1,68 +1,79 @@
<script language="javascript" type="text/javascript"> <script language="javascript" type="text/javascript">
var editor; var editor=false;
var textlen = 0; var textlen = 0;
function initEditor(){
$("#profile-jot-text-loading").show();
tinyMCE.init({
theme : "advanced",
mode : "specific_textareas",
editor_selector: /(profile-jot-text|prvmail-text)/,
plugins : "bbcode,paste,autoresize",
theme_advanced_buttons1 : "bold,italic,underline,undo,redo,link,unlink,image,forecolor,formatselect,code",
theme_advanced_buttons2 : "",
theme_advanced_buttons3 : "",
theme_advanced_toolbar_location : "top",
theme_advanced_toolbar_align : "center",
theme_advanced_blockformats : "blockquote,code",
paste_text_sticky : true,
entity_encoding : "raw",
add_unload_trigger : false,
remove_linebreaks : false,
force_p_newlines : false,
force_br_newlines : true,
forced_root_block : '',
convert_urls: false,
content_css: "$baseurl/view/custom_tinymce.css",
theme_advanced_path : false,
setup : function(ed) {
//Character count
ed.onKeyUp.add(function(ed, e) {
var txt = tinyMCE.activeEditor.getContent();
textlen = txt.length;
if(textlen != 0 && $('#jot-perms-icon').is('.unlock')) {
$('#profile-jot-desc').html(ispublic);
}
else {
$('#profile-jot-desc').html('&nbsp;');
}
tinyMCE.init({ if(textlen <= 140) {
theme : "advanced", $('#character-counter').removeClass('red');
mode : "specific_textareas", $('#character-counter').removeClass('orange');
editor_selector: /(profile-jot-text|prvmail-text)/, $('#character-counter').addClass('grey');
plugins : "bbcode,paste,autoresize", }
theme_advanced_buttons1 : "bold,italic,underline,undo,redo,link,unlink,image,forecolor,formatselect,code", if((textlen > 140) && (textlen <= 420)) {
theme_advanced_buttons2 : "", $('#character-counter').removeClass('grey');
theme_advanced_buttons3 : "", $('#character-counter').removeClass('red');
theme_advanced_toolbar_location : "top", $('#character-counter').addClass('orange');
theme_advanced_toolbar_align : "center", }
theme_advanced_blockformats : "blockquote,code", if(textlen > 420) {
paste_text_sticky : true, $('#character-counter').removeClass('grey');
entity_encoding : "raw", $('#character-counter').removeClass('orange');
add_unload_trigger : false, $('#character-counter').addClass('red');
remove_linebreaks : false, }
force_p_newlines : false, $('#character-counter').text(textlen);
force_br_newlines : true, });
forced_root_block : '',
convert_urls: false,
content_css: "$baseurl/view/custom_tinymce.css",
theme_advanced_path : false,
setup : function(ed) {
//Character count
ed.onKeyUp.add(function(ed, e) {
var txt = tinyMCE.activeEditor.getContent();
textlen = txt.length;
if(textlen != 0 && $('#jot-perms-icon').is('.unlock')) {
$('#profile-jot-desc').html(ispublic);
}
else {
$('#profile-jot-desc').html('&nbsp;');
}
if(textlen <= 140) { ed.onInit.add(function(ed) {
$('#character-counter').removeClass('red'); ed.pasteAsPlainText = true;
$('#character-counter').removeClass('orange'); $("#profile-jot-text-loading").hide();
$('#character-counter').addClass('grey'); $("#profile-jot-submit-wrapper").show();
} });
if((textlen > 140) && (textlen <= 420)) {
$('#character-counter').removeClass('grey');
$('#character-counter').removeClass('red');
$('#character-counter').addClass('orange');
}
if(textlen > 420) {
$('#character-counter').removeClass('grey');
$('#character-counter').removeClass('orange');
$('#character-counter').addClass('red');
}
$('#character-counter').text(textlen);
});
ed.onInit.add(function(ed) {
ed.pasteAsPlainText = true;
});
}
});
}
});
editor = true;
// setup acl popup
$("#profile-jot-acl-wrapper").hide();
$("a#jot-perms-icon").fancybox({
'transitionIn' : 'none',
'transitionOut' : 'none'
});
}
</script> </script>
<script type="text/javascript" src="include/ajaxupload.js" ></script> <script type="text/javascript" src="include/ajaxupload.js" ></script>
@ -70,11 +81,13 @@ tinyMCE.init({
var ispublic = '$ispublic'; var ispublic = '$ispublic';
$(document).ready(function() { $(document).ready(function() {
$("#profile-jot-acl-wrapper").hide(); /* enable tinymce on focus */
$("a#jot-perms-icon").fancybox({ $("#profile-jot-text").focus(function(){
'transitionIn' : 'none', if (editor) return;
'transitionOut' : 'none' $(this).val("");
}); initEditor();
});
var uploader = new window.AjaxUpload( var uploader = new window.AjaxUpload(
'wall-image-upload', 'wall-image-upload',

View File

@ -15,10 +15,12 @@
<input type="hidden" name="title" id="jot-title" value="" /> <input type="hidden" name="title" id="jot-title" value="" />
<input type="hidden" name="post_id" value="$post_id" /> <input type="hidden" name="post_id" value="$post_id" />
<textarea rows="5" cols="64" class="profile-jot-text" id="profile-jot-text" name="body" >$content</textarea> <img id="profile-jot-text-loading" src="images/rotator.gif" alt="$wait" title="$wait" style="display: none;" />
<textarea rows="5" cols="64" class="profile-jot-text" id="profile-jot-text" name="body" >{{ if $content }}$content{{ else }}$share{{ endif }}</textarea>
{{ if $content }}<script>initEditor();</script>{{ endif }}
<div id="profile-jot-submit-wrapper" > <div id="profile-jot-submit-wrapper" style="display:none">
<input type="submit" id="profile-jot-submit" name="submit" value="$share" /> <input type="submit" id="profile-jot-submit" name="submit" value="$share" />
<div id="profile-upload-wrapper" style="display: $visitor;" > <div id="profile-upload-wrapper" style="display: $visitor;" >
<div id="wall-image-upload-div" ><a href="#" onclick="return false;" id="wall-image-upload" class="icon camera" title="$upload"></a></div> <div id="wall-image-upload-div" ><a href="#" onclick="return false;" id="wall-image-upload" class="icon camera" title="$upload"></a></div>

View File

@ -1483,6 +1483,13 @@ input#dfrn-url {
width: 180px; width: 180px;
} }
#profile-jot-text {
height: 20px;
color:#cccccc;
border: 1px solid #cccccc;
}
/** acl **/ /** acl **/
#profile-jot-acl-wrapper{ #profile-jot-acl-wrapper{

View File

@ -1561,6 +1561,13 @@ padding: 5px 10px 0px;
overflow: auto; overflow: auto;
} }
#profile-jot-text {
height: 20px;
color:#cccccc;
border: 1px solid #cccccc;
}
/** acl **/ /** acl **/
#profile-jot-acl-wrapper{ #profile-jot-acl-wrapper{
display:block!important; display:block!important;