Friday, May 23, 2008

Soft Hyphens in javascript

Soft Hyphens
Tucked away in the list of CSS improvements in Firefox 3 is this innocuous-looking feature: “HTML soft hyphens (­) are now supported.”
Soft hyphens are one of those obscure gems that HTML has always supported on paper, but that no one has taken any notice of because browser support has been spotty. With the imminent release of Firefox 3, however, soft hyphens will be supported by all major browsers including Internet Explorer, Safari, and Opera.
So, what is a soft hyphen, anyway?
A soft hyphen is a character of text that is usually invisible. It signals a spot in the text (usually in the middle of a long word) where it would be acceptable to break the line with a hyphen.
When a browser that supports soft hyphens encounters a long word or other long piece of text with no obvious wrap point that doesn’t fit horizontally inside a block on the page, it will look for a soft hyphen within the text and display it as a normal hyphen followed by a line break.
Take a look at this code sample:


Supercalifragilisticexpialidocious


Display this in any browser, and the long word will protrude from the side of the div.

This situation arises all the time in real-world web design. Say you’ve got a navigation menu that occupies 25% of the width of the page. At small enough browser window sizes, a particularly long word in one of your menu items will either protrude messily from your menu into another part of the page, or force the menu to increase its width, possibly breaking your page layout.
Soft hyphens to the rescue!


Supercalifragilistic­expialidocious



Firefox 3 will be the last major browser to add support for soft hyphens, but you don’t have to wait for it to be released to start using them! Firefox 2 simply ignores the character, leaving it invisible (and leaving your text protruding from its box). Not bad as a fallback, especially compared to Safari, which used to display it as a normal hyphen! Thankfully, Safari 2 or later gets it right.
Depending on how you edit your HTML, you may simply want to insert the soft hyphen character itself rather than the HTML character entity reference (­). It’ll save a few bytes, and good code editors (jEdit, for example) will display soft hyphens as normal hyphens, so you can see them in your code. Some are even smart enough to ignore soft hyphens when checking your spelling!
You can type a soft hyphen in Windows by holding down the Alt key and then typing either 0173 on the number pad, or the plus key on the number pad followed by 00AD, before releasing Alt. If you can’t remember that (I sure can’t), or if you’re on a Mac, you can find the soft hyphen in the Character Map (the Character Palette in Mac OS X).
If you do decide to use actual soft hyphen characters in your code, make sure you know your character encodings, because unlike most Latin-1 characters, soft hyphens are encoded differently in UTF-8, so you need to save your code with the right encoding for the soft hyphens to work.

Artical from SitePoint. JavaScript & CSS Blog: Stylish Scriptingby Kevin YankTwo Hidden Features New in Firefox 3

Wednesday, May 14, 2008

Java Script Validation Functions


/****************************************************/
/* COMMON JAVASCRIPT FUNCTIONS */
/****************************************************/
// VARIABLES FOR COLOR
//var BG_ERR_CLR = 'red'; // error background color.
var FG_ERR_CLR = 'black'; // error foreground color.
var BG_DEF_CLR = 'white'; // default background color.
var FG_DEF_CLR = 'black'; // default foreground color.
var CONTROL = 'CONTROL'; // default foreground color.
var BG_ERR_CLR = '#FFE87C';
//var BG_ERR_CLR = 'RED';
--------------------------Method names --------------------------------------
1. showError()
/**
* showError()
* ================
*
* Show the Message Box (Error, Information, Warning)
*
* Parameters
* ----------
* - MANDATORY MUST BE PASSED BY USER
* - MANDATORY MUST BE PASSED BY USER
* - OPTIONAL
* Return value
* ------------
*/
function showError()
{
lstrMessageID = showError.arguments[0];
lstrMessage = showError.arguments[1];
lobjField = showError.arguments[2];

lstrFinalMsg = lstrMessageID + ' : ' + lstrMessage;

if(lobjField!=null)
{
setErrorColor(lobjField);
lobjField.focus();
}
alert(lstrFinalMsg);
}

