Permalink
Browse files

Now using prototyping for better performance

  • Loading branch information...
1 parent b448e53 commit 5f587125102e11fdbec895b9b5382d1ce58000e5 Brian Cray committed May 20, 2011
Showing with 91 additions and 91 deletions.
  1. +2 −2 tooltipsy.min.js
  2. +89 −89 tooltipsy.source.js
View
Oops, something went wrong.
View
@@ -12,111 +12,111 @@
*/
(function($){
- $.tooltipsy = function(el, options){
- var base = this;
+ $.tooltipsy = function (el, options) {
+ this.options = options;
+ this.$el = $(el);
+ this.el = el;
+ this.random = parseInt(Math.random()*10000);
+ this.ready = false;
+ this.shown = false;
+ this.width = 0;
+ this.height = 0;
- base.$el = $(el);
- base.el = el;
- base.random = parseInt(Math.random()*10000);
- base.ready = false;
- base.shown = false;
- base.width = 0;
- base.height = 0;
+ this.$el.data("tooltipsy", this);
+ this.init();
+ };
- base.$el.data("tooltipsy", base);
+ $.tooltipsy.prototype.init = function () {
+ var base = this;
- base.init = function() {
- base.settings = $.extend({},$.tooltipsy.defaults, options);
+ base.settings = $.extend({}, base.defaults, base.options);
- if (typeof base.settings.content === 'function') {
- base.readify();
+ if (typeof base.settings.content === 'function') {
+ base.readify();
+ }
+
+ base.$el.bind('mouseenter', function (e) {
+ if (base.ready === false) {
+ base.readify();
}
-
- base.$el.bind('mouseenter', function (e) {
- if (base.ready === false) {
- base.readify();
- }
- if (base.shown === false) {
- if ((function (o) {
- var s = 0, k;
- for (k in o) {
- if (o.hasOwnProperty(k)) {
- s++;
- }
+ if (base.shown === false) {
+ if ((function (o) {
+ var s = 0, k;
+ for (k in o) {
+ if (o.hasOwnProperty(k)) {
+ s++;
}
- return s;
- })(base.settings.css) > 0) {
- base.$tip.css(base.settings.css);
}
- base.width = base.$tipsy.outerWidth();
- base.height = base.$tipsy.outerHeight();
+ return s;
+ })(base.settings.css) > 0) {
+ base.$tip.css(base.settings.css);
}
+ base.width = base.$tipsy.outerWidth();
+ base.height = base.$tipsy.outerHeight();
+ }
- if (base.settings.alignTo == 'cursor') {
- var tip_position = [e.pageX + base.settings.offset[0], e.pageY + base.settings.offset[1]];
- if(tip_position[0] + base.width > $(window).width()) {
- var tip_css = {top: tip_position[1] + 'px', right: tip_position[0] + 'px', left: 'auto'};
- }
- else {
- var tip_css = {top: tip_position[1] + 'px', left: tip_position[0] + 'px', right: 'auto'};
- }
+ if (base.settings.alignTo == 'cursor') {
+ var tip_position = [e.pageX + base.settings.offset[0], e.pageY + base.settings.offset[1]];
+ if(tip_position[0] + base.width > $(window).width()) {
+ var tip_css = {top: tip_position[1] + 'px', right: tip_position[0] + 'px', left: 'auto'};
}
else {
- var tip_position = [
- (function (pos) {
- if (base.settings.offset[0] < 0) {
- return pos.left - Math.abs(base.settings.offset[0]) - base.width;
- }
- else if (base.settings.offset[0] == 0) {
- return pos.left - ((base.width - base.$el.outerWidth()) / 2);
- }
- else {
- return pos.left + base.$el.outerWidth() + base.settings.offset[0];
- }
- })(base.$el.offset()),
- (function (pos) {
- if (base.settings.offset[1] < 0) {
- return pos.top - Math.abs(base.settings.offset[1]) - base.height;
- }
- else if (base.settings.offset[1] == 0) {
- return pos.top - ((base.height - base.$el.outerHeight()) / 2);
- }
- else {
- return pos.top + base.$el.outerHeight() + base.settings.offset[1];
- }
- })(base.$el.offset())
- ];
+ var tip_css = {top: tip_position[1] + 'px', left: tip_position[0] + 'px', right: 'auto'};
}
- base.$tipsy.css({top: tip_position[1] + 'px', left: tip_position[0] + 'px'});
- base.settings.show(e, base.$tipsy.stop(true, true));
- }).bind('mouseleave', function (e) {
- if (e.relatedTarget == base.$tip[0]) {
- base.$tip.bind('mouseleave', function (e) {
- if (e.relatedTarget == base.$el[0]) {
- return;
+ }
+ else {
+ var tip_position = [
+ (function (pos) {
+ if (base.settings.offset[0] < 0) {
+ return pos.left - Math.abs(base.settings.offset[0]) - base.width;
}
- base.settings.hide(e, base.$tipsy.stop(true, true));
- });
- return;
- }
- base.settings.hide(e, base.$tipsy.stop(true, true));
- });
- };
-
- base.readify = function () {
- base.ready = true;
- base.title = base.$el.attr('title') || '';
- base.$el.attr('title', '');
- base.$tipsy = $('<div id="tooltipsy' + base.random + '">').appendTo('body').css({position: 'absolute', zIndex: '999'}).hide();
- base.$tip = $('<div class="' + base.settings.className + '">').appendTo(base.$tipsy);
- base.$tip.data('rootel', base.$el);
- base.$tip.html(base.settings.content != '' ? base.settings.content : base.title);
- };
+ else if (base.settings.offset[0] == 0) {
+ return pos.left - ((base.width - base.$el.outerWidth()) / 2);
+ }
+ else {
+ return pos.left + base.$el.outerWidth() + base.settings.offset[0];
+ }
+ })(base.$el.offset()),
+ (function (pos) {
+ if (base.settings.offset[1] < 0) {
+ return pos.top - Math.abs(base.settings.offset[1]) - base.height;
+ }
+ else if (base.settings.offset[1] == 0) {
+ return pos.top - ((base.height - base.$el.outerHeight()) / 2);
+ }
+ else {
+ return pos.top + base.$el.outerHeight() + base.settings.offset[1];
+ }
+ })(base.$el.offset())
+ ];
+ }
+ base.$tipsy.css({top: tip_position[1] + 'px', left: tip_position[0] + 'px'});
+ base.settings.show(e, base.$tipsy.stop(true, true));
+ }).bind('mouseleave', function (e) {
+ if (e.relatedTarget == base.$tip[0]) {
+ base.$tip.bind('mouseleave', function (e) {
+ if (e.relatedTarget == base.$el[0]) {
+ return;
+ }
+ base.settings.hide(e, base.$tipsy.stop(true, true));
+ });
+ return;
+ }
+ base.settings.hide(e, base.$tipsy.stop(true, true));
+ });
+ };
- base.init();
+ $.tooltipsy.prototype.readify = function () {
+ this.ready = true;
+ this.title = this.$el.attr('title') || '';
+ this.$el.attr('title', '');
+ this.$tipsy = $('<div id="tooltipsy' + this.random + '">').appendTo('body').css({position: 'absolute', zIndex: '999'}).hide();
+ this.$tip = $('<div class="' + this.settings.className + '">').appendTo(this.$tipsy);
+ this.$tip.data('rootel', this.$el);
+ this.$tip.html(this.settings.content != '' ? this.settings.content : this.title);
};
- $.tooltipsy.defaults = {
+ $.tooltipsy.prototype.defaults = {
alignTo: 'element',
offset: [0, -1],
content: '',

0 comments on commit 5f58712

Please sign in to comment.