Skip to content
This repository
  • 3 commits
  • 2 files changed
  • 0 comments
  • 2 contributors
Aug 27, 2012
Adrian Föder [FEATURE] Add position class name to outmost div
This patch adds a class name telling the intended position
of the tip. This allows specific styling per position.

Current class name, configuration dependent, would be
  `floating-tip-wrapper`,
whereas the new class name with this patch would be
  `floating-tip-wrapper position-bottom`
for example.
c900868
Adrian Föder [TASK] Cleaned indendation character and empty lines
For being able to stick to a CGL and making commit
diffs easier to read, this sets every indendation to
tab instead of spaces and completely cleans empty lines
from tabs or spaces.
28e3246
Lorenzo Stanco Merge pull request #14 from wishbase/master
Augmented wrapper class name and CGL corrections
6278403
22  Source/FloatingTips.Dialog.js
@@ -18,22 +18,22 @@ provides: [FloatingTips.Dialog]
18 18
 FloatingTips.Dialog = new Class({
19 19
 
20 20
 	Extends: FloatingTips,
21  
-	
  21
+
22 22
 	options: {
23 23
 		showOn: 'click',
24 24
 		hideOn: 'never',
25 25
 		buttons: { },
26 26
 		buttonsClassName: ''
27 27
 	},
28  
-	
  28
+
29 29
 	initialize: function(element, text, options) {
30  
-		
  30
+
31 31
 		// Setup options
32 32
 		this.setOptions(options);
33  
-		
  33
+
34 34
 		// Store element reference
35 35
 		this.element = $(element);
36  
-		
  36
+
37 37
 		// Create buttons
38 38
 		var s = this;
39 39
 		var buttonsIndex = 0;
@@ -45,25 +45,25 @@ FloatingTips.Dialog = new Class({
45 45
 			button.set('text', buttonCaption).addEvent('click', buttonCallback.pass([ s.element, button, s ], s));
46 46
 			buttonsWrapper.adopt(button);
47 47
 		});
48  
-		
  48
+
49 49
 		// Create tip content
50 50
 		var contentText = new Element('p', { 'text': text });
51 51
 		var content = new Element('div').adopt(contentText, buttonsWrapper);
52 52
 		this.options.content = function() { return content; };
53 53
 		this.options.html = true;
54 54
 		this.options.html_adopt = true;
55  
-		
  55
+
56 56
 		// Call FloatingTips constructor
57 57
 		this.parent([this.element]);
58  
-		
  58
+
59 59
 	},
60  
-	
  60
+
61 61
 	popup: function() {
62 62
 		this.show(this.element);
63 63
 	},
64  
-	
  64
+
65 65
 	dismiss: function() {
66 66
 		this.hide(this.element);
67 67
 	}
68  
-	
  68
+
69 69
 });
