updating a js file
Hey Jason
Am using the following js to run a testimonials 'slideshow' on a site and was wondering if there is any way to use PCMS to allow the client to be able to update the textArray area without having to get them to update the whole js file?
$(document).ready( function() {
var textArray = [
'Yesterday is history. Tomorrow is a mystery. Today is a gift. That\'s why we call it present.',
'The best way to get a man to do something is to suggest they are too old for it.',
'To be happy with a man you must understand him a lot and love him a little. To be happy with a woman you must love her a lot and not try to understand her at all.',
'My wife suggested a book for me to read to enhance our relationship. It\'s titled, "Women are from Venus, Men are Wrong."',
'You can tell more about a person by what he says about others than you can by what others say about him.',
'If you wish to live wisely, ignore sayings, including this one.',
'You have the right to remain silent. Anything you say will be misquoted, then used against you.',
'Murphy\'s Fourth Law: If there is a possibility that several things can go wrong, then the one that will cause the greatest damage will be the one to go wrong.',
'I want to die peacefully in my sleep like my grandfather - not screaming and yelling like the passengers in his car.',
'The early bird may get the worm, but the second mouse gets the cheese.',
'Evening news is where they start by saying "Good Evening" and proceed by telling you why it\'s not.',
'Before you criticize someone, walk a mile in their shoes. That way, you\'ll be a mile from them and have their shoes.',
'All generalizations are false, including this one.' /**/
];
$('#text-box').randomText( textArray, 10000); // ( array, interval, ["reload text or html"] )
});
// custom jquery plugin loadText()
$.fn.randomText = function( textArray, interval, randomEle, prevText ) {
var obj = $(this);
if( $('#text-content').length == 0 ){ obj.append('<div id="text-content">'); }
var textCont = $('#text-content');
if( typeof randomEle != 'undefined' ){ if( $('#randomizer').length == 0 ){ obj.append('<a href="javascript:;" id="randomizer"><em>' + randomEle ); } }
textCont.fadeOut( 'slow', function() {
var chosenText = random_array( textArray );
while( chosenText == prevText ) { chosenText = random_array( textArray ); }
textCont.empty().html( chosenText );
textCont.fadeIn( 'slow' );
sendText = chosenText;
});
timeOut = setTimeout( function(){ obj.randomText( textArray, interval, randomEle, sendText ); }, interval );
$("#randomizer").click( function(){
if( !textCont.is(':animated') ) { clearTimeout( timeOut ); obj.randomText( textArray, interval, randomEle, sendText );} // animation check prevents "too much recursion" error in jQuery
});
}
//public function
function random_array( aArray ) {
var rand = Math.floor( Math.random() * aArray.length + aArray.length );
var randArray = aArray[ rand - aArray.length ];
return randArray;
}