Created
September 23, 2011 23:31
-
-
Save reedobrien/1238716 to your computer and use it in GitHub Desktop.
defor richtext with char count
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<textarea id="${field.oid}" class="richtext" | |
name="${field.name}">${cstruct}</textarea> | |
<script language="javascript" | |
type="text/javascript"> | |
deform.addCallback( | |
'${field.oid}', | |
function(oid) { | |
tinyMCE.init({ | |
mode : 'exact', | |
elements: oid, | |
height: '${field.widget.height}', | |
width: '${field.widget.width}', | |
theme : '${field.widget.theme}', | |
theme_advanced_resizing : true, | |
theme_advanced_toolbar_align : 'left', | |
theme_advanced_toolbar_location : 'top', | |
theme_advanced_path : false, | |
theme_advanced_statusbar_location : "bottom", | |
relative_urls : false, | |
document_base_url : "${field.widget.document_base_url}/", | |
charLimit : ${field.widget.char_limit}, // this is a default value which can get modified later | |
//set up a new editor function | |
setup : function(ed) { | |
ed.onNodeChange.add(function(ed, e) { | |
//define local variables | |
var tinymax, tinylen, htmlcount; | |
//manually setting our max character limit | |
tinymax = ed.settings.charLimit; | |
//grabbing the length of the curent editors content | |
tinylen = ed.getContent().replace(/<[^>]+>/g, '').length; | |
//setting up the text string that will display in the path area | |
htmlcount = "Character Count: " + tinylen + "/" + tinymax; | |
//if the user has exceeded the max turn the path bar red. | |
if (tinylen>tinymax){ | |
htmlcount = "<span style='font-weight:bold; color: #f00;'>" + htmlcount + "</span>" | |
} | |
//enable to override the limit for various editors here | |
//tinyMCE.editors["mytextarea1"].settings.charLimit = 3000; | |
//this line writes the html count into the path row of the active editor | |
tinymce.DOM.setHTML(tinymce.DOM.get(tinyMCE.activeEditor.id + '_path_row'), htmlcount); | |
}); | |
} | |
}); | |
}); | |
</script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment