Opened 14 years ago

Closed 14 years ago

Last modified 14 years ago

#589 closed defect (fixed)

Character counter not work

Reported by: anonymous Owned by: anonymous
Priority: highest Milestone:
Component: Documentation Version:
Severity: normal Keywords: Character counter
Cc:

Description

Character counter not work when i insert table, image, etc....
Its only work when typing..... Anyone can help me?
Thanks

Attachments (1)

char-counter.js (3.8 KB) - added by mokhet 14 years ago.

Download all attachments as: .zip

Change History (10)

comment:1 Changed 14 years ago by mharrisonline

The character counter is showing you the number of text characters, rather than actual HTML characters. I actually find it more useful as a word counter:

// Charcounter for HTMLArea-3.0
// (c) Udo Schmal & L.N.Schaffrath NeueMedien 
// Distributed under the same terms as HTMLArea itself.
// This notice MUST stay intact for use (see license.txt).

//This plugin has been greatly modified for use in JESS

function CharCounter(editor) {
    this.editor = editor;
};

CharCounter._pluginInfo = {
    name : "CharCounter",
    version : "1.0",
    developer : "Udo Schmal",
    developer_url : "http://www.schaffrath-neuemedien.de",
    sponsor       : "L.N.Schaffrath NeueMedien",
    sponsor_url   : "http://www.schaffrath-neuemedien.de",
    c_owner : "Udo Schmal & L.N.Schaffrath NeueMedien",
    license : "htmlArea"
};

CharCounter.prototype._lc = function(string) {
    return HTMLArea._lc(string, "CharCounter");
};


CharCounter.prototype.onGenerate = function() {
  var self = this;
  if (this.charCount==null) {
    var charCount = document.createElement("span");
    charCount.style.padding = "2px 5px";
    if(HTMLArea.is_ie) {
      charCount.style.styleFloat = "right";
    } else {
      charCount.style.cssFloat = "right";
    }
    var brk = document.createElement('div');
    brk.style.height =
    brk.style.width =
    brk.style.lineHeight =
    brk.style.fontSize = '1px';
    brk.style.clear = 'both';
    if(HTMLArea.is_ie) {
      this.editor._statusBarTree.style.styleFloat = "left";
    } else {
      this.editor._statusBarTree.style.cssFloat = "left";
    }
    this.editor._statusBar.appendChild(charCount);
    this.editor._statusBar.appendChild(brk);
    this.charCount = charCount;
  }
};

CharCounter.prototype.onUpdateToolbar = function() {
    this.updateCharCount();
};

CharCounter.prototype.onMode = function (mode)
{
  //Hide Chars in statusbar when switching into textmode
  switch (mode)
  {
    case "textmode":
      this.charCount.style.display = "none";
      break;
    case "wysiwyg":
      this.charCount.style.display = "";
      break;
    default:
      alert("Mode <" + mode + "> not defined!");
      return false;
  }
};

CharCounter.prototype.updateCharCount = function(ev) {
    editor = this.editor;
    var contents = editor.getHTML();
contents = contents.replace(/<\/?\s*!--[^-->]*-->/gi, "" );
contents = contents.replace(/<(.+?)>/g, '');
contents = contents.replace(/&nbsp;/gi, ' ');
contents = contents.replace(/([\n\r\t])/g, ' '); 
contents = contents.replace(/<\/table>/g, '</table> ');
contents = contents.replace(/<p>/gi, '<p> ');
contents = contents.replace(/<body[^>]*[^<]*>/g, '<body> $nbsp;');
contents = contents.replace(/<img[^>]*[^<]*>/g, ' ');
contents = contents.replace(/(  +)/g, ' ');
contents = contents.replace(/&(.*);/g, ' ');
contents = contents.replace(/^\s*|\s*$/g, '');
    var words=0;
    for (var x=0;x<contents.length;x++) {
      if (contents.charAt(x) == " " )  {words++}
    }
	if (words>=1){words=words+1;}
    this.charCount.innerHTML = this._lc("Words") + ": " + words;
};

comment:2 Changed 14 years ago by anonymous

Thanks for your reply. But i need to count the actual HTML instead of a word or character.

comment:3 Changed 14 years ago by anonymous

  • Owner changed from akaEdge to anonymous
  • Status changed from new to assigned

I think i just need to comment out the
contents = contents.replace(/<(.+?)>/g, );
then character counter will also count html character ;)
Thanks.

comment:4 Changed 14 years ago by gocher

I think if you want to get the comlete HTML-Source length you had do comment out all replace lines!

Changed 14 years ago by mokhet

comment:5 Changed 14 years ago by mokhet

In the attached file (char-counter.js) you will find what i've called the version 2.0 of the plugin :)

there is now 4 configuration variables

show the characters count from 1.0 version
config.CharCounter?.showChar = true

show the words count from this ticket by mharrisonline
config.CharCounter?.showWord = true

show the total html characters in content
config.CharCounter?.showHtml = true

separator used to join the different informations
config.CharCounter?.separator = ' | '

So with this version, it's up to you to show chars and/or words and/or html count.

