BUG 9484 Label display wrong in multi-byte language SOLVED

- Whe a label is in a multi-byte language the size is calculated wrong
- Add a multi-byte string length function
This commit is contained in:
Julio Cesar Laura
2012-08-15 20:00:54 -04:00
parent 15115d64f5
commit 5e1037b8f4
2 changed files with 95 additions and 87 deletions

View File

@@ -925,11 +925,11 @@ function get_xmlhttp() {
xmlhttp = false; xmlhttp = false;
if ( window.ActiveXObject ) if ( window.ActiveXObject )
xmlhttp = new ActiveXObject("Msxml2.XMLHTTP"); xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
} }
catch (e) { catch (e) {
try { try {
xmlhttp = new ActiveXObject("Microsoft.XMLHTTP"); xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
} }
catch (E) { catch (E) {
xmlhttp = false; xmlhttp = false;
} }
@@ -1231,47 +1231,47 @@ var radios = document.getElementById('form[' + field + ']');
/* @author Alvaro Campos Sanchez /* @author Alvaro Campos Sanchez
*/ */
function validDate(TheField, Required) { function validDate(TheField, Required) {
var date = TheField.split("-"); var date = TheField.split("-");
var date1 = date[0]; var date1 = date[0];
var date2 = date[1]; var date2 = date[1];
var date3 = date[2]; var date3 = date[2];
var TheDay,TheMonth,TheYear; var TheDay,TheMonth,TheYear;
if ((date1.length==4)&&(!TheYear)) if ((date1.length==4)&&(!TheYear))
TheYear = date1; TheYear = date1;
if (date1.length==2) if (date1.length==2)
if ((date1>0)&&(date1<=12)&&(!TheMonth)) if ((date1>0)&&(date1<=12)&&(!TheMonth))
TheMonth = date1; TheMonth = date1;
else else
if ((date1>0)&&(date1<=31)&&(!TheDay)) if ((date1>0)&&(date1<=31)&&(!TheDay))
TheDay = date1; TheDay = date1;
else else
TheYear = date1; TheYear = date1;
if ((date2.length==4)&&(!TheYear)) if ((date2.length==4)&&(!TheYear))
TheYear = date2; TheYear = date2;
if (date2.length==2) if (date2.length==2)
if ((date2>0)&&(date2<=12)&&(!TheMonth)) if ((date2>0)&&(date2<=12)&&(!TheMonth))
TheMonth = date2; TheMonth = date2;
else else
if ((date2>0)&&(date2<=31)&&(!TheDay)) if ((date2>0)&&(date2<=31)&&(!TheDay))
TheDay = date2; TheDay = date2;
else else
TheYear = date2; TheYear = date2;
if((date3.length==4)&&(!TheYear)) if((date3.length==4)&&(!TheYear))
TheYear = date3; TheYear = date3;
if (date3.length==2) if (date3.length==2)
if ((date3>0)&&(date3<=12)&&(!TheMonth)) if ((date3>0)&&(date3<=12)&&(!TheMonth))
TheMonth = date3; TheMonth = date3;
else else
if ((date3>0)&&(date3<=31)&&(!TheDay)) if ((date3>0)&&(date3<=31)&&(!TheDay))
TheDay = date3; TheDay = date3;
else else
TheYear = date3; TheYear = date3;
if (!TheYear || !TheMonth || !TheDay) if (!TheYear || !TheMonth || !TheDay)
return false; return false;
if ((Required)||(Required=='true')) if ((Required)||(Required=='true'))
@@ -1283,9 +1283,9 @@ function validDate(TheField, Required) {
if ((TheMonth != 02)&&(TheMonth < 13)&&(TheMonth > 0)) if ((TheMonth != 02)&&(TheMonth < 13)&&(TheMonth > 0))
if (TheDay > 30) if (TheDay > 30)
return false; return false;
return true; return true;
} }
/* @author David S. Callizaya S. /* @author David S. Callizaya S.
@@ -1363,34 +1363,34 @@ function dynaformSetFocus(){
* @Author alvaro <alvaro@colosa.com, alvaro.cs@live.com> * @Author alvaro <alvaro@colosa.com, alvaro.cs@live.com>
* @return false * @return false
*/ */
function idSet(name){ function idSet(name){
var inputs = document.getElementsByTagName('input'); var inputs = document.getElementsByTagName('input');
if(inputs.length > 0){ if(inputs.length > 0){
for(i in inputs){ for(i in inputs){
id = inputs[i].id; id = inputs[i].id;
if(id == "form["+name+"_label]"){ if(id == "form["+name+"_label]"){
if(inputs[i].value.trim()) if(inputs[i].value.trim())
var valueLabel = inputs[i].value; var valueLabel = inputs[i].value;
else else
var valueLabel = "Empty"; var valueLabel = "Empty";
} }
if(id == "form["+name+"]"){ if(id == "form["+name+"]"){
try { try {
if(valueLabel !="Empty"){ if(valueLabel !="Empty"){
if (! inputs[i].value) if (! inputs[i].value)
inputs[i].value = valueLabel; inputs[i].value = valueLabel;
}else }else
inputs[i].value = ""; inputs[i].value = "";
} catch (e) { } catch (e) {
//nothing //nothing
} }
} }
} }
} }
return false; return false;
} }
/** /**
@@ -1406,8 +1406,8 @@ function idSet(name){
* @Return (string) the parsed string with htmlentities at the string passed such as parameter * @Return (string) the parsed string with htmlentities at the string passed such as parameter
*/ */
function htmlentities (string, quote_style, charset, double_encode) { function htmlentities (string, quote_style, charset, double_encode) {
// Convert all applicable characters to HTML entities // Convert all applicable characters to HTML entities
// //
// version: 1109.2015 // version: 1109.2015
// discuss at: http://phpjs.org/functions/htmlentities // + original by: Kevin van Zonneveld (http://kevin.vanzonneveld.net) // discuss at: http://phpjs.org/functions/htmlentities // + original by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
// + revised by: Kevin van Zonneveld (http://kevin.vanzonneveld.net) // + revised by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
@@ -1421,31 +1421,31 @@ function htmlentities (string, quote_style, charset, double_encode) {
// * example 1: htmlentities('Kevin & van Zonneveld'); // * example 1: htmlentities('Kevin & van Zonneveld');
// * returns 1: 'Kevin &amp; van Zonneveld' // * returns 1: 'Kevin &amp; van Zonneveld'
// * example 2: htmlentities("foo'bar","ENT_QUOTES"); // * example 2: htmlentities("foo'bar","ENT_QUOTES");
// * returns 2: 'foo&#039;bar' // * returns 2: 'foo&#039;bar'
var hash_map = get_html_translation_table('HTML_ENTITIES', quote_style), symbol = ''; var hash_map = get_html_translation_table('HTML_ENTITIES', quote_style), symbol = '';
string = string == null ? '' : string + ''; string = string == null ? '' : string + '';
if (!hash_map) { if (!hash_map) {
return false; return false;
} }
if (quote_style && quote_style === 'ENT_QUOTES') { if (quote_style && quote_style === 'ENT_QUOTES') {
hash_map["'"] = '&#039;'; } hash_map["'"] = '&#039;'; }
if (!!double_encode || double_encode == null) { if (!!double_encode || double_encode == null) {
for (symbol in hash_map) { for (symbol in hash_map) {
if (hash_map.hasOwnProperty(symbol)) { if (hash_map.hasOwnProperty(symbol)) {
string = string.split(symbol).join(hash_map[symbol]); string = string.split(symbol).join(hash_map[symbol]);
} }
} }
} else { } else {
string = string.replace(/([\s\S]*?)(&(?:#\d+|#x[\da-f]+|[a-zA-Z][\da-z]*);|$)/g, function (ignore, text, entity) { string = string.replace(/([\s\S]*?)(&(?:#\d+|#x[\da-f]+|[a-zA-Z][\da-z]*);|$)/g, function (ignore, text, entity) {
for (symbol in hash_map) { for (symbol in hash_map) {
if (hash_map.hasOwnProperty(symbol)) { if (hash_map.hasOwnProperty(symbol)) {
text = text.split(symbol).join(hash_map[symbol]); text = text.split(symbol).join(hash_map[symbol]);
} }
} }
return text + entity; return text + entity;
}); });
} }
@@ -1470,7 +1470,7 @@ function utf8_encode (argString) {
} }
else { else {
enc = String.fromCharCode((c1 >> 12) | 224) + String.fromCharCode(((c1 >> 6) & 63) | 128) + String.fromCharCode((c1 & 63) | 128); enc = String.fromCharCode((c1 >> 12) | 224) + String.fromCharCode(((c1 >> 6) & 63) | 128) + String.fromCharCode((c1 & 63) | 128);
} }
if (enc !== null) { if (enc !== null) {
if (end > start) { if (end > start) {
utftext += string.slice(start, end); utftext += string.slice(start, end);
@@ -1478,34 +1478,34 @@ function utf8_encode (argString) {
utftext += enc; utftext += enc;
start = end = n + 1; start = end = n + 1;
} }
} }
if (end > start) { if (end > start) {
utftext += string.slice(start, stringl); utftext += string.slice(start, stringl);
} }
return utftext; return utftext;
} }
function base64_encode (data) { function base64_encode (data) {
var b64 = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/="; var b64 = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=";
var o1, o2, o3, h1, h2, h3, h4, bits, i = 0, var o1, o2, o3, h1, h2, h3, h4, bits, i = 0,
ac = 0, ac = 0,
enc = "", enc = "",
tmp_arr = []; tmp_arr = [];
if (!data) { if (!data) {
return data; return data;
} }
data = utf8_encode(data + ''); data = utf8_encode(data + '');
do { do {
o1 = data.charCodeAt(i++); o1 = data.charCodeAt(i++);
o2 = data.charCodeAt(i++); o2 = data.charCodeAt(i++);
o3 = data.charCodeAt(i++); o3 = data.charCodeAt(i++);
bits = o1 << 16 | o2 << 8 | o3; bits = o1 << 16 | o2 << 8 | o3;
h1 = bits >> 18 & 0x3f; h1 = bits >> 18 & 0x3f;
h2 = bits >> 12 & 0x3f; h2 = bits >> 12 & 0x3f;
h3 = bits >> 6 & 0x3f; h3 = bits >> 6 & 0x3f;
h4 = bits & 0x3f; h4 = bits & 0x3f;
tmp_arr[ac++] = b64.charAt(h1) + b64.charAt(h2) + b64.charAt(h3) + b64.charAt(h4); tmp_arr[ac++] = b64.charAt(h1) + b64.charAt(h2) + b64.charAt(h3) + b64.charAt(h4);
} while (i < data.length); } while (i < data.length);
enc = tmp_arr.join(''); enc = tmp_arr.join('');
switch (data.length % 3) { switch (data.length % 3) {
case 1: case 1:
enc = enc.slice(0, -2) + '=='; enc = enc.slice(0, -2) + '==';
@@ -1513,13 +1513,13 @@ function base64_encode (data) {
case 2: case 2:
enc = enc.slice(0, -1) + '='; enc = enc.slice(0, -1) + '=';
break; break;
} }
return enc; return enc;
} }
function get_html_translation_table (table, quote_style) { function get_html_translation_table (table, quote_style) {
// Returns the internal translation table used by htmlspecialchars and htmlentities // Returns the internal translation table used by htmlspecialchars and htmlentities
// //
// version: 1109.2015 // version: 1109.2015
// discuss at: http://phpjs.org/functions/get_html_translation_table // + original by: Philip Peterson // discuss at: http://phpjs.org/functions/get_html_translation_table // + original by: Philip Peterson
// + revised by: Kevin van Zonneveld (http://kevin.vanzonneveld.net) // + revised by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
@@ -1541,19 +1541,19 @@ function get_html_translation_table (table, quote_style) {
var constMappingTable = {}, var constMappingTable = {},
constMappingQuoteStyle = {}; constMappingQuoteStyle = {};
var useTable = {}, var useTable = {},
useQuoteStyle = {}; useQuoteStyle = {};
// Translate arguments // Translate arguments
constMappingTable[0] = 'HTML_SPECIALCHARS'; constMappingTable[0] = 'HTML_SPECIALCHARS';
constMappingTable[1] = 'HTML_ENTITIES'; constMappingTable[1] = 'HTML_ENTITIES';
constMappingQuoteStyle[0] = 'ENT_NOQUOTES'; constMappingQuoteStyle[2] = 'ENT_COMPAT'; constMappingQuoteStyle[0] = 'ENT_NOQUOTES'; constMappingQuoteStyle[2] = 'ENT_COMPAT';
constMappingQuoteStyle[3] = 'ENT_QUOTES'; constMappingQuoteStyle[3] = 'ENT_QUOTES';
useTable = !isNaN(table) ? constMappingTable[table] : table ? table.toUpperCase() : 'HTML_SPECIALCHARS'; useTable = !isNaN(table) ? constMappingTable[table] : table ? table.toUpperCase() : 'HTML_SPECIALCHARS';
useQuoteStyle = !isNaN(quote_style) ? constMappingQuoteStyle[quote_style] : quote_style ? quote_style.toUpperCase() : 'ENT_COMPAT'; useQuoteStyle = !isNaN(quote_style) ? constMappingQuoteStyle[quote_style] : quote_style ? quote_style.toUpperCase() : 'ENT_COMPAT';
if (useTable !== 'HTML_SPECIALCHARS' && useTable !== 'HTML_ENTITIES') { if (useTable !== 'HTML_SPECIALCHARS' && useTable !== 'HTML_ENTITIES') {
throw new Error("Table: " + useTable + ' not supported'); throw new Error("Table: " + useTable + ' not supported');
// return false; // return false;
} }
entities['38'] = '&amp;'; entities['38'] = '&amp;';
if (useTable === 'HTML_ENTITIES') { if (useTable === 'HTML_ENTITIES') {
entities['160'] = '&nbsp;'; entities['160'] = '&nbsp;';
@@ -1633,7 +1633,7 @@ function get_html_translation_table (table, quote_style) {
entities['253'] = '&yacute;'; entities['253'] = '&yacute;';
entities['254'] = '&thorn;'; entities['254'] = '&thorn;';
entities['255'] = '&yuml;'; entities['255'] = '&yuml;';
} }
if (useQuoteStyle !== 'ENT_NOQUOTES') { if (useQuoteStyle !== 'ENT_NOQUOTES') {
entities['34'] = '&quot;'; entities['34'] = '&quot;';
} }
@@ -1641,13 +1641,13 @@ function get_html_translation_table (table, quote_style) {
} }
entities['60'] = '&lt;'; entities['60'] = '&lt;';
entities['62'] = '&gt;'; entities['62'] = '&gt;';
// ascii decimals to real symbols // ascii decimals to real symbols
for (decimal in entities) { for (decimal in entities) {
if (entities.hasOwnProperty(decimal)) { if (entities.hasOwnProperty(decimal)) {
hash_map[String.fromCharCode(decimal)] = entities[decimal]; } hash_map[String.fromCharCode(decimal)] = entities[decimal]; }
} }
return hash_map; return hash_map;
} }
@@ -1892,22 +1892,22 @@ function PMOS_TemporalMessage(timeToHide){
/** /**
* fast messagesbox * fast messagesbox
* *
* @Param msg (string) : your message * @Param msg (string) : your message
* @Param type (string): {alert|info|confirm} * @Param type (string): {alert|info|confirm}
* @Param type (string): xcallback, callback function name to execute after at user click on Accept * @Param type (string): xcallback, callback function name to execute after at user click on Accept
* @Author <erik@colosa.com> * @Author <erik@colosa.com>
*/ */
function msgBox(msg, type, callbackAccept, callbackCancel){ function msgBox(msg, type, callbackAccept, callbackCancel){
//setting default type //setting default type
type = typeof(type) != 'undefined'? type: 'info'; type = typeof(type) != 'undefined'? type: 'info';
//setting up the callback action //setting up the callback action
acceptEv = typeof(callbackAccept) != 'undefined'? callbackAccept: false; acceptEv = typeof(callbackAccept) != 'undefined'? callbackAccept: false;
cancelEv = typeof(callbackCancel) != 'undefined'? callbackCancel: false; cancelEv = typeof(callbackCancel) != 'undefined'? callbackCancel: false;
switch(type){ switch(type){
case 'alert': case 'alert':
new leimnud.module.app.alert().make({ new leimnud.module.app.alert().make({
@@ -1954,9 +1954,9 @@ function msgBox(msg, type, callbackAccept, callbackCancel){
}.extend(this) }.extend(this)
}); });
} }
break; break;
} }
} }
@@ -1966,8 +1966,8 @@ function executeEvent(id, ev){
document.getElementById(id).checked = true; document.getElementById(id).checked = true;
if(document.getElementById(id).onclick){ if(document.getElementById(id).onclick){
try{ try{
document.getElementById(id).onclick(); document.getElementById(id).onclick();
}catch(e){} }catch(e){}
} }
break; break;
} }
@@ -2002,7 +2002,7 @@ function getClientWindowSize() {
function popUp(URL, width, height, left, top, resizable) { function popUp(URL, width, height, left, top, resizable) {
window.open(URL, '', 'toolbar=0,scrollbars=1,location=0,statusbar=0,menubar=1,resizable='+resizable+',width='+width+',height='+height+',left = '+left+',top = '+top+''); window.open(URL, '', 'toolbar=0,scrollbars=1,location=0,statusbar=0,menubar=1,resizable='+resizable+',width='+width+',height='+height+',left = '+left+',top = '+top+'');
} }
/** /**
* Alias for tedious large definition for ajax object - By Erik A.O. <erik@colosa.com> * Alias for tedious large definition for ajax object - By Erik A.O. <erik@colosa.com>
@@ -2016,12 +2016,12 @@ function removeValue(id){
document.getElementById('form['+id+']').value = ''; document.getElementById('form['+id+']').value = '';
else if( document.getElementById(id) ) else if( document.getElementById(id) )
document.getElementById(id).value = ''; document.getElementById(id).value = '';
fireEvent(document.getElementById(id), 'change'); fireEvent(document.getElementById(id), 'change');
} }
function datePicker4(obj, id, mask, startDate, endDate, showTIme, idIsoDate) function datePicker4(obj, id, mask, startDate, endDate, showTIme, idIsoDate)
{ {
if (showTIme=='false') { if (showTIme=='false') {
showTIme = false; showTIme = false;
} }
@@ -2063,7 +2063,7 @@ function fireEvent(element, event)
} }
} }
function elementAttributesNS(e, ns) function elementAttributesNS(e, ns)
{ {
if (!this.__namespaceRegexps) if (!this.__namespaceRegexps)
this.__namespaceRegexps = {}; this.__namespaceRegexps = {};
@@ -2083,7 +2083,7 @@ function elementAttributesNS(e, ns)
return result; return result;
} }
/** /**
* Translator function for internationalization * Translator function for internationalization
*/ */
function _() function _()
@@ -2093,23 +2093,31 @@ function _()
if( typeof TRANSLATIONS != 'undefined' && TRANSLATIONS) { if( typeof TRANSLATIONS != 'undefined' && TRANSLATIONS) {
if( typeof TRANSLATIONS[argv[0]] != 'undefined' ) { if( typeof TRANSLATIONS[argv[0]] != 'undefined' ) {
if (argc > 1) { if (argc > 1) {
trn = TRANSLATIONS[argv[0]]; trn = TRANSLATIONS[argv[0]];
for (i = 1; i < argv.length; i++) { for (i = 1; i < argv.length; i++) {
trn = trn.replace('{'+(i-1)+'}', argv[i]); trn = trn.replace('{'+(i-1)+'}', argv[i]);
} }
} }
else { else {
trn = TRANSLATIONS[argv[0]]; trn = TRANSLATIONS[argv[0]];
} }
} }
else { else {
trn = '**' + argv[0] + '**'; trn = '**' + argv[0] + '**';
} }
} }
else { else {
PMExt.error('Processmaker JS Core Error', 'The TRANSLATIONS global object is not loaded!'); PMExt.error('Processmaker JS Core Error', 'The TRANSLATIONS global object is not loaded!');
trn = ''; trn = '';
} }
return trn; return trn;
} }
var mb_strlen = function(str) {
var len = 0;
for (var i = 0; i < str.length; i++) {
len += str.charCodeAt(i) < 0 || str.charCodeAt(i) > 255 ? 2 : 1;
}
return len;
};

View File

@@ -1368,7 +1368,7 @@ var processmap=function(){
/* Change label End */ /* Change label End */
var menu = new this.parent.module.app.menuRight(); var menu = new this.parent.module.app.menuRight();
var textMenu = G_STRINGS.ID_PROCESSMAP_USERS_AND_GROUPS_ADHOC; var textMenu = G_STRINGS.ID_PROCESSMAP_USERS_AND_GROUPS_ADHOC;
var lengthText = textMenu.length * 0.60; var lengthText = mb_strlen(textMenu) * 0.60;
menu.make({ menu.make({
target: a, target: a,