[ Index ]

PHP Cross Reference of GlotPress

title

Body

[close]

/js/ -> common.js (source)

   1  var $gp = function($) { return {
   2      notices: {
   3          element: null,
   4          init: function() {
   5              $gp.notices.element = $('#gp-js-message');
   6          },
   7          error: function(message) {
   8              $gp.notices.generic_message('gp-js-error', message);
   9          },
  10          notice: function(message) {
  11              $gp.notices.generic_message('gp-js-notice', message);
  12          },
  13          success: function(message) {
  14              $gp.notices.generic_message('gp-js-success', message);
  15              $gp.notices.element.fadeOut(10000);
  16          },
  17          clear: function(message) {
  18              $gp.notices.element.html('').hide();
  19          },
  20          generic_message: function(css_class, message) {
  21              // TODO: add close button, at least to errors
  22              $gp.notices.element.removeClass().addClass(css_class).html(message);
  23              $gp.notices.center();
  24              $gp.notices.element.show();
  25          },
  26          center: function() {
  27              $gp.notices.element.css('left', ($(document).width() - $gp.notices.element.width()) / 2);
  28          }
  29      },
  30      esc_html: function(s) {
  31          return $('<div/>').text(s).html();
  32      },
  33      init: function() {
  34          $gp.notices.init();
  35      }
  36  }}(jQuery);
  37  
  38  $gp.showhide = function($) { return function(link, container, options) {
  39      var defaults= {
  40          show_text: 'Show',
  41          hide_text: 'Hide',
  42          focus: false,
  43          group: 'default'
  44      }
  45      var options = $.extend({}, defaults, options);
  46      var $link = $(link);
  47      var $container = $(container);
  48      if ( !$gp.showhide.registry[options.group] ) $gp.showhide.registry[options.group] = [];
  49      var registry = $gp.showhide.registry[options.group]; 
  50      var show = function() {
  51          for(var i = 0; i < registry.length; ++i) {
  52              registry[i].hide();
  53          }
  54          $container.show();
  55          if (options.focus) $(options.focus, $container).focus();
  56          $link.html(options.hide_text).addClass('open');
  57      }
  58      var hide = function() {
  59          $container.hide();
  60          $link.html(options.show_text).removeClass('open');
  61      }
  62      registry.push({show: show, hide: hide});
  63      $link.click(function() {
  64          $container.is(':visible')? hide() : show();
  65          return false;
  66      })
  67  }}(jQuery);
  68  $gp.showhide.registry = {};


Generated: Thu May 24 03:59:35 2012 Hosted by follow the white rabbit.