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

Contents of /contributions/modules/admin_menu/admin_menu.js

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


Revision 1.27 - (show annotations) (download) (as text)
Wed Jul 22 20:32:13 2009 UTC (4 months ago) by sun
Branch: MAIN
CVS Tags: HEAD
Changes since 1.26: +3 -3 lines
File MIME type: text/javascript
#276751 by sun: Revamped rendering of menu additions/widgets.
1 /* $Id: admin_menu.js,v 1.26 2009/07/11 21:14:19 sun Exp $ */
2 (function($) {
3
4 Drupal.admin = Drupal.admin || {};
5 Drupal.admin.behaviors = Drupal.admin.behaviors || {};
6 Drupal.admin.hashes = Drupal.admin.hashes || {};
7
8 /**
9 * Core behavior for Administration menu.
10 *
11 * Test whether there is an administration menu is in the output and execute all
12 * registered behaviors.
13 */
14 Drupal.behaviors.adminMenu = {
15 attach: function (context, settings) {
16 // Initialize settings.
17 settings.admin_menu = $.extend({
18 suppress: false,
19 margin_top: false,
20 position_fixed: false,
21 tweak_modules: false,
22 tweak_tabs: false,
23 destination: '',
24 basePath: settings.basePath,
25 hash: 0,
26 replacements: {}
27 }, settings.admin_menu || {});
28 // Check whether administration menu should be suppressed.
29 if (settings.admin_menu.suppress) {
30 return;
31 }
32 var $adminMenu = $('#admin-menu:not(.admin-menu-processed)', context);
33 // Client-side caching; if administration menu is not in the output, it is
34 // fetched from the server and cached in the browser.
35 if (!$adminMenu.length && settings.admin_menu.hash) {
36 Drupal.admin.getCache(settings.admin_menu.hash, function (response) {
37 if (typeof response == 'string' && response.length > 0) {
38 $('body', context).prepend(response);
39 }
40 var $adminMenu = $('#admin-menu:not(.admin-menu-processed)', context);
41 // Apply our behaviors.
42 Drupal.admin.attachBehaviors(context, settings, $adminMenu);
43 });
44 }
45 // If the menu is in the output already, this means there is a new version.
46 else {
47 // Apply our behaviors.
48 Drupal.admin.attachBehaviors(context, settings, $adminMenu);
49 }
50 }
51 };
52
53 /**
54 * Collapse fieldsets on Modules page.
55 *
56 * For why multiple selectors see #111719.
57 */
58 Drupal.behaviors.adminMenuCollapseModules = {
59 attach: function (context, settings) {
60 if (settings.admin_menu.tweak_modules) {
61 $('#system-modules fieldset:not(.collapsed), #system-modules-1 fieldset:not(.collapsed)', context).addClass('collapsed');
62 }
63 }
64 };
65
66 /**
67 * Apply margin to page.
68 *
69 * Note that directly applying marginTop does not work in IE. To prevent
70 * flickering/jumping page content with client-side caching, this is a regular
71 * Drupal behavior.
72 */
73 Drupal.behaviors.adminMenuMarginTop = {
74 attach: function (context, settings) {
75 if (!settings.admin_menu.suppress && settings.admin_menu.margin_top) {
76 $('body:not(.admin-menu)', context).addClass('admin-menu');
77 }
78 }
79 };
80
81 /**
82 * Retrieve content from client-side cache.
83 *
84 * @param hash
85 * The md5 hash of the content to retrieve.
86 * @param onSuccess
87 * A callback function invoked when the cache request was successful.
88 */
89 Drupal.admin.getCache = function (hash, onSuccess) {
90 if (Drupal.admin.hashes.hash !== undefined) {
91 return Drupal.admin.hashes.hash;
92 }
93 $.ajax({
94 cache: true,
95 type: 'GET',
96 dataType: 'text', // Prevent auto-evaluation of response.
97 global: false, // Do not trigger global AJAX events.
98 url: Drupal.settings.admin_menu.basePath.replace(/admin_menu/, 'js/admin_menu/cache/' + hash),
99 success: onSuccess,
100 complete: function (XMLHttpRequest, status) {
101 Drupal.admin.hashes.hash = status;
102 }
103 });
104 }
105
106 /**
107 * @defgroup admin_behaviors Administration behaviors.
108 * @{
109 */
110
111 /**
112 * Attach administrative behaviors.
113 */
114 Drupal.admin.attachBehaviors = function (context, settings, $adminMenu) {
115 if ($adminMenu.length) {
116 $adminMenu.addClass('admin-menu-processed');
117 $.each(Drupal.admin.behaviors, function() {
118 this(context, settings, $adminMenu);
119 });
120 }
121 };
122
123 /**
124 * Apply 'position: fixed'.
125 */
126 Drupal.admin.behaviors.positionFixed = function (context, settings, $adminMenu) {
127 if (settings.admin_menu.position_fixed) {
128 $adminMenu.css('position', 'fixed');
129 }
130 };
131
132 /**
133 * Move page tabs into administration menu.
134 */
135 Drupal.admin.behaviors.pageTabs = function (context, settings, $adminMenu) {
136 if (settings.admin_menu.tweak_tabs) {
137 $('ul.tabs.primary li', context).addClass('admin-menu-tab').appendTo('#admin-menu-wrapper > ul');
138 $('ul.tabs.secondary', context).appendTo('#admin-menu-wrapper > ul > li.admin-menu-tab.active');
139 $('ul.tabs.primary', context).remove();
140 }
141 };
142
143 /**
144 * Perform dynamic replacements in cached menu.
145 */
146 Drupal.admin.behaviors.replacements = function (context, settings, $adminMenu) {
147 for (var item in settings.admin_menu.replacements) {
148 $(item, $adminMenu).html(settings.admin_menu.replacements[item]);
149 }
150 }
151
152 /**
153 * Inject destination query strings for current page.
154 */
155 Drupal.admin.behaviors.destination = function (context, settings, $adminMenu) {
156 if (settings.admin_menu.destination) {
157 $('a.admin-menu-destination', $adminMenu).each(function() {
158 this.search += (!this.search.length ? '?' : '&') + Drupal.settings.admin_menu.destination;
159 });
160 }
161 }
162
163 /**
164 * Apply JavaScript-based hovering behaviors.
165 *
166 * @todo This has to run last. If another script registers additional behaviors
167 * it will not run last.
168 */
169 Drupal.admin.behaviors.hover = function (context, settings, $adminMenu) {
170 // Hover emulation for IE 6.
171 if ($.browser.msie && parseInt(jQuery.browser.version) == 6) {
172 $('li', $adminMenu).hover(function() {
173 $(this).addClass('iehover');
174 }, function() {
175 $(this).removeClass('iehover');
176 });
177 }
178
179 // Delayed mouseout.
180 $('li', $adminMenu).hover(function() {
181 // Stop the timer.
182 clearTimeout(this.sfTimer);
183 // Display child lists.
184 $('> ul', this).css({left: 'auto', display: 'block'})
185 // Immediately hide nephew lists.
186 .parent().siblings('li').children('ul').css({left: '-999em', display: 'none'});
187 }, function() {
188 // Start the timer.
189 var uls = $('> ul', this);
190 this.sfTimer = setTimeout(function() {
191 uls.css({left: '-999em', display: 'none'});
192 }, 400);
193 });
194 };
195
196 /**
197 * @} End of "defgroup admin_behaviors".
198 */
199
200 })(jQuery);

  ViewVC Help
Powered by ViewVC 1.1.2