[ Index ]

PHP Cross Reference of Drupal 6 (gatewave)

title

Body

[close]

/sites/all/modules/views/js/ -> base.js (source)

   1  // $Id: base.js,v 1.11.2.1 2010/03/10 20:08:58 merlinofchaos Exp $
   2  /**
   3   * @file base.js
   4   *
   5   * Some basic behaviors and utility functions for Views.
   6   */
   7  
   8  Drupal.Views = {};
   9  
  10  /**
  11   * jQuery UI tabs, Views integration component
  12   */
  13  Drupal.behaviors.viewsTabs = function (context) {
  14    $('#views-tabset:not(.views-processed)').addClass('views-processed').each(function() {
  15      new Drupal.Views.Tabs($(this), {selectedClass: 'active'});
  16    });
  17  
  18    $('a.views-remove-link')
  19      .addClass('views-processed')
  20      .click(function() {
  21        var id = $(this).attr('id').replace('views-remove-link-', '');
  22        $('#views-row-' + id).hide();
  23        $('#views-removed-' + id).attr('checked', true);
  24        return false;
  25      });
  26  }
  27  
  28  /**
  29   * For IE, attach some javascript so that our hovers do what they're supposed
  30   * to do.
  31   */
  32  Drupal.behaviors.viewsHoverlinks = function() {
  33    if ($.browser.msie) {
  34      // If IE, attach a hover event so we can see our admin links.
  35      $("div.view:not(.views-hover-processed)").addClass('views-hover-processed').hover(
  36        function() {
  37          $('div.views-hide', this).addClass("views-hide-hover"); return true;
  38        },
  39        function(){
  40          $('div.views-hide', this).removeClass("views-hide-hover"); return true;
  41        }
  42      );
  43      $("div.views-admin-links:not(.views-hover-processed)")
  44        .addClass('views-hover-processed')
  45        .hover(
  46          function() {
  47            $(this).addClass("views-admin-links-hover"); return true;
  48          },
  49          function(){
  50            $(this).removeClass("views-admin-links-hover"); return true;
  51          }
  52        );
  53    }
  54  }
  55  
  56  /**
  57   * Helper function to parse a querystring.
  58   */
  59  Drupal.Views.parseQueryString = function (query) {
  60    var args = {};
  61    var pos = query.indexOf('?');
  62    if (pos != -1) {
  63      query = query.substring(pos + 1);
  64    }
  65    var pairs = query.split('&');
  66    for(var i in pairs) {
  67      var pair = pairs[i].split('=');
  68      // Ignore the 'q' path argument, if present.
  69      if (pair[0] != 'q' && pair[1]) {
  70        args[pair[0]] = decodeURIComponent(pair[1].replace(/\+/g, ' '));
  71      }
  72    }
  73    return args;
  74  };
  75  
  76  /**
  77   * Helper function to return a view's arguments based on a path.
  78   */
  79  Drupal.Views.parseViewArgs = function (href, viewPath) {
  80    var returnObj = {};
  81    var path = Drupal.Views.getPath(href);
  82    // Ensure we have a correct path.
  83    if (viewPath && path.substring(0, viewPath.length + 1) == viewPath + '/') {
  84      var args = decodeURIComponent(path.substring(viewPath.length + 1, path.length));
  85      returnObj.view_args = args;
  86      returnObj.view_path = path;
  87    }
  88    return returnObj;
  89  };
  90  
  91  /**
  92   * Strip off the protocol plus domain from an href.
  93   */
  94  Drupal.Views.pathPortion = function (href) {
  95    // Remove e.g. http://example.com if present.
  96    var protocol = window.location.protocol;
  97    if (href.substring(0, protocol.length) == protocol) {
  98      // 2 is the length of the '//' that normally follows the protocol
  99      href = href.substring(href.indexOf('/', protocol.length + 2));
 100    }
 101    return href;
 102  };
 103  
 104  /**
 105   * Return the Drupal path portion of an href.
 106   */
 107  Drupal.Views.getPath = function (href) {
 108    href = Drupal.Views.pathPortion(href);
 109    href = href.substring(Drupal.settings.basePath.length, href.length);
 110    // 3 is the length of the '?q=' added to the url without clean urls.
 111    if (href.substring(0, 3) == '?q=') {
 112      href = href.substring(3, href.length);
 113    }
 114    var chars = ['#', '?', '&'];
 115    for (i in chars) {
 116      if (href.indexOf(chars[i]) > -1) {
 117        href = href.substr(0, href.indexOf(chars[i]));
 118      }
 119    }
 120    return href;
 121  };


Generated: Thu Mar 24 11:18:33 2011 Cross-referenced by PHPXref 0.7