diff annotator_files/lib/widget.js @ 3:6356e78ccf5c

new version contains Annotator JS files to be used with FilesystemSite.
author casties
date Thu, 05 Apr 2012 19:37:27 +0200
parents
children 6979313586cf
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/annotator_files/lib/widget.js	Thu Apr 05 19:37:27 2012 +0200
@@ -0,0 +1,65 @@
+var __hasProp = Object.prototype.hasOwnProperty,
+  __extends = function(child, parent) { for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor; child.__super__ = parent.prototype; return child; };
+
+Annotator.Widget = (function(_super) {
+
+  __extends(Widget, _super);
+
+  Widget.prototype.classes = {
+    hide: 'annotator-hide',
+    invert: {
+      x: 'annotator-invert-x',
+      y: 'annotator-invert-y'
+    }
+  };
+
+  function Widget(element, options) {
+    Widget.__super__.constructor.apply(this, arguments);
+    this.classes = $.extend({}, Annotator.Widget.prototype.classes, this.classes);
+  }
+
+  Widget.prototype.checkOrientation = function() {
+    var current, offset, viewport, widget, window;
+    this.resetOrientation();
+    window = $(util.getGlobal());
+    widget = this.element.children(":first");
+    offset = widget.offset();
+    viewport = {
+      top: window.scrollTop(),
+      right: window.width() + window.scrollLeft()
+    };
+    current = {
+      top: offset.top,
+      right: offset.left + widget.width()
+    };
+    if ((current.top - viewport.top) < 0) this.invertY();
+    if ((current.right - viewport.right) > 0) this.invertX();
+    return this;
+  };
+
+  Widget.prototype.resetOrientation = function() {
+    this.element.removeClass(this.classes.invert.x).removeClass(this.classes.invert.y);
+    return this;
+  };
+
+  Widget.prototype.invertX = function() {
+    this.element.addClass(this.classes.invert.x);
+    return this;
+  };
+
+  Widget.prototype.invertY = function() {
+    this.element.addClass(this.classes.invert.y);
+    return this;
+  };
+
+  Widget.prototype.isInvertedY = function() {
+    return this.element.hasClass(this.classes.invert.y);
+  };
+
+  Widget.prototype.isInvertedX = function() {
+    return this.element.hasClass(this.classes.invert.x);
+  };
+
+  return Widget;
+
+})(Delegator);