/[drupal]/contributions/modules/user_display/user_display_links.js
ViewVC logotype

Contents of /contributions/modules/user_display/user_display_links.js

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


Revision 1.1 - (show annotations) (download) (as text)
Sat Jul 19 23:12:33 2008 UTC (16 months, 1 week ago) by sun
Branch: MAIN
CVS Tags: HEAD
Branch point for: DRUPAL-5
File MIME type: text/javascript
Initial commit of User Display API.
1 // $Id$
2
3 /**
4 * Cache for already queried users.
5 */
6 Drupal.userDisplayLinksStack = [];
7
8 /**
9 * Current hovered DOM element.
10 */
11 Drupal.userDisplayLinksHoverNode = null;
12
13 /**
14 * Attach user menu to user images.
15 */
16 Drupal.userDisplayLinksAttach = function() {
17 // Setup synchronous requests for user menus.
18 $.ajaxSetup({
19 url: '/js/user_display_links/links',
20 async: false
21 });
22 $('.user-links:not(.user-links-processed)').each(function() {
23 $(this)
24 .addClass('user-links-processed')
25 .click(function() {
26 Drupal.userDisplayLinksLoad(this);
27 Drupal.userDisplayLinksHoverNode = this;
28 Drupal.userDisplayLinksHover(this, true);
29 return false;
30 }
31 )
32 // Avoid mouseover clashes by removing title attributes from images and
33 // links.
34 .find('img, a').attr('title', '');
35 });
36 }
37
38 /**
39 * Query user menu for a given user.
40 */
41 Drupal.userDisplayLinksLoad = function(node) {
42 var uid = node.className.replace(/.*user-(\d+).*/g, '$1');
43 if (Drupal.userDisplayLinksStack[uid]) {
44 return;
45 }
46 $('body').append('<div id="user-links-'+ uid +'" class="user-links-menu"></div>');
47 $.getJSON('/js/user_display_links/links/'+ uid, function(response) {
48 Drupal.userDisplayLinksStack[uid] = response.data;
49 $('#user-links-'+ uid).html(response.data).hide()
50 .hover(function() {
51 },
52 function() {
53 Drupal.userDisplayLinksHover(node, false);
54 Drupal.userDisplayLinksHoverNode = null;
55 }
56 );
57 });
58 }
59
60 /**
61 * Ensure current hovered DOM element; apply UI effects.
62 */
63 Drupal.userDisplayLinksHover = function(node, hover) {
64 if (Drupal.userDisplayLinksHoverNode != node) {
65 return;
66 }
67 var uid = node.className.replace(/.*user-(\d+).*/g, '$1');
68 var $menu = $('#user-links-'+ uid);
69 if (hover) {
70 var $node = $(node);
71 var offset = $node.offset();
72 var left = offset.left + (($node.width() - $menu.width()) / 2);
73 var top = offset.top + (($node.height() - $menu.height()) / 2);
74 $menu.css({position: 'absolute', left: left, top: top}).fadeIn('fast');
75 }
76 else {
77 $menu.fadeOut('fast');
78 }
79 }
80
81 if (Drupal.jsEnabled) {
82 $(document).ready(Drupal.userDisplayLinksAttach);
83 }

  ViewVC Help
Powered by ViewVC 1.1.2