2. showQuestion()
/**
* showQuestion()
* ================
*
* Show the Message Box (Warning) - Yes/No
*
* Parameters
* ----------
* - MANDATORY MUST BE PASSED BY USER
* - MANDATORY MUST BE PASSED BY USER
* - OPTIONAL
* Return value
* ------------
* -
*/
function showQuestion()
{
lstrMessageID = showQuestion.arguments[0];
lstrMessage = showQuestion.arguments[1];
lobjField = showQuestion.arguments[2];

lstrFinalMsg = lstrMessageID + ' : ' + lstrMessage;

/*if(lobjField!=null){
lobjField.focus();
}*/
return confirm(lstrFinalMsg);
}

3. getComboUpdated(comboObj,strDispValue, strKey)
// Input Parameter - 1. Combo Object
// 2. Text of the option
// 3. Value that is to be returned, when the option is selected
// Output Parameter - None
// Functionality - This function dynamically adds an option to the combo.

function getComboUpdated(comboObj,strDispValue, strKey)
{
var option = new Option(strDispValue, strKey);
// Add a new option to the combo
var i = comboObj.length;
comboObj.options[i]=option;
}

4. openFlmAsPopup(frameName,url,context1,context2,context3,context4)
// Input Parameter - 1. Url of the popup frame
// 2. Url of screen to be opened in the frame
// 3. object name to be passed to the popup screen.
// 4. object name to be passed to the popup screen.
// 5. object name to be passed to the popup screen.
// 6. object name to be passed to the popup screen.
// Output Parameter - None
// Functionality - This is used to open flm in popup mode..
function openFlmAsPopup(frameName,url,context1,context2,context3,context4)
{
strURL = frameName;
if(context1 != null)
{
strURL = strURL + "&enq_context1=";
strURL = strURL + context1;
}
if(context2 != null)
{
strURL = strURL + "&enq_context2=";
strURL = strURL + context2;
}
if(context3 != null)
{
strURL = strURL + "&enq_context3=";
strURL = strURL + context3;
}
if(context4 != null)
{
strURL = strURL + "&enq_context4=";
strURL = strURL + context4;
}
strURL=strURL + '&url='+escape(url+'&popup=true');
//alert('url constructed is'+strURL);
openPopupWindowWithPos(strURL, '870', '550', '20', '40');

}

5. populateGR(objField, HiddenFieldvalue)
function populateGR(objField, HiddenFieldvalue)
{
if ((objField.value).length == 0)
{
objField.value=HiddenFieldvalue;
}
}

6. RefreshOpenerWindowAndCloseMe(strUrl)
function RefreshOpenerWindowAndCloseMe(strUrl)
{
if(window.opener)
{
// refresh the opener window...as user has selected one of the customer records from the table
window.opener.location.href = strUrl;
// close the current window after refreshing the opener
window.close();
}
}


7. openPopupWindow(strUrl, lngWidth, lngHeight)
function openPopupWindow(strUrl, lngWidth, lngHeight)
{

var strWindowName = "";
var strWindowFeatures;

strWindowFeatures = "toolbar=no,resize=yes,titlebar=no,";
strWindowFeatures = strWindowFeatures + "location=no,directories=no,status=no,scrollbars=yes,"
strWindowFeatures = strWindowFeatures + "menubar=no,width=" + lngWidth + ",height=" + lngHeight + ",maximize=null";

// open the window
window.open(strUrl, "", strWindowFeatures);
}

//--- Enter Numeric value with decimal..
8. function pressCharOnlyHandeler(e)

{

if ((e.keyCode >= 65 && e.keyCode <= 90) || (e.keyCode >= 97 && e.keyCode <= 122) ) {
return true;
}
else
{
return false;
}
}

/**
* isSelected()
* ================
*
* Function to check if any checkbox is selected or not
* Assumes that the checkbox column in the table has been defined by the name 'selected'
*
* Parameters -
* ----------
*
* Return value -
* ------------
*/

9. function isSelected()

