home *** CD-ROM | disk | FTP | other *** search
- class com.comp.WordCount extends TextField
- {
- var c_txtSource;
- var c_length;
- var c_objRoot;
- var c_txtCount;
- var c_strTmp;
- var c_strTmpLeft;
- var c_iWordLimit;
- function WordCount(_objRoot, _inptxtName, _dynCount, _objTestRef, _iWordLimit)
- {
- var _loc1_ = this;
- super();
- _loc1_.c_objRoot = _objRoot;
- _loc1_.c_txtSource = _loc1_.c_objRoot[_inptxtName];
- _loc1_.c_txtCount = _loc1_.c_objRoot[_dynCount];
- _loc1_.c_objTestRef = _objTestRef;
- _loc1_.c_struserName = com.controller.UICoordinator.getInstance().userName;
- _loc1_.c_strTestMode = _objTestRef.c_strMode;
- _loc1_.c_blnFreezed = false;
- _loc1_.c_iWordLimit = _iWordLimit;
- _loc1_.init();
- }
- function init()
- {
- this.arrange();
- }
- function setQueType(_iPart)
- {
- var _loc1_ = this;
- if(_loc1_.c_objTestRef.c_strSkill.toLowerCase() == "writing")
- {
- var _loc2_ = _loc1_.c_objTestRef.c_hQuestionState["get"]("writing_" + _iPart).attempted;
- _loc1_.c_txtSource.text = _loc2_;
- }
- }
- function arrange()
- {
- var _loc1_ = this;
- _loc1_.c_txtSource.textSize = 10;
- _loc1_.c_txtSource.textColor = 0;
- _loc1_.c_txtSource.border = false;
- _loc1_.c_txtSource.wordWrap = true;
- _loc1_.c_txtSource.multiline = true;
- mcRef = _loc1_.c_objRoot._parent;
- mcRef.wc_ScrollReference._y = mcRef.mc_WordCount._height + mcRef.mc_WordCount._y + 5;
- mcRef.wcScrollPane._y = mcRef.wc_ScrollReference._y;
- if(_loc1_.c_strTestMode != "Review")
- {
- Selection.setFocus(_loc1_.c_txtSource);
- }
- _loc1_.setEvents();
- }
- function countWords()
- {
- var _loc3_ = this.c_txtSource.text.split(String.fromCharCode(13)).join(" ").split(" ");
- var _loc2_ = 0;
- this.c_length = _loc3_.length;
- if(this.c_txtSource.scroll <= 1)
- {
- this.c_objRoot.cmp_ScrollBar._visible = false;
- }
- else
- {
- this.c_objRoot.cmp_ScrollBar._visible = true;
- }
- if(this.c_txtSource.scroll <= 1)
- {
- this.c_objRoot.wcTextScroller._visible = false;
- }
- else
- {
- this.c_objRoot.wcTextScroller._visible = true;
- }
- var _loc1_ = 0;
- while(_loc1_ < _loc3_.length)
- {
- if(_loc3_[_loc1_] != "")
- {
- _loc2_ += 1;
- }
- _loc1_ = _loc1_ + 1;
- }
- this.c_txtCount.text = _loc2_.toString();
- }
- function txt111Changed()
- {
- var _loc1_ = this;
- if(_loc1_.c_txtCount.text > _loc1_.c_iWordLimit)
- {
- _loc1_.c_txtSource.text = _loc1_.c_strTmp;
- }
- else
- {
- _loc1_.c_strTmp = _loc1_.c_txtSource.text;
- }
- _loc1_.c_txtSource.text = _loc1_.c_txtSource.text;
- _loc1_.controlNext(_loc1_);
- }
- function txtChanged()
- {
- this.c_strTmp = this.c_txtSource.text.substr(0,Selection.getBeginIndex());
- this.c_strTmpLeft = this.c_txtSource.text.substr(Selection.getBeginIndex(),this.c_txtSource.text.length);
- if(Number(this.c_txtCount.text) > Number(this.c_iWordLimit))
- {
- var _loc2_ = "";
- var _loc3_ = this.c_strTmp.split(String.fromCharCode(13)).join(" \n").split(" ");
- var arrTmpLeft = this.c_strTmpLeft.split(String.fromCharCode(13)).join(" ").split(" ");
- var ctr = 0;
- var _loc1_ = 0;
- while(_loc1_ < arrTmpLeft.length)
- {
- if(arrTmpLeft[_loc1_] != "")
- {
- ctr += 1;
- }
- _loc1_ = _loc1_ + 1;
- }
- _loc1_ = 0;
- j = 0;
- while(_loc1_ < this.c_iWordLimit - ctr)
- {
- if(_loc3_[j] != "" and _loc3_[j] != undefined and _loc3_[j] != null)
- {
- _loc2_ = _loc2_ + _loc3_[j] + " ";
- _loc1_ = _loc1_ + 1;
- }
- else
- {
- _loc2_ += " ";
- }
- j++;
- }
- if(_loc3_[_loc3_.length - 2] != "")
- {
- if(arrTmpLeft.length > 1)
- {
- _loc2_ += _loc3_[_loc3_.length - 2];
- }
- }
- this.c_txtSource.text = _loc2_.substr(0,_loc2_.length) + this.c_strTmpLeft;
- }
- this.c_txtSource.text = this.c_txtSource.text;
- this.c_txtCount.text = this.c_txtSource.text.split(String.fromCharCode(13)).join(" ").split(" ").length.toString();
- this.controlNext(this);
- }
- function controlNext(_objRef)
- {
- var _loc2_ = this;
- var _loc3_ = _loc2_.c_objRoot.txt_Header.text;
- var len = _loc3_.length;
- var tmp = _loc3_.charAt(len - 1);
- objRef = _loc2_.c_objRoot._parent;
- var _loc1_ = new Object();
- _loc1_.answeroption = tmp;
- if(_objRef.c_txtSource.text == "")
- {
- objRef.btn_next._visible = false;
- _loc1_.attempted = _objRef.c_txtSource.text;
- _loc2_.c_objTestRef.removeQuesObject();
- _loc2_.c_objTestRef.c_objNavigator.markUnAttempted();
- }
- else
- {
- _loc1_.attempted = _objRef.c_txtSource.text;
- _loc2_.c_objTestRef.c_objNavigator.markAttempted();
- objRef.btn_next._visible = true;
- _loc2_.c_objTestRef.appendQuesObject(_loc1_);
- }
- }
- function setEvents()
- {
- var _loc1_ = this;
- Mouse_listener = new Object();
- Mouse_listener.objRef = _loc1_;
- _loc1_.c_txtSource.objRef = _loc1_;
- _loc1_.c_txtSource.onChanged = function()
- {
- var _loc1_ = this;
- _loc1_.objRef.countWords();
- _loc1_.objRef.txtChanged();
- _loc1_.objRef.countWords();
- };
- Mouse_listener.onMouseUp = function()
- {
- var _loc1_ = this;
- if(Selection.getBeginIndex() < _loc1_.objRef.c_txtSource.text.length)
- {
- _loc1_.objRef.c_txtSource.maxChars = 99999;
- }
- else
- {
- _loc1_.objRef.c_txtSource.maxChars = Number(_loc1_.objRef.c_txtSource.text.length);
- }
- _loc1_.objRef.c_txtSource.text = _loc1_.objRef.c_txtSource.text;
- };
- if(_loc1_.c_strTestMode != "Review")
- {
- Key.addListener(Key_listener);
- }
- else if(_loc1_.c_strTestMode == "Review")
- {
- Key.removeListener(Key_listener);
- Mouse.removeListener(Mouse_listener);
- }
- var _btnObjRef = _loc1_;
- _loc1_.c_objRoot._parent.btn_Print.onRelease = function()
- {
- var strQuestionNo = _btnObjRef.c_objRoot._parent.mc_WordCount.txt_QuestionNo.text;
- var stQuestionText = _btnObjRef.c_objRoot._parent.mc_WordCount.txt_Question.htmlText;
- var _loc3_ = _btnObjRef.c_objTestRef.c_objSection;
- var _iTestNum = _loc3_.attributes.test;
- var _loc2_ = _loc3_.attributes.skill;
- _loc2_ = _loc2_.charAt(0).toUpperCase() + _loc2_.substr(1,_loc2_.length);
- var _loc1_ = _loc3_.attributes.type;
- _loc1_ = _loc1_.charAt(0).toUpperCase() + _loc1_.substr(1,_loc1_.length - 1);
- _loc1_ = _loc1_.substr(0,_loc1_.length - 1) + " " + _loc1_.substr(-1);
- var _headerText = com.controller.UICoordinator.getInstance().getTitle() + " - Test: " + _loc2_ + " " + _loc1_;
- com.comp.PrintManager.printIt(_level101.printText_mc,_headerText,_btnObjRef.c_struserName,strQuestionNo,stQuestionText,_btnObjRef.c_txtSource.text);
- };
- }
- }
-