106  Source/FloatingTips.js
@@ -90,7 +90,7 @@ var FloatingTips = new Class({
90 90
 		this.fireEvent('show', [tip, element]);
91 91
 		return this;
92 92
 	},
93  
-	
  93
+
94 94
 	hide: function(element) {
95 95
 		var tip = element.retrieve('floatingtip');
96 96
 		if (!tip) return this;
@@ -99,74 +99,78 @@ var FloatingTips = new Class({
99 99
 		this.fireEvent('hide', [tip, element]);
100 100
 		return this;
101 101
 	},
102  
-	
  102
+
103 103
 	toggle: function(element) {
104 104
 		if (element.retrieve('floatingtip_visible')) return this.hide(element);
105 105
 		else return this.show(element);
106 106
 	},
107  
-	
  107
+
108 108
 	_create: function(elem) {
109  
-		
  109
+
110 110
 		var o = this.options;
111 111
 		var oc = o.content;
112 112
 		var opos = o.position;
113  
-		
  113
+
114 114
 		if (oc == 'title') {
115 115
 			oc = 'floatingtitle';
116 116
 			if (!elem.get('floatingtitle')) elem.setProperty('floatingtitle', elem.get('title'));
117 117
 			elem.set('title', '');
118 118
 		}
119  
-		
  119
+
120 120
 		var cnt = (typeof(oc) == 'string' ? elem.get(oc) : oc(elem));
121 121
 		var cwr = new Element('div').addClass(o.className).setStyle('margin', 0);
122  
-		var tip = new Element('div').addClass(o.className + '-wrapper').setStyles({ 'margin': 0, 'padding': 0, 'z-index': cwr.getStyle('z-index') }).adopt(cwr);
123  
-		
124  
-		if (cnt) { 
  122
+		var tip = new Element('div')
  123
+			.addClass(o.className + '-wrapper')
  124
+			.addClass('position-' + this.options.position)
  125
+			.setStyles({ 'margin': 0, 'padding': 0, 'z-index': cwr.getStyle('z-index') })
  126
+			.adopt(cwr);
  127
+
  128
+		if (cnt) {
125 129
 			if (o.html) {
126 130
 				if (o.html_adopt) cwr.adopt(cnt);
127 131
 				else cwr.set('html', typeof(cnt) == 'string' ? cnt : cnt.get('html'));
128 132
 			} else {
129  
-				cwr.set('text', cnt); 
  133
+				cwr.set('text', cnt);
130 134
 			}
131  
-		} else { 
  135
+		} else {
132 136
 			return null;
133 137
 		}
134  
-		
  138
+
135 139
 		var body = document.id(document.body);
136 140
 		tip.setStyles({ 'position': (o.fixed ? 'fixed' : 'absolute'), 'opacity': 0, 'top': 0, 'left': 0 }).inject(body);
137  
-		
  141
+
138 142
 		if (o.balloon && !Browser.ie6) {
139  
-			
  143
+
140 144
 			var trg = new Element('div').addClass(o.className + '-triangle').setStyles({ 'margin': 0, 'padding': 0 });
141 145
 			var trgSt = { 'border-color': cwr.getStyle('background-color'), 'border-width': o.arrowSize, 'border-style': 'solid','width': 0, 'height': 0 };
142  
-			
  146
+
143 147
 			switch (opos) {
144  
-				case 'inside': 
  148
+				case 'inside':
145 149
 				case 'top'   : trgSt['border-bottom-width'] = 0; break;
146 150
 				case 'right' : trgSt['border-left-width'  ] = 0; trgSt['float'] = 'left'; cwr.setStyle('margin-left', o.arrowSize); break;
147 151
 				case 'bottom': trgSt['border-top-width'   ] = 0; break;
148  
-				case 'left'  : trgSt['border-right-width' ] = 0; 
  152
+				case 'left'  : trgSt['border-right-width' ] = 0;
149 153
 					if (Browser.ie7) { trgSt['position'] = 'absolute'; trgSt['right'] = 0; } else { trgSt['float'] = 'right'; }
150 154
 					cwr.setStyle('margin-right', o.arrowSize); break;
151 155
 			}
152  
-			
  156
+
153 157
 			switch (opos) {
154  
-				case 'inside': case 'top': case 'bottom': 
  158
+				case 'inside': case 'top': case 'bottom':
155 159
 					trgSt['border-left-color'] = trgSt['border-right-color'] = 'transparent';
156 160
 					trgSt['margin-left'] = o.center ? tip.getSize().x / 2 - o.arrowSize : o.arrowOffset; break;
157  
-				case 'left': case 'right': 
  161
+				case 'left': case 'right':
158 162
 					trgSt['border-top-color'] = trgSt['border-bottom-color'] = 'transparent';
159 163
 					trgSt['margin-top'] = o.center ?  tip.getSize().y / 2 - o.arrowSize : o.arrowOffset; break;
160 164
 			}
161  
-			
  165
+
162 166
 			trg.setStyles(trgSt).inject(tip, (opos == 'top' || opos == 'inside') ? 'bottom' : 'top');
163  
-			
  167
+
164 168
 		}
165  
-		
  169
+
166 170
 		var tipSz = tip.getSize(), trgC = elem.getCoordinates();
167 171
 		var offsetOption = ('function' === typeof(o.offset) ? Object.merge({ x: 0, y: 0 }, o.offset(elem)) : o.offset);
168 172
 		var pos = { x: trgC.left + offsetOption.x, y: trgC.top + offsetOption.y };
169  
-		
  173
+
170 174
 		if (opos == 'inside') {
171 175
 			tip.setStyles({ 'width': tip.getStyle('width'), 'height': tip.getStyle('height') });
172 176
 			elem.setStyle('position', 'relative').adopt(tip);
@@ -179,7 +183,7 @@ var FloatingTips = new Class({
179 183
 				case 'left'  :  pos.x -= tipSz.x + o.distance; break;
180 184
 			}
181 185
 		}
182  
-		
  186
+
183 187
 		if (o.center) {
184 188
 			switch (opos) {
185 189
 				case 'top' : case 'bottom': pos.x += (trgC.width / 2 - tipSz.x / 2); break;
@@ -189,85 +193,85 @@ var FloatingTips = new Class({
189 193
 					pos.y += (trgC.height / 2 - tipSz.y / 2); break;
190 194
 			}
191 195
 		}
192  
-		
  196
+
193 197
 		tip.set('morph', o.fx).store('position', pos);
194 198
 		tip.setStyles({ 'top': pos.y, 'left': pos.x });
195  
-		
  199
+
196 200
 		return tip;
197  
-		
  201
+
198 202
 	},
199  
-	
  203
+
200 204
 	_animate: function(tip, d) {
201  
-		
  205
+
202 206
 		clearTimeout(tip.retrieve('timeout'));
203  
-		tip.store('timeout', (function(t) { 
204  
-			
  207
+		tip.store('timeout', (function(t) {
  208
+
205 209
 			var o = this.options, din = (d == 'in');
206 210
 			var m = { 'opacity': din ? 1 : 0 };
207  
-			
  211
+
208 212
 			if ((o.motionOnShow && din) || (o.motionOnHide && !din)) {
209 213
 				var pos = t.retrieve('position');
210 214
 				if (!pos) return;
211 215
 				switch (o.position) {
212  
-					case 'inside': 
  216
+					case 'inside':
213 217
 					case 'top'   : m['top']  = din ? [pos.y - o.motion, pos.y] : pos.y - o.motion; break;
214 218
 					case 'right' : m['left'] = din ? [pos.x + o.motion, pos.x] : pos.x + o.motion; break;
215 219
 					case 'bottom': m['top']  = din ? [pos.y + o.motion, pos.y] : pos.y + o.motion; break;
216 220
 					case 'left'  : m['left'] = din ? [pos.x - o.motion, pos.x] : pos.x - o.motion; break;
217 221
 				}
218 222
 			}
219  
-			
  223
+
220 224
 			t.morph(m);
221  
-			if (!din) t.get('morph').chain(function() { this.dispose(); }.bind(t)); 
222  
-			
  225
+			if (!din) t.get('morph').chain(function() { this.dispose(); }.bind(t));
  226
+
223 227
 		}).delay((d == 'in') ? this.options.showDelay : this.options.hideDelay, this, tip));
224  
-		
  228
+
225 229
 		return this;
226  
-		
  230
+
227 231
 	}
228 232
 
229 233
 });
230 234
 
231 235
 Elements.implement({
232  
-	
  236
+
233 237
 	floatingTips: function(options) {
234 238
 		new FloatingTips(this, options);
235 239
 		return this;
236 240
 	}
237  
-	
  241
+
238 242
 });
239 243
 
240 244
 Element.implement({
241  
-	
  245
+
242 246
 	floatingTips: function(options) {
243 247
 		new FloatingTips($$(this), options);
244 248
 		return this;
245 249
 	},
246  
-	
  250
+
247 251
 	floatingTipsShow: function() {
248 252
 		var tip = this.retrieve('floatingtip_object');
249 253
 		if (tip) tip.show(this);
250 254
 		return this;
251 255
 	},
252  
-	
  256
+
253 257
 	floatingTipsHide: function() {
254 258
 		var tip = this.retrieve('floatingtip_object');
255 259
 		if (tip) tip.hide(this);
256 260
 		return this;
257 261
 	},
258  
-	
  262
+
259 263
 	floatingTipsToggle: function() {
260 264
 		var tip = this.retrieve('floatingtip_object');
261 265
 		if (tip) tip.toggle(this);
262 266
 		return this;
263 267
 	}
264  
-	
  268
+
265 269
 });
266 270
 
267 271
 Element.Properties.floatingTips = {
268  
- 
269  
-    get: function(){
270  
-        return this.retrieve('floatingtip_object');
271  
-    }
272  
- 
  272
+
  273
+	get: function(){
  274
+		return this.retrieve('floatingtip_object');
  275
+	}
  276
+
273 277
 };

No commit comments for this range

Something went wrong with that request. Please try again.