/* * * * */ function NP_znSmiley(previewFlag, sendUrl) { this.previewFlag = previewFlag; this.sendUrl = sendUrl; this.sendCounter = 0; this.sendStr = ""; var znsmiley_tgtform = document.getElementById('nucleus_cf_body'); znsmiley_tgtform.pIns = this; //-------------------- // onKeyup event //-------------------- znsmiley_tgtform.onkeyup = function() { if (this.pIns.previewFlag) this.pIns.timelagSendPreviewRequest(this.value); } } NP_znSmiley.prototype = { //-------------------- // receiver //-------------------- on_loaded1: function(oj) { var res = decodeURIComponent(oj.responseText); document.getElementById("znSmiley_preview").innerHTML = res; document.getElementById('znsmiley_load').style.display = 'none'; }, //-------------------- // preview request //-------------------- sendPreviewRequest: function() { document.getElementById('znsmiley_load').style.display = 'inline'; sendRequest( this.on_loaded1, '&action=plugin&name=znSmiley&body=' + this.URLencode(this.sendStr), 'POST', this.sendUrl, true, true ); }, //-------------------- // timelag //-------------------- timelagSendPreviewRequest: function(str) { this.sendStr = str; this.sendCounter++; setTimeout('znSmiley.sendTimer()', 3000); //3s }, //-------------------- // sendTimer //-------------------- sendTimer: function() { this.sendCounter--; if (this.sendCounter == 0) this.sendPreviewRequest(); }, //-------------------- // add icon //-------------------- addSmiley: function(sm) { var tgt = document.getElementById('nucleus_cf_body'); if (document.selection) { //IE tgt.focus(); sel = document.selection.createRange(); sel.text = sm; } else if (tgt.selectionStart == '0' || tgt.selectionStart) { //Mozilla var sPos = tgt.selectionStart; var ePos = tgt.selectionEnd; tgt.value = tgt.value.substring(0, sPos) + sm + tgt.value.substring(ePos, tgt.value.length); } else { //Other tgt.value += sm; } if (this.previewFlag) this.timelagSendPreviewRequest(tgt.value); }, //-------------------- // collapsed //-------------------- dispSmiley: function(e, flag) { document.getElementById('znsmiley_disp' ).style.display = (flag) ? 'none' : 'inline'; document.getElementById('znsmiley_none' ).style.display = (flag) ? 'inline' : 'none'; document.getElementById('znsm_ico_layer').style.display = (flag) ? 'block' : 'none'; }, //-------------------- // URLencode //-------------------- URLencode: function(str) { // Unicode to URL encoded UTF-8 var i, encoded_str, char_code, padded_str; encoded_str = ""; for (i = 0; i < str.length; i++){ char_code = str.charCodeAt(i); if (char_code == 0x20){ // space -> "+" encoded_str += "+"; } else { // else 1 if (((0x30 <= char_code) && (char_code <= 0x39)) || ((0x41 <= char_code) && (char_code <= 0x5a)) || ((0x61 <= char_code) && (char_code <= 0x7a))){ // [0-9a-z-A-Z] // no escape encoded_str += str.charAt(i); } else if ((char_code == 0x2a) || (char_code == 0x2e) || (char_code == 0x2d) || (char_code == 0x5f)) { // [.-_] // no escape encoded_str += str.charAt(i); } else { // else 2 // for internal unicode to UTF-8 // Ref. http://homepage3.nifty.com/aokura/jscript/utf8.html // Ref. http://homepage1.nifty.com/nomenclator/unicode/ucs_utf.htm if ( char_code > 0xffff ) { encoded_str += "%" + ((char_code >> 18) | 0xf0).toString(16).toUpperCase(); encoded_str += "%" + (((char_code >> 12) & 0x3f) | 0x80).toString(16).toUpperCase(); encoded_str += "%" + (((char_code >> 6) & 0x3f) | 0x80).toString(16).toUpperCase(); encoded_str += "%" + ((char_code & 0x3f) | 0x80).toString(16).toUpperCase(); } else if ( char_code > 0x7ff ) { encoded_str += "%" + ((char_code >> 12) | 0xe0).toString(16).toUpperCase(); encoded_str += "%" + (((char_code >> 6) & 0x3f) | 0x80).toString(16).toUpperCase(); encoded_str += "%" + ((char_code & 0x3f) | 0x80).toString(16).toUpperCase(); } else if ( char_code > 0x7f ) { encoded_str += "%" + (((char_code >> 6) & 0x1f) | 0xc0).toString(16).toUpperCase(); encoded_str += "%" + ((char_code & 0x3f) | 0x80).toString(16).toUpperCase(); } else { // for ascii padded_str = "0" + char_code.toString(16).toUpperCase(); encoded_str += "%" + padded_str.substr(padded_str.length - 2, 2); } } // else 2 } // else 1 } // for return encoded_str; } }