Enjoy :)

comment:6 Changed 14 years ago by mokhet

this bug is assigned to ... mister anonymous ... but no news from mister anonymous since this day. A few patches and full code has been proposed to resolve the bug of the ticket. So what is the status of the ticket now ? Should it be closed without updating the SVN revision or is there some part of proposed patches we should commit to the repository first ?

comment:7 Changed 14 years ago by mharrisonline

Mokhet, I think the new version is superior, and should be committed. Word count and HTML count is more useful than text character count, to have them all there should benefit everyone.

comment:8 Changed 14 years ago by gocher

  • Resolution set to fixed
  • Status changed from assigned to closed

Changeset 432

comment:9 Changed 14 years ago by anonymous

</COMMENT>

<META NAME=VS_TARGETSCHEMA CONTENT="HTML 4.0">
<META NAME=VS_DEFAULTCLIENTSCRIPT CONTENT="JAVASCRIPT">

<meta name="Microsoft Border" content="none">

<LINK rel="stylesheet" type="text/css" href="NHData.css">

</head>

<body LANGUAGE=javascript>
<h1>Message Analyser</h1>
<HR>
<table WIDTH = "100%" >

<THEAD>
<tr>

<th>Parameter</th>
<th>Value</th>
<th colspan=3>Description</th>

</tr>

</THEAD>

<TBODY>
<tr>

<td>

Level:

</td>
<td>

<select name="cboDetail" size="1" style="WIDTH: 100%" ID=Select1>

<option>No details</option>
<option>Message name</option>
<option>Message name and IE names</option>

<option selected>Full</option>
</select>

</td>
<td class="descText"

colspan=3>
Decoding detail level

</td>

<tr>
</tr>

<tr>

<td>

Coding:

</td>
<td>

<select name="cboCoding" size="1" ID=Select3>

<option>No coding</option>
<option>Hex</option>
<option selected>Hex+space</option>
<option>Decimal</option>
<option>Ascii</option>
<option>Binary</option>

</select>

</td>
<td class="descText"

colspan=3>
Coding

</td></tr>

<tr>

<td>

Protocol:

</td>
<td>

<select name="cboProtocols" size="1" style="WIDTH: 95px" ID=Select2>

<option selected>BTSM</option>
<option>RR</option>
<option>MM</option>
<option>CC</option>
<option>SMS</option>
<option>O&amp;M</option>
<option>LAPD</option>

</select>

</td>
<td class="descText"

colspan=3>
Protocol

</td>

</tr>

</TBODY>
</table>
<table WIDTH = "100%" >

<tr>

<td colspan=5>
<h2>Message to analyze: </h2>
<textarea name="txtMessage" rows="2" cols = "60" style="WIDTH: 100%" ID=Textarea1></textarea>
</td>

</tr>
<tr>

<td class="textMenu"

class="textMenu"
onmouseover="this.className='textSelected'"
onmouseout="this.className='textMenu'"
onclick="Analyze()"
colspan=5>
Analyze Message

</td>

</tr>

<tr>

<td class="tableLastRow" colspan=5>
<select id=lstLog size=2 style="WIDTH: 100%; HEIGHT: 200px">

</select>

</td>

</tr>

</table>

<comment>Create event source</comment>
<object id=oNHSEv height=0 width=0
data=data:application/x-oleobject;base64,Ax3PMu880hG4UhCArcigWQADAAAaAAAAGgAAAA==
border=0 classid=clsid:32CF1D03-3CEF-11D2-B852-1080ADC8A059 VIEWASTEXT>

</object>

<script language="JavaScript?">
==================================================================
script
==================================================================

var coding=6, detail=3
var oNHS
var protocols=new Array("BTSM","RR","MM","CC","SM-TP","O&M","LAPD")
oNHS = new ActiveXObject("NetHawk?.BSCAbis")
oNHS.WindowConnect?(document)

==================================================================
Function:
Analyze
Description:
Decodes message
Parameters:
-
Calls:
-
Returns:
-
==================================================================
function Analyze()
{

var protocol=protocols[cboProtocols.selectedIndex]
var decodedMessage=oNHS.ProtocolDecodeMsg?(
protocol,txtMessage.value,
cboDetail.selectedIndex,
cboCoding.selectedIndex,
true)
printTrace("*")
printTrace(decodedMessage)

}
==================================================================
Function:
printTrace
Description:
Prints trace line to trace box
Parameters:
sMsg - trace line to print
Calls:
-
Returns:
-
==================================================================
function printTrace(sMsg)
{
var regexp=new RegExp?("[
n
r]")
var arLines = sMsg.split(regexp)
var i

for (i = 0; i<arLines.length; i++)
{
var oOption


oOption = document.createElement("OPTION")
oOption.text = arLines[i].replace(/&nbsp;/gi, " ")
lstLog.options.add(oOption)
lstLog.selectedIndex = lstLog.options.length - 1

}

}

</script>
</body>
</html>

In the Analyze Message Box i want to copy the text after analysing the message,so help me in modifying the code.

Note: See TracTickets for help on using tickets.