/** * @summary Create and Animate everything. * * Executed everytime a shortcode or widget is called. * Assigns the background, sets the height and creates all the random values needed * for the animation. * * @since 0.1.0 * * @global string actusAnitID:true The unique ID of this instance. * @global string actusAnitTerms:true The terms to be animated. * @global string actusAnitOpts:true The plugin options. * @global string actusAnitDir:true The plugin directory. * @global string actusAnitSelector:true The plugin selector name - #id. * * @param array actusAnitParams Parameters received from PHP call. */ var actusAnitID, actusAnitTerms, actusAnitOpts, actusAnitDir, actusAnitSelector; // Set main variables from parameters received from PHP. actusAnitID = actusAnitParams.id; actusAnitTerms = actusAnitParams.terms; actusAnitOpts = actusAnitParams.opts; actusAnitDir = actusAnitOpts.plugin_dir; site_url = actusAnitParams.site_url; actusAnitSelector = '#' + actusAnitID; if ( typeof( actusVisibleTags ) === 'undefined' ) { actusVisibleTags = []; } actusVisibleTags[ actusAnitID ] = 0; actusAnitOpts.height = parseInt( actusAnitOpts.height ); actusAnitOpts.min_font_size = parseInt( actusAnitOpts.min_font_size ); actusAnitOpts.max_font_size = actusAnitOpts.height + ( actusAnitOpts.height / 6 ); if ( typeof( actusAnitArgs ) === 'undefined' ) { var actusAnitArgs = {}; } actusAnitArgs[ actusAnitID ] = {}; /** * @summary Sets the background and the height of the plugin. * * @since 0.1.0 * * @global type $varname Short description. * @fires target:event * @listens target:event * * @var string terms The terms to be animated. * @var string options The plugin options. * @var string backFilename The background filename (or random). * @var string backURL The background URL. * @var array args All arguments needed for the animation. * @var int visibleTags The number of currently visible tags. */ function actusAnitStart( iid ) { var backFilename, backURL; actusAnitArgs[ iid ] = { 'id' : actusAnitID, 'selector' : actusAnitSelector, 'opts' : actusAnitOpts, 'terms' : actusAnitTerms, 'plugin_dir' : actusAnitDir, 'visibleTags': 0 }; backFilename = actusAnitOpts.background; if ( backFilename == 'random' ) { backNumber = Math.floor((Math.random() * 14 ) + 1 ); if ( backNumber < 10 ) { backNumber = '0' + backNumber; } backFilename = backNumber + '.jpg'; } backURL = 'url( ' + actusAnitDir + 'img/back/' + backFilename + ' )'; jQuery( actusAnitSelector + ' .actus-anit-cloud').height( actusAnitOpts.height ); jQuery( actusAnitSelector + ' .actus-anit-cloud').css( "background-image", backURL ); actusAnitRandomValues( iid, function() { actusAnitAnimate( iid ); }); } // Execute Animation. actusAnitStart( actusAnitID ); /** * @summary Sets the random values needed for the animation. * * @since 0.1.0 * * @var string randomTerm The term to be animated. * @var string randomFontSize. * @var string randomOpacity. * @var string randomVpos. * @var string randomSpeed. * @var string randomDirection. * @var string minTime The minimum number of ms for animation. * @var string maxTime The maximum number of ms for animation. * * @param string id The unique ID of the current instance. * @param string selector The plugin selector name - #id. * @param string callback The callback function. */ function actusAnitRandomValues( iid, callback ) { callback = callback || function(){}; var minTime, maxTime; minTime = 7 * 1000; maxTime = 30 * 1000; opts = actusAnitArgs[ iid ].opts; terms = actusAnitArgs[ iid ].terms; actusAnitArgs[ iid ].randomTerm = terms [ Math.floor( ( Math.random() * terms.length ) - 0) ]; actusAnitArgs[ iid ].randomFontSize = Math.floor( Math.random() * ( opts.max_font_size - opts.min_font_size ) + opts.min_font_size ); actusAnitArgs[ iid ].randomOpacity = ( Math.floor( ( Math.random() * 70 ) + 5 ) ) / 100; actusAnitArgs[ iid ].randomVpos = Math.floor( ( Math.random() * ( opts.height - ( actusAnitArgs[ iid ].randomFontSize / 3.75 ) ) ) - ( actusAnitArgs[ iid ].randomFontSize / 5 ) ); actusAnitArgs[ iid ].randomSpeed = Math.floor( Math.random() * ( maxTime - minTime + 1 ) + minTime ); actusAnitArgs[ iid ].randomDirection = Math.floor( ( Math.random() * 2 ) + 1 ); callback(); } /** * @summary Sets the background and the height of the plugin. * * @since 0.1.0 * * @var int randomFreq Time until next timeout. * @var int visibleTags The number of currently visible tags. * * @param string id The unique ID of the current instance. * @param string selector The plugin selector name - #id. */ function actusAnitAnimate( iid ) { var randomFreq; actusAnitRandomValues( iid, function(){ if ( actusAnitArgs[ iid ].visibleTags < parseInt( opts.density ) ) { actusAnitAnimateTag( iid ); } }); randomFreq = Math.floor((Math.random() * 3000) + 350); if ( opts.density > 8 ) { randomFreq = Math.floor((Math.random() * 2500) + 250); } if ( opts.density > 20 ) { randomFreq = Math.floor((Math.random() * 500) + 50); } window.setTimeout(function() { actusAnitAnimate( iid ) }, randomFreq ); } /** * @summary Sets the random values needed for the animation. * * @since 0.1.0 * * @var string randomTerm The term to be animated. * @var string randomFontSize. * * @param string id The unique ID of the current instance. * @param string selector The plugin selector name - #id. * @param string callback The callback function. */ function actusAnitAnimateTag( iid ) { var termID, termH, cur, curW, cloudW, startX, endX; if ( typeof( actusAnitArgs[ iid ].randomTerm ) !== 'undefined' ) { if ( typeof( actusAnitArgs[ iid ].randomTerm.name ) !== 'undefined' ) { actusAnitArgs[ iid ].visibleTags = actusAnitArgs[ iid ].visibleTags + 1; termID = 'T-' + jQuery.now(); termH = '' + actusUpper( actusAnitArgs[ iid ].randomTerm.name ) + ''; jQuery( actusAnitArgs[ iid ].selector + ' .actus-anit-cloud' ).append( termH ); cur = jQuery( actusAnitArgs[ iid ].selector + ' .actus-anit-cloud .actus-animated-tag' ).last(); cloudW = jQuery( actusAnitArgs[ iid ].selector + ' .actus-anit-cloud' ).width(); jQuery( '#' + termID ).css({ 'font-size': actusAnitArgs[ iid ].randomFontSize + 'px' }); curW = cur.width(); startX = 0 - curW; endX = cloudW; if ( actusAnitArgs[ iid ].randomDirection == 2 ) { startX = cloudW; endX = 0 - curW - 20; } jQuery( '#' + termID ).css({ 'transform': 'translateX(' + startX + 'px)', 'top' : actusAnitArgs[ iid ].randomVpos, 'opacity' : actusAnitArgs[ iid ].randomOpacity }); window.setTimeout( function( tagID ) { jQuery( '#' + tagID ).css({ '-webkit-transition': 'transform ' + actusAnitArgs[ iid ].randomSpeed + 'ms linear', 'transition' : 'transform ' + actusAnitArgs[ iid ].randomSpeed + 'ms linear', 'transform' : 'translateX(' + endX + 'px)' }).delay( actusAnitArgs[ iid ].randomSpeed ).queue(function() { jQuery( this ).remove(); actusAnitArgs[ iid ].visibleTags = actusAnitArgs[ iid ].visibleTags - 1; if ( actusAnitArgs[ iid ].visibleTags < 0 ) { actusAnitArgs[ iid ].visibleTags = 0; } }); }, 100, termID ); } } } /** * @summary Converts a string to uppercase removing accents on Greek alphabet. * * @since 0.1.0 * * @param string string The string to be converted. * * @return string string The converted string. */ function actusUpper( string ) { // ************************************************************** string = string.replace(/[ΰ]/g,"ϋ"); string = string.replace(/[ΐ]/g,"ϊ"); string = string.toUpperCase(); string = string.replace(/[Ά]/g,"Α"); string = string.replace(/[Έ]/g,"Ε"); string = string.replace(/[Ή]/g,"Η"); string = string.replace(/[Ύ]/g,"Υ"); string = string.replace(/[Ώ]/g,"Ω"); string = string.replace(/[Ί]/g,"Ι"); string = string.replace(/[Ό]/g,"Ο"); return string; }