This way does not work (elements are pulled in from with in the function ).
function styleTwitter1( pair_array )
{
var i;
var input;
var label;
var font_size;
for ( i = 0; i < pair_array.length; i+=2 )
{
/*
*/
input = document.getElementById( pair_array[ i ] );
label = document.getElementById( pair_array[ i + 1 ] );
/*
*/
label.fontSize = window.getComputedStyle( label, null ).getPropertyValue("font-size");
/*
*/
input.addEventListener( "keypress", function()
{
label.style.opacity = 0;
}, false );
/*
*/
input.addEventListener( "focus", function()
{
if( input.value === '' )
{
label.style.opacity = 0.2;
input.style.border = '1px solid #888888';
}
} , false );
/*
*/
input.addEventListener( "blur", function()
{
if( input.value === '' )
{
label.style.opacity = 1;
new EffectsFont( label ).fade( 'up', 150 );
input.style.border = '1px solid #dddddd';
}
} , false );
/*
*/
}
}
However, this way does (elements are injected from outside the function).
function initTwitterStyle( input, label )
{
/*
*/
input.addEventListener( "keypress", function()
{
label.style.opacity = 0;
}, false );
/*
*/
input.addEventListener( "focus", function()
{
if( input.value === '' )
{
label.style.opacity = 0.2;
input.style.border = '1px solid #888888';
}
}, false );
/*
*/
input.addEventListener( "blur", function()
{
if( input.value === '' )
{
label.style.opacity = 1;
new EffectsFont( label ).fade( 'up', 150 );
input.style.border = '1px solid #dddddd';
}
}, false );
/*
*/
}
What I will end up doing if I can't figure out the difference is pull my array loop outside and just inject twitterStyle2 with elements.
Currently, I can't get an error code but only one pair is being initialized..and then EffectsFont does not work.
Jshint warns against creating function in loops but I don't understand why? What is the issue?