/* * Trim a string */ function trim(str) { return str.replace(/^\s*/, "").replace(/\s*$/, ""); } /* * Check if the string is email */ function isEmail(email){ var reg = /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/; return reg.test(email); } /* * Merge two list string into one. The list string contains items separated by ',' * The merged string eliminate duplicate items. */ function mergeList(list1, list2){ var listArray1 = list1.split(','); var listArray2 = list2.split(','); var mergedArray = listArray1.concat(listArray2); var trimedArray = new Array(); // Eliminate empty items and trim other items for(key in mergedArray){ var trimed = trim(mergedArray[key]); if(trimed.length > 0){ trimedArray.push(trimed); } } // Eliminate duplicates mergedArray = eliminateDuplicates(trimedArray); return mergedArray.join(', '); } /* * Subtract 2nd list string from the 1st. The items in the second list will be deleted * from the first list. */ function subtractList(list1, list2){ var listArray1 = trimArray(list1.split(',')); var listArray2 = trimArray(list2.split(',')); var indexArray = new Array(); var result = new Array(); // Build index of list2 for(key in listArray2){ if(listArray2[key]!=''){ indexArray[listArray2[key]] = 1; } } for(key in listArray1){ if(indexArray[listArray1[key]]==undefined){ // This item doesn't exist in list2, add it to the result result.push(listArray1[key]); } } return result.join(', '); } /* * Trim items in an array */ function trimArray(arr){ var out = new Array(); for(key in arr){ out.push(trim(arr[key])); } return out; } /* * Eliminate duplicate items in an array */ function eliminateDuplicates(arr) { var i, len=arr.length, out=[], obj={}; for (i=0;i'); jQuery('#cms_util_userinput_bg').css({'opacity':0.1}); // Get popup window config var width = '500px;'; var top = '200px'; if(panelConfig!=null && panelConfig!=undefined){ if(panelConfig['width']!=undefined) width=panelConfig['width']; if(panelConfig['top']!=undefined) top=panelConfig['top']; } // Create popup panel jQuery('body').append('
'); // Create popup window jQuery('#cms_util_userinput_panel').append('
'); jQuery('#cms_util_userinput').append(panelContent); jQuery('#cms_util_userinput').append('
' + '    ' + '' + '
'); // Animate the display of input box jQuery('#cms_util_userinput').css({'height':'auto'}); var height=jQuery('#cms_util_userinput').height(); jQuery('#cms_util_userinput').css({'height':'0'}); jQuery('#cms_util_userinput').animate({'height':height+'px'},500); // Click on panel event jQuery('#cms_util_userinput_bg').click(function(){ // Clean panel jQuery('#cms_util_userinput').animate({'height':'0'}, 500, function(){ jQuery('#cms_util_userinput').remove(); jQuery('#cms_util_userinput_panel').remove(); jQuery('#cms_util_userinput_bg').remove(); }); callback(new Array()); }); // Ok Event jQuery('#cms_util_userinput_ok').click(function(){ // Get user input var userInput = new Array(); jQuery('#cms_util_userinput input, #cms_util_userinput textarea, #cms_util_userinput select').each(function(){ var name = jQuery(this).attr('name'); if(name == undefined || name == ''){ name = jQuery(this).attr('id'); if(name == undefined || name == ''){ return; } } var value = jQuery(this).val(); userInput[name] = value; }); // Clean panel jQuery('#cms_util_userinput').animate({'height':'0'}, 500, function(){ jQuery('#cms_util_userinput').remove(); jQuery('#cms_util_userinput_panel').remove(); jQuery('#cms_util_userinput_bg').remove(); }); callback(userInput); }); // Cancel event jQuery('#cms_util_userinput_cancel').click(function(){ // Clean panel jQuery('#cms_util_userinput').animate({'height':'0'}, 500, function(){ jQuery('#cms_util_userinput').remove(); jQuery('#cms_util_userinput_panel').remove(); jQuery('#cms_util_userinput_bg').remove(); }); callback(new Array()); }); } /* * Convert plain text to permalink */ function toPermalink(permalink){ permalink = permalink.toLowerCase().replace(/[ ]/g,'-'); // /g means search all permalink = permalink.replace(/[^a-zA-Z0-9\-\/\.]/g,''); while(permalink.indexOf('--')!=-1){ permalink = permalink.replace(/\-\-/g,'-'); } return permalink; } /* * Get the current date and time */ function getDateTime(){ var currentTime = new Date() var year = currentTime.getFullYear(); var month = currentTime.getMonth() + 1 var day = currentTime.getDate()+1; var hours = currentTime.getHours() var minutes = currentTime.getMinutes() var seconds = currentTime.getSeconds(); return '' + year + '-' + month + '-' + day + ' ' + hours + ':' + minutes + ':' + seconds; } /* * Restore the height of a object */ function restoreHeight(object, time){ jQuery(object).stop(); jQuery(object).css({'height':'auto'}); var height=jQuery(object).height(); jQuery(object).css({'height':'0'}); jQuery(object).animate({'height':height+'px'}, time, function(){ jQuery(object).css({'height':'auto'}); }); } /* * Solution for target="_blank". Use class="newWindow" to indicate open a new window for the link */ jQuery(document).ready(function(){ refreshNewWindowLink(); }); function refreshNewWindowLink(){ jQuery('.newWindow').unbind('click.cms'); jQuery('.newWindow').bind('click.cms', function(){ var href = jQuery(this).attr('href'); window.open(href); return false; }); }