/[drupal]/contributions/modules/activemenu/activemenu.js
ViewVC logotype

Contents of /contributions/modules/activemenu/activemenu.js

Parent Directory Parent Directory | Revision Log Revision Log | View Revision Graph Revision Graph


Revision 1.1 - (show annotations) (download) (as text)
Fri Mar 28 16:36:44 2008 UTC (19 months, 4 weeks ago) by nedjo
Branch: MAIN
CVS Tags: HEAD
Branch point for: DRUPAL-6--2
File MIME type: text/javascript
Drupal 6 update of activemenu module. Moving out of jstools.
1 // $Id: activemenu.js,v 1.29 2008/03/26 23:51:45 nedjo Exp $
2
3 Drupal.behaviors.activeMenu = function (context) {
4 // The elements supported. Each can designate a different uri.
5 var menus = Drupal.settings.activemenu;
6 for (var menu in menus) {
7 $(menu + ' li.expanded:not(.activemenu-processed)').each(function () {
8 Drupal.preventSelect(this);
9 $(this)
10 .click(function (e) {
11 Drupal.activemenuToggle(this, e);
12 })
13 .addClass('activemenu-processed')
14 });
15 $(menu + ' li.collapsed:not(.activemenu-processed)').each(function() {
16 if ($(this).children('ul').length > 0) {
17 return;
18 }
19 var path = Drupal.getPath($('a:first', this).attr('href'));
20 var url = Drupal.url(menus[menu]);
21 var elt = this;
22 Drupal.preventSelect(this);
23 $(this)
24 .click(function (e) {
25 var offset = Drupal.mousePosition(e).x - Drupal.absolutePosition(this).x;
26 var padding = $(this).css('padding-left');
27 // Determine if we are in the selection area.
28 if (offset < (padding.slice(-2) == "px" ? parseInt(padding) : 18)) {
29 $(elt).addClass('loading');
30 $.ajax({
31 type: 'POST',
32 url: url,
33 data: {path: path},
34 dataType: 'json',
35 success: function (data) {
36 $(elt).removeClass('loading');
37 if ($(elt).children('ul').length > 0) {
38 return;
39 }
40 var dummy = document.createElement('div');
41 $(dummy).html(data.content);
42 $(elt)
43 .append($(dummy).find('li:has(> a[href*='+ path +'])').find('> ul'))
44 .removeClass('collapsed')
45 .addClass('expanded')
46 .unbind('click')
47 .click(function (e) {
48 Drupal.activemenuToggle(this, e);
49 })
50 .find('ul:first')
51 .slideDown(200);
52 Drupal.attachBehaviors(elt);
53 },
54 error: function (xmlhttp) {
55 if(xmlhttp.status >= 400)
56 alert('An HTTP error '+ xmlhttp.status +' occured.\n' + url);
57 }
58 });
59 return false;
60 }
61 })
62 .addClass('activemenu-processed');
63 });
64 }
65 };
66
67 Drupal.activemenuToggle = function (menu, e) {
68 // Only toggle if this is the element that was clicked.
69 // Otherwise, a parent li element might be toggled too.
70 // Don't animate multiple times.
71 if (menu == e.target && !$(menu).is('.animating')) {
72 if ($(menu).is('.collapsed')) {
73 $(menu)
74 .addClass('animating')
75 .removeClass('collapsed')
76 .addClass('expanded')
77 .find('ul:first')
78 .slideDown(200, function(){
79 $(this).parents('.animating').removeClass('animating')
80 });
81 }
82 else {
83 $(menu)
84 .addClass('animating')
85 .removeClass('expanded')
86 .addClass('collapsed')
87 .find('ul:first')
88 .slideUp(200, function(){
89 $(this).parents('.animating').removeClass('animating')
90 });
91 }
92 }
93 };

  ViewVC Help
Powered by ViewVC 1.1.2