initially import ZendFramework-1.9.5 into repository
[cacert-mgr.git] / external / ZendFramework-1.9.5 / externals / dojo / demos / faces / src / block.js
1 dojo.provide("demos.faces.src.block");
2
3 (function(){
4
5 // a simple shallow alias
6 var d = dojo;
7
8 d.declare("dojo._Blocker", null, {
9 // summary: The blocker instance used by dojo.block to overlay a node
10 //
11 // duration: Integer
12 // The duration of the fadeIn/fadeOut for the overlay
13 duration: 400,
14
15 // opacity: Float
16 // The final opacity of the overlay. A number from 0 to 1
17 opacity: 0.6,
18
19 // backgroundColor: String
20 // The color to set the overlay
21 backgroundColor: "#fff",
22
23 // zIndex: Integer
24 // The z-index to apply to the overlay, should you need to adjust for higher elements
25 zIndex: 999,
26
27 constructor: function(node, args){
28 // the constructor function is always called by dojo.declare.
29 // first, mixin any passed args into this instance to override defaults, or hook in custom stuff
30 d.mixin(this, args);
31 // in-case someone passed node:"something", force this.node to be the first param
32 this.node = d.byId(node);
33 // create a node for our overlay.
34 this.overlay = d.doc.createElement('div');
35
36 // do some chained magic nonsense
37 d.query(this.overlay)
38 // make it the last-child of <body>
39 .place(d.body(),"last")
40 // give it a common class
41 .addClass("dojoBlockOverlay")
42 // mixin our styles. I'd prefer to do this purly in CSS, but that would
43 // require external css somehow, and is an extra file. ;)
44 .style({
45 backgroundColor: this.backgroundColor,
46 position: "absolute",
47 zIndex: this.zIndex,
48 display: "none",
49 opacity: this.opacity
50 });
51 },
52
53 _position: function(){
54 var pos = d._abs(this.node, true);
55 // adjust for margins/padding: (edge case, may only be this demo's styles)
56 pos = dojo.mixin(dojo.marginBox(this.node), {
57 l: pos.x, t: pos.y
58 });
59
60 dojo.style(this.overlay,{
61 position:"absolute",
62 left: pos.l + "px",
63 width: pos.w + "px",
64 height: pos.h + "px",
65 top: pos.t + "px"
66 });
67 },
68
69 show: function(){
70 // summary: Show this overlay
71
72 if(this._showing){ return; }
73 var ov = this.overlay;
74
75 this._position();
76 if(this.keepPosition){
77 this.positionConnect = dojo.connect(window, "onresize", this, "_position");
78 }
79
80 d.style(ov, { opacity:0, display:"block" });
81 d._fade({ node:ov, end: this.opacity, duration: this.duration }).play();
82 this._showing = true;
83 },
84
85 hide: function(){
86 // summary: Hide this overlay
87
88 d.fadeOut({
89 node: this.overlay,
90 duration: this.duration,
91 // when the fadeout is done, set the overlay to display:none
92 onEnd: d.hitch(this, function(){
93 d.style(this.overlay, "display", "none");
94 if(this.keepPosition){
95 dojo.disconnect(this.positionConnect);
96 }
97 this._showing = false;
98 })
99 }).play();
100 }
101
102 });
103
104 // Generates a unique id for a node
105 var id_count = 0;
106 var _uniqueId = function(){
107 var id_base = "dojo_blocked",
108 id;
109 do{
110 id = id_base + "_" + (++id_count);
111 }while(d.byId(id));
112 return id;
113 }
114
115 var blockers = {}; // hash of all blockers
116 d.mixin(d, {
117 block: function(/* String|DomNode */node, /* dojo.block._blockArgs */args){
118 // summary: Overlay the passed node to prevent further input, creates an
119 // instance of dojo._Blocker attached to this node byId, or generates a
120 // unique id if the node doesn't have one already.
121 //
122 // node: The node to overlay
123 // args: An object hash of configuration options. See dojo._Blocker for
124 // a list of parameters mixed in.
125 //
126 // returns: The dojo._Blocker instance created for the passed node for convenience.
127 // You can call var thing = dojo.block("someNode"); thing.hide(); or simply call
128 // dojo.unblock("someNode"), whichever you prefer.
129 var n = d.byId(node);
130 var id = d.attr(n, "id");
131 if(!id){
132 id = _uniqueId();
133 d.attr(n, "id", id);
134 }
135 if(!blockers[id]){
136 blockers[id] = new d._Blocker(node, args);
137 }
138 blockers[id].show();
139 return blockers[id]; // dojo._Blocker
140 },
141
142 unblock: function(node, args){
143 // summary: Unblock the passed node
144 var id = d.attr(node, "id");
145 if(id && blockers[id]){
146 blockers[id].hide();
147 }
148 }
149
150 });
151
152 d.extend(d.NodeList, {
153 block: d.NodeList._adaptAsForEach("block"),
154 unblock: d.NodeList._adaptAsForEach("unblock")
155 });
156
157 })();