b2evolution PHP Cross Reference Blogging Systems

Source: /rsc/js/helper.js - 183 lines - 4572 bytes - Text - Print

Description: This file implements the b2evoHelper object This file is part of the evoCore framework - {@link http://evocore.net/} See also {@link http://sourceforge.net/projects/evocms/}.

   1  /**
   2   * This file implements the b2evoHelper object
   3   * This file is part of the evoCore framework - {@link http://evocore.net/}
   4   * See also {@link http://sourceforge.net/projects/evocms/}.
   5   * @author yabs {@link http://innervisions.org.uk/ }
   6   * @version $Id: helper.js 9 2011-10-24 22:32:00Z fplanque $
   7   */
   8  
   9  
  10  var _b2evoHelper = function()
  11  {
  12      var me; // reference to self
  13  
  14      var _debug = false;
  15  
  16      var _t = Array(); // translation strings
  17  
  18      return {
  19          /**
  20           * Initialise the helper object
  21           * Adds any translation strings found in html
  22           *
  23           * @param debug (boolean) enable debug mode
  24           */
  25          Init:function()
  26          {
  27              // set available params to defaults
  28              var params = jQuery.fn.extend({
  29                  // no comma after final entry or IE barfs
  30                  debug:false, // are we in debug mode?
  31                  }, ( arguments.length ? arguments[0] : '' ) );
  32  
  33              _debug = params.debug; // set debug mode
  34  
  35              me = this; // set reference to self
  36  
  37              jQuery( '<div id="b2evoMessages"></div>' ).prependTo( '.pblock' );// placeholder for error/success messages
  38  
  39              jQuery( '#b2evo_translations div' ).each( function(){ // grab all translation strings
  40                  var untranslated = jQuery( this ).find( '.b2evo_t_string' ).html();
  41                  var translated = jQuery( this ).find( '.b2evo_translation' ).html();
  42                  _t[ untranslated ] = translated;
  43              });
  44  
  45              me.info( 'Helper object ready' );
  46          },
  47  
  48  
  49          /**
  50           * Displays messages
  51           *
  52           * @param message (string) message to display
  53           */
  54          DisplayMessage:function( message )
  55          {
  56              jQuery( '#b2evoMessages' ).addClass( "log_container" ).html( message );
  57          },
  58  
  59  
  60          /**
  61           * Displays Server messages
  62           *
  63           * @param message (string) message to display
  64           */
  65          DisplayServerMessage:function( message )
  66          {
  67              jQuery( '#b2evoMessages' ).removeClass( "log_container" ).html( message );
  68          },
  69  
  70  
  71          /**
  72           * Fades out the selected element(s)
  73           * For available effects see @link http://http://docs.jquery.com/Effects/animate#paramsoptions
  74           */
  75          FadeOut:function()
  76          {
  77              // set available params to defaults
  78              var params = jQuery.fn.extend({
  79                  // no comma after final entry or IE barfs
  80                  selector:'', // jQuery selector for objects to fade
  81                  start:{}, // params for start see @link http://http://docs.jquery.com/Effects/animate#paramsoptions
  82                  end:{}, // params for end see @link http://http://docs.jquery.com/Effects/animate#paramsoptions
  83                  callback:function(obj){}, // callback function when finished, will be passed the faded object
  84                  remove_style: true // remove style attribute when finished
  85                  }, ( arguments.length ? arguments[0] : '' ) );
  86              jQuery( params.selector ).animate( params.start, {
  87                      duration:"fast",
  88                      complete:function(){
  89                          jQuery( this ).animate( params.end,{
  90                              duration:"fast",
  91                              complete:function(){
  92                                  if( params.remove_style )
  93                                  {
  94                                      jQuery( this ).removeAttr( 'style' );
  95                                  }
  96                                  params.callback( this ); // trigger callback
  97                              }
  98                          });
  99                      }
 100              });
 101          },
 102  
 103  
 104          /**
 105           * replicates PHP's str_repeat() function
 106           *
 107           * @param data (string) string to repeat
 108           * @param multiplier (int) number of repeats required
 109           *
 110           * @return the multiplied string
 111           */
 112          str_repeat:function( data, multiplier )
 113          {
 114              if( multiplier = Math.floor( multiplier ) )
 115              {
 116                  return new Array( multiplier + 1 ).join( data );
 117              }
 118              return false;
 119          },
 120  
 121  
 122          /**
 123           * Translates a string
 124           *
 125           * @param untranslated (string) the string to be translated
 126           *
 127           * @return string translated string if available or original string
 128           */
 129          T_:function( untranslated )
 130          {
 131              if( typeof( _t[ untranslated ] ) == 'string' )
 132              { // we have a translation
 133                  return _t[ untranslated ];
 134              }
 135              return untranslated;
 136          },
 137  
 138  
 139          /**
 140           * Add Log message to console if enabled and in debug mode
 141           *
 142           * @param message (string) message to be added to the console
 143           */
 144          log:function(message)
 145          {
 146              if( _debug && typeof( console ) == 'object' )
 147              {
 148                  console.log( message );
 149              }
 150          },
 151  
 152  
 153          /**
 154           * Add Error message to console if enabled and in debug mode
 155           *
 156           * @param message (string) message to be added to the console
 157           */
 158          error:function(message)
 159          {
 160              if( _debug && typeof( console ) == 'object' )
 161              {
 162                  console.error( message );
 163              }
 164          },
 165  
 166  
 167          /**
 168           * Add Info message to console if enabled and in debug mode
 169           *
 170           * @param message (string) message to be added to the console
 171           */
 172          info:function(message)
 173          {
 174              if( _debug && typeof( console ) == 'object' )
 175              {
 176                  console.info( message );
 177              }
 178          }
 179      }
 180  } // _b2evoHelper
 181  
 182  // create instance of the helper
 183  var b2evoHelper = new _b2evoHelper();

title

Description

title

Description

title

Description

title

title

Body