{
var table = document.getElementById(arguments[0]);
var numrows = table.rows.length;
if(numrows <= 0) { return false; } var chk = 0; for(i=0;;i++)
{
var str = 'accountDatas[' + i + '].delStatus';
var obj = document.getElementById(str);
if(obj == null)
{
break;
}
if(obj.checked)
{
chk=1; break;
}
}
if(chk==1)
{
return true;
}
else
{
return false;
}
}


/**
* isEmpty()
* ================
*
* Check whether string s is empty.
*
* Parameters
* ----------
* -
*
* Return value
* ------------
* -
*/
10. function isEmpty(lstrValue)

{
lstrValue=leftTrimString(lstrValue);
lstrValue=rightTrimString(lstrValue);

return ((lstrValue == null) (lstrValue.length == 0))
}

/////////////////// STRING FUNCTIONS- BEGIN /////////////////////////////////////

/**
* rightTrimString()
* ================
*
* Trim the blank spaces on the right side of the string
*
* Parameters
* ----------
* -
*
* Return value
* ------------
* -
*/
11. function rightTrimString(astrValue)

{
var lstrValue = astrValue;

lstrValue=lstrValue.replace(/(.*?)\s*$/, "$1");
return lstrValue;
}

/**
* leftTrimString()
* ================
*
* Method to Trim the blank spaces on the left side of the string
*
* Parameters
* ----------
* -
*
* Return value
* ------------
* -
*/
12. function leftTrimString(astrValue)

{
var lstrValue = astrValue;

lstrValue=lstrValue.replace(/^\s*(.*)/, "$1");
return lstrValue;
}

/**
* trimString()
* ================
*
* Method to remove the left and right curtailing spaces
*
* Parameters
* ----------
* -
*
* Return value
* ------------
* -
*/
13. function trimString(astrValue)

{
var lstrValue = astrValue;

lstrValue=leftTrimString(lstrValue);
lstrValue=rightTrimString(lstrValue);
return lstrValue;
}

14. function isInteger(aValue)
{
var lstrValue = aValue;
re = new RegExp(",","g");
lstrValue = lstrValue.replace(re,"");
for (lintCounter = 0; lintCounter < c =" lstrValue.charAt(lintCounter);"> "9"))){
return false;
}
}

/**
* validateFloat()
* ================
*
* To validate that the number passed is valid or not
*
* Parameters
* ----------
* - MANDATORY MUST BE PASSED BY USER
* - MANDATORY MUST BE PASSED BY USER
* - MANDATORY MUST BE PASSED BY USER
* - OPTIONAL (By default it is false)
*
* Return value
* ------------
* -
*/

15. function validateFloat(astrNumber,astrDigitsBefDec,astrDigitsAfterDec)
{
var lreComma = new RegExp(",","g");
var lblnResult = false;
var lstrVal = astrNumber;
var lstrDigitsBefDec = astrDigitsBefDec;
var lstrDigitsAfterDec = astrDigitsAfterDec;
var lblnNegativeAllowed = validateFloat.arguments[3];
// Replace the commas if present in the value
if(lstrVal != null && lstrVal.length > 0){
lstrVal = validateFloat.arguments[0].replace(lreComma,"");
}else{
// If Null is passed then return false
return false;
}

if(lblnNegativeAllowed == null lblnNegativeAllowed.length == 0){
lblnNegativeAllowed = false;
}

if(lblnNegativeAllowed){
//To match positive or negative real numbers with or without a decimal point and 0 to <> decimal places.
lexp = "^-?\\d{0," + lstrDigitsBefDec + "}(\\.\\d{0," + lstrDigitsAfterDec + "})?$";
lreData = new RegExp(lexp);
lblnResult = lreData.test(lstrVal);
}else{
//To match positive real numbers with or without a decimal point and 0 to <> decimal places.
lexp = "^\\d{0," + lstrDigitsBefDec + "}(\\.\\d{0," + lstrDigitsAfterDec + "})?$";
lreData = new RegExp(lexp);
lblnResult = lreData.test(lstrVal);
}
return lblnResult;
}


Global Tech Soft Solution

Smart software solution.

Webdesigning, software Development & Consultant GlobalTech Soft Solution