Permalink
Browse files

Merge pull request #14 from wishbase/master

Augmented wrapper class name and CGL corrections
  • Loading branch information...
2 parents 2fa444c + 28e3246 commit 62784038869234e5e14af4465f33a2bf770f9ba1 @lorenzos committed Aug 27, 2012
Showing with 66 additions and 62 deletions.
  1. +11 −11 Source/FloatingTips.Dialog.js
  2. +55 −51 Source/FloatingTips.js
@@ -18,22 +18,22 @@ provides: [FloatingTips.Dialog]
FloatingTips.Dialog = new Class({
Extends: FloatingTips,
-
+
options: {
showOn: 'click',
hideOn: 'never',
buttons: { },
buttonsClassName: ''
},
-
+
initialize: function(element, text, options) {
-
+
// Setup options
this.setOptions(options);
-
+
// Store element reference
this.element = $(element);
-
+
// Create buttons
var s = this;
var buttonsIndex = 0;
@@ -45,25 +45,25 @@ FloatingTips.Dialog = new Class({
button.set('text', buttonCaption).addEvent('click', buttonCallback.pass([ s.element, button, s ], s));
buttonsWrapper.adopt(button);
});
-
+
// Create tip content
var contentText = new Element('p', { 'text': text });
var content = new Element('div').adopt(contentText, buttonsWrapper);
this.options.content = function() { return content; };
this.options.html = true;
this.options.html_adopt = true;
-
+
// Call FloatingTips constructor
this.parent([this.element]);
-
+
},
-
+
popup: function() {
this.show(this.element);
},
-
+
dismiss: function() {
this.hide(this.element);
}
-
+
});
View
@@ -90,7 +90,7 @@ var FloatingTips = new Class({
this.fireEvent('show', [tip, element]);
return this;
},
-
+
hide: function(element) {
var tip = element.retrieve('floatingtip');
if (!tip) return this;
@@ -99,74 +99,78 @@ var FloatingTips = new Class({
this.fireEvent('hide', [tip, element]);
return this;
},
-
+
toggle: function(element) {
if (element.retrieve('floatingtip_visible')) return this.hide(element);
else return this.show(element);
},
-
+
_create: function(elem) {
-
+
var o = this.options;
var oc = o.content;
var opos = o.position;
-
+
if (oc == 'title') {
oc = 'floatingtitle';
if (!elem.get('floatingtitle')) elem.setProperty('floatingtitle', elem.get('title'));
elem.set('title', '');
}
-
+
var cnt = (typeof(oc) == 'string' ? elem.get(oc) : oc(elem));
var cwr = new Element('div').addClass(o.className).setStyle('margin', 0);
- var tip = new Element('div').addClass(o.className + '-wrapper').setStyles({ 'margin': 0, 'padding': 0, 'z-index': cwr.getStyle('z-index') }).adopt(cwr);
-
- if (cnt) {
+ var tip = new Element('div')
+ .addClass(o.className + '-wrapper')
+ .addClass('position-' + this.options.position)
+ .setStyles({ 'margin': 0, 'padding': 0, 'z-index': cwr.getStyle('z-index') })
+ .adopt(cwr);
+
+ if (cnt) {
if (o.html) {
if (o.html_adopt) cwr.adopt(cnt);
else cwr.set('html', typeof(cnt) == 'string' ? cnt : cnt.get('html'));
} else {
- cwr.set('text', cnt);
+ cwr.set('text', cnt);
}
- } else {
+ } else {
return null;
}
-
+
var body = document.id(document.body);
tip.setStyles({ 'position': (o.fixed ? 'fixed' : 'absolute'), 'opacity': 0, 'top': 0, 'left': 0 }).inject(body);
-
+
if (o.balloon && !Browser.ie6) {
-
+
var trg = new Element('div').addClass(o.className + '-triangle').setStyles({ 'margin': 0, 'padding': 0 });
var trgSt = { 'border-color': cwr.getStyle('background-color'), 'border-width': o.arrowSize, 'border-style': 'solid','width': 0, 'height': 0 };
-
+
switch (opos) {
- case 'inside':
+ case 'inside':
case 'top' : trgSt['border-bottom-width'] = 0; break;
case 'right' : trgSt['border-left-width' ] = 0; trgSt['float'] = 'left'; cwr.setStyle('margin-left', o.arrowSize); break;
case 'bottom': trgSt['border-top-width' ] = 0; break;
- case 'left' : trgSt['border-right-width' ] = 0;
+ case 'left' : trgSt['border-right-width' ] = 0;
if (Browser.ie7) { trgSt['position'] = 'absolute'; trgSt['right'] = 0; } else { trgSt['float'] = 'right'; }
cwr.setStyle('margin-right', o.arrowSize); break;
}
-
+
switch (opos) {
- case 'inside': case 'top': case 'bottom':
+ case 'inside': case 'top': case 'bottom':
trgSt['border-left-color'] = trgSt['border-right-color'] = 'transparent';
trgSt['margin-left'] = o.center ? tip.getSize().x / 2 - o.arrowSize : o.arrowOffset; break;
- case 'left': case 'right':
+ case 'left': case 'right':
trgSt['border-top-color'] = trgSt['border-bottom-color'] = 'transparent';
trgSt['margin-top'] = o.center ? tip.getSize().y / 2 - o.arrowSize : o.arrowOffset; break;
}
-
+
trg.setStyles(trgSt).inject(tip, (opos == 'top' || opos == 'inside') ? 'bottom' : 'top');
-
+
}
-
+
var tipSz = tip.getSize(), trgC = elem.getCoordinates();
var offsetOption = ('function' === typeof(o.offset) ? Object.merge({ x: 0, y: 0 }, o.offset(elem)) : o.offset);
var pos = { x: trgC.left + offsetOption.x, y: trgC.top + offsetOption.y };
-
+
if (opos == 'inside') {
tip.setStyles({ 'width': tip.getStyle('width'), 'height': tip.getStyle('height') });
elem.setStyle('position', 'relative').adopt(tip);
@@ -179,7 +183,7 @@ var FloatingTips = new Class({
case 'left' : pos.x -= tipSz.x + o.distance; break;
}
}
-
+
if (o.center) {
switch (opos) {
case 'top' : case 'bottom': pos.x += (trgC.width / 2 - tipSz.x / 2); break;
@@ -189,85 +193,85 @@ var FloatingTips = new Class({
pos.y += (trgC.height / 2 - tipSz.y / 2); break;
}
}
-
+
tip.set('morph', o.fx).store('position', pos);
tip.setStyles({ 'top': pos.y, 'left': pos.x });
-
+
return tip;
-
+
},
-
+
_animate: function(tip, d) {
-
+
clearTimeout(tip.retrieve('timeout'));
- tip.store('timeout', (function(t) {
-
+ tip.store('timeout', (function(t) {
+
var o = this.options, din = (d == 'in');
var m = { 'opacity': din ? 1 : 0 };
-
+
if ((o.motionOnShow && din) || (o.motionOnHide && !din)) {
var pos = t.retrieve('position');
if (!pos) return;
switch (o.position) {
- case 'inside':
+ case 'inside':
case 'top' : m['top'] = din ? [pos.y - o.motion, pos.y] : pos.y - o.motion; break;
case 'right' : m['left'] = din ? [pos.x + o.motion, pos.x] : pos.x + o.motion; break;
case 'bottom': m['top'] = din ? [pos.y + o.motion, pos.y] : pos.y + o.motion; break;
case 'left' : m['left'] = din ? [pos.x - o.motion, pos.x] : pos.x - o.motion; break;
}
}
-
+
t.morph(m);
- if (!din) t.get('morph').chain(function() { this.dispose(); }.bind(t));
-
+ if (!din) t.get('morph').chain(function() { this.dispose(); }.bind(t));
+
}).delay((d == 'in') ? this.options.showDelay : this.options.hideDelay, this, tip));
-
+
return this;
-
+
}
});
Elements.implement({
-
+
floatingTips: function(options) {
new FloatingTips(this, options);
return this;
}
-
+
});
Element.implement({
-
+
floatingTips: function(options) {
new FloatingTips($$(this), options);
return this;
},
-
+
floatingTipsShow: function() {
var tip = this.retrieve('floatingtip_object');
if (tip) tip.show(this);
return this;
},
-
+
floatingTipsHide: function() {
var tip = this.retrieve('floatingtip_object');
if (tip) tip.hide(this);
return this;
},
-
+
floatingTipsToggle: function() {
var tip = this.retrieve('floatingtip_object');
if (tip) tip.toggle(this);
return this;
}
-
+
});
Element.Properties.floatingTips = {
-
- get: function(){
- return this.retrieve('floatingtip_object');
- }
-
+
+ get: function(){
+ return this.retrieve('floatingtip_object');
+ }
+
};

0 comments on commit 6278403

Please sign in to comment.