Modificare il file:
\FckEditor\plugins\CharsCounter\fckplugin.js
// Define the command. var CharsCounterLoaded=false; var FCKCharsCounterCommand = function( maxlength, countername ) { this.Name = 'CharsCounter' ; this.TextLength = 0 ; this.HTMLLength = 0 ; this.MaxLength = parseInt(maxlength) ; this.LeftChars = parseInt(maxlength) ; this.CounterName = countername ; } FCKCharsCounterCommand.prototype.Execute = function() { var DOMDocument = FCK.EditorDocument ; // The are two diffent browser specific ways to get the text. // I also use a trick to count linebreaks (<br>/</p>) as one-stroke. if ( FCKBrowserInfo.IsIE ) { var HTMLText = DOMDocument.body.innerHTML ; var linebreaks = HTMLText.length - HTMLText.replace(/<(br|\/p)/gi,'**').length; this.TextLength = DOMDocument.body.innerText.length + linebreaks; this.HTMLLength = HTMLText.length ; } else { var r = DOMDocument.createRange() ; r.selectNodeContents( DOMDocument.body ) ; var HTMLText = r.startContainer.innerHTML ; var linebreaks = HTMLText.length - HTMLText.replace(/<(br|\/p)/gi,'**').length; this.TextLength = r.toString().length + linebreaks; this.HTMLLength = HTMLText.length ; } // MaxLength is optional: if undefined, LeftChars is always 1 this.LeftChars = this.MaxLength ? this.MaxLength - this.TextLength : 1 ; if ( this.LeftChars < 0 && this.MaxLength>0) { // What will I do if I reached MaxLength ? // By now I simply force an 'Undo' command, but often this result in a big step back! // For example: if I type a text, once I reach the limit, // the whole last sentence will be removed, instead of the last char typed only. // You may want to update values in the counters always, // then you can block too long texts simply adding an external check on the counter. FCKCommands.GetCommand( 'Undo' ).Execute() ; this.Execute() ; } else { // Update values in the toolbar button, if defined. this.DOMLabel = document.getElementById( 'CharsCounterDiv' ) ; if ( this.DOMLabel ) { var text = ' ' + FCKLang.ContentLengthShortText + ':' + this.TextLength + ' / ' + FCKLang.ContentLengthShortHtml + ':' + this.HTMLLength; if(this.MaxLength>0){ text += ' / ' + FCKLang.ContentLengthShortLeft + ':' + this.LeftChars + ' '; }else{ text += ' '; } var title = FCKLang.ContentLengthTitleText + ':' + this.TextLength + ' / ' + FCKLang.ContentLengthTitleHtml + ':' + this.HTMLLength; if(this.MaxLength>0){ title += ' / ' + FCKLang.ContentLengthTitleLeft + ':' + this.LeftChars; } var sHtml = '<table style="border:1px solid #003399;" height="20" title="" cellspacing="0" cellpadding="0" border="0" unselectable="on"><tr>' ; sHtml += '<td class="TB_Icon" height="20" title="' + title + '" nowrap="nowrap" valign="middle" unselectable="on">' + text + '</td>' ; sHtml += '</tr></table>' ; this.DOMLabel.innerHTML = sHtml; } // Update value in the external counter, if defined. if(FCK.LinkedField.form){ this.Counter = FCK.LinkedField.form[this.CounterName]; if ( this.Counter ) { this.Counter.value = this.LeftChars ; } } } } FCKCharsCounterCommand.prototype.GetState = function() { return FCK_TRISTATE_OFF ; } // Define the event handler. function CharsCounterEventHandler() { FCKCommands.GetCommand( 'CharsCounter' ).Execute() ; } function CharsCounter_SetListeners() { // First time execution. // Attach events "OnSelectionChange" "onPaste" and "onKeyUp", this is browser specific. if (CharsCounterLoaded == false) // I don’t know the code so in that way I disable double event attachment { CharsCounterLoaded == true; if (FCKBrowserInfo.IsIE) { FCK.Events.AttachEvent( 'OnSelectionChange', CharsCounterEventHandler ) ; FCK.EditorDocument.attachEvent( 'focus', CharsCounterEventHandler ) ; FCK.EditorDocument.attachEvent( 'onkeyup', CharsCounterEventHandler ) ; FCK.EditorDocument.attachEvent( 'onkeydown', CharsCounterEventHandler ) ; } else { FCK.Events.AttachEvent( 'OnSelectionChange', CharsCounterEventHandler ) ; FCK.EditorDocument.addEventListener( 'focus', CharsCounterEventHandler, true ) ; FCK.EditorDocument.addEventListener( 'keyup', CharsCounterEventHandler, true ) ; FCK.EditorDocument.addEventListener( 'keydown', CharsCounterEventHandler, true ) ; } FCKCommands.GetCommand( 'CharsCounter' ).Execute() ; } } function CharsCounter_CheckEditorStatus( sender, status ) { // check if the fckdocument is loaded and if so I can attach events to the code if ( status == FCK_STATUS_COMPLETE ) CharsCounter_SetListeners() ; } FCK.Events.AttachEvent( 'OnStatusChange', CharsCounter_CheckEditorStatus ) ; // attach to load status event // Register the related command. FCKCommands.RegisterCommand( 'CharsCounter', new FCKCharsCounterCommand( FCK.Config['CounterMaxLength'], FCK.Config['CounterName'] ) ) ; // Create the "CharsCounter" toolbar button. //var oCharsCounterItem = new FCKToolbarButton( 'CharsCounter', '<label id="__CharsCounterLabel">0 / 0 / ' + FCK.Config['MaxLength'] + '</label>', 'Text length / HTML length / Left chars', FCK_TOOLBARITEM_ONLYTEXT, false, true ) ; //FCKToolbarItems.RegisterItem( 'CharsCounter', oCharsCounterItem ) ; var FCKCharsCounterButton = function() { commandName = 'CharsCounter' this.Command = FCKCommands.GetCommand(commandName) ; // this.Label = label ? label : commandName ; this.Label = ''; // this.Tooltip = tooltip ? tooltip : ( label ? label : commandName) ; this.Tooltip = ''; // this.Style = style ? style : FCK_TOOLBARITEM_ONLYTEXT; this.Style = FCK_TOOLBARITEM_ONLYTEXT; // this.SourceView = sourceView ? true : false ; this.SourceView = true; // this.ContextSensitive = contextSensitive ? true : false ; this.ContextSensitive = false; this.IconPath = '' ; this.State = FCK_UNKNOWN ; } FCKCharsCounterButton.prototype.Create = function( parentToolbar ) { this.DOMDiv = document.createElement( 'div' ) ; this.DOMDiv.className = 'TB_Button_Off' ; this.DOMDiv.FCKToolbarButton = this ; var sHtml = '<div id="CharsCounterDiv" ><table style="border:1px solid #003399;" height="20" title="" cellspacing="0" cellpadding="0" border="0" unselectable="on"><tr>' ; sHtml += '<td class="TB_Icon" height="20" valign="middle" unselectable="on"></td>' ; sHtml += '</tr></table></div>' ; this.DOMDiv.innerHTML = sHtml ; //this._LabelEl = this.DOMDiv.getElementsByTagName('label')[0]; //this._LabelEl.innerHTML = this.Label ; parentToolbar.appendChild( this.DOMDiv ) ; } // Create the "CharsCounter" toolbar button. var oCharsCounterItem = new FCKCharsCounterButton() ; FCKToolbarItems.RegisterItem( 'CharsCounter', oCharsCounterItem ) ;
[
Íàçàä
]