/[drupal]/contributions/modules/ui/javascript/ui.shadow.js
ViewVC logotype

Diff of /contributions/modules/ui/javascript/ui.shadow.js

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

revision 1.1, Sun Sep 2 20:21:42 2007 UTC revision 1.2, Mon Sep 17 03:42:34 2007 UTC
# Line 3  Line 3 
3          //If the UI scope is not available, add it          //If the UI scope is not available, add it
4          $.ui = $.ui || {};          $.ui = $.ui || {};
5    
6            //Make nodes selectable by expression
7            $.extend($.expr[':'], { shadowed: "(' '+a.className+' ').indexOf(' ui-shadowed ')" });
8    
9            $.fn.shadowEnable = function() { if($(this[0]).next().is(".ui-shadow")) $(this[0]).next().show(); }
10            $.fn.shadowDisable = function() { if($(this[0]).next().is(".ui-shadow")) $(this[0]).next().hide(); }
11    
12          $.fn.shadow = function(options) {          $.fn.shadow = function(options) {
13    
14                  options = options || {};                  options = options || {};
15                  options.offset = options.offset ? Math.round(options.offset/2) : 0;                  options.offset = options.offset ? options.offset : 0;
16                    options.opacity = options.opacity ? options.opacity : 0.2;
17    
18                  return this.each(function() {                  return this.each(function() {
19    
20                          var cur = $(this);                          var cur = $(this);
21    
22                          //Wrap the original element with a shadow element                          //Create a shadow element
23                          cur.wrap("<div class='ui-shadow'></div>");                          var shadow = $("<div class='ui-shadow'></div>"); cur.after(shadow);
24                          var shadow = $(this.parentNode);  
25                            //Figure the base height and width
26                            var baseWidth = cur.outerWidth();
27                            var baseHeight = cur.outerHeight();
28    
29                            //get the offset
30                            var position = cur.position();
31    
32                          //Append smooth corners                          //Append smooth corners
33                          $('<div class="ui-shadow-ne"></div>').css("width", 6+(options.offset*2)).appendTo(shadow);                          $('<div class="ui-shadow-color ui-shadow-layer-1"></div>').css({ opacity: options.opacity-0.05, left: 5+options.offset, top: 5+options.offset, width: baseWidth+1, height: baseHeight+1 }).appendTo(shadow);
34                          $('<div class="ui-shadow-sw"></div>').css("height", 6+(options.offset*2)).appendTo(shadow);                          $('<div class="ui-shadow-color ui-shadow-layer-2"></div>').css({ opacity: options.opacity-0.1, left: 7+options.offset, top: 7+options.offset, width: baseWidth, height: baseHeight-3 }).appendTo(shadow);
35                            $('<div class="ui-shadow-color ui-shadow-layer-3"></div>').css({ opacity: options.opacity-0.1, left: 7+options.offset, top: 7+options.offset, width: baseWidth-3, height: baseHeight }).appendTo(shadow);
36                            $('<div class="ui-shadow-color ui-shadow-layer-4"></div>').css({ opacity: options.opacity, left: 6+options.offset, top: 6+options.offset, width: baseWidth-1, height: baseHeight-1 }).appendTo(shadow);
37    
38                            //If we have a color, use it
39                            if(options.color)
40                                    $("div.ui-shadow-color", shadow).css("background-color", options.color);
41    
42                            //Determine the stack order (attention: the zIndex will get one higher!)
43                            if(!cur.css("zIndex") || cur.css("zIndex") == "auto") {
44                                    var stack = 0;
45                                    cur.css("position", (cur.css("position") == "static" ? "relative" : cur.css("position"))).css("z-index", "1");
46                            } else {
47                                    var stack = parseInt(cur.css("zIndex"));
48                                    cur.css("zIndex", stack+1);
49                            }
50    
51                          //Copy the original z-index and position to the clone                          //Copy the original z-index and position to the clone
52                            //alert(shadow); If you insert this alert, opera will time correctly!!
53                          shadow.css({                          shadow.css({
54                                  position: cur.css("position") != "static" ? cur.css("position") : "relative",                                  position: "absolute",
55                                  zIndex: cur.css("zIndex"),                                  zIndex: stack,
56                                  left: cur.css("left"),                                  left: position.left,
57                                  top: cur.css("top"),                                  top: position.top,
58                                  right: cur.css("right"),                                  width: baseWidth,
59                                  bottom: cur.css("bottom"),                                  height: baseHeight,
                                 width: cur.outerWidth()+options.offset,  
                                 height: cur.outerHeight()+options.offset,  
60                                  marginLeft: cur.css("marginLeft"),                                  marginLeft: cur.css("marginLeft"),
61                                  marginRight: cur.css("marginRight"),                                  marginRight: cur.css("marginRight"),
62                                  marginBottom: cur.css("marginBottom"),                                  marginBottom: cur.css("marginBottom"),
63                                  marginTop: cur.css("marginTop")                                  marginTop: cur.css("marginTop")
64                          });                          });
65    
66                          //Remove these values from the inner node  
67                          cur.css({                          function rearrangeShadow(el,sh) {
68                                  position: "relative",                                  var $el = $(el);
69                                  left: -6-options.offset,                                  $(sh).css($el.position());
70                                  top: -6-options.offset,                                  $(sh).children().css({ height: $el.outerHeight()+"px", width: $el.outerWidth()+"px" });
71                                  right: 0,                          }
72                                  bottom: 0,  
73                                  marginLeft: 0,                          if($.browser.msie) {
74                                  marginRight: 0,                                  //Add dynamic css expressions
75                                  marginBottom: 0,                                  shadow[0].style.setExpression("left","parseInt(jQuery(this.previousSibling).css('left'))+'px' || jQuery(this.previousSibling).position().left");
76                                  marginTop: 0                                  shadow[0].style.setExpression("top","parseInt(jQuery(this.previousSibling).css('top'))+'px' || jQuery(this.previousSibling).position().top");
77                          });                          } else {
78                                    //Bind events for good browsers
79                                    this.addEventListener("DOMAttrModified",function() { rearrangeShadow(this,shadow); },false);
80                            }
81    
82    
83                  });                  });
84          };          };

Legend:
Removed from v.1.1  
changed lines
  Added in v.1.2

  ViewVC Help
Powered by ViewVC 1.1.2