Permalink
Browse files

sync with master

  • Loading branch information...
1 parent 27055c2 commit 1359541fa79eaa1c033574cc726db38457fe3f03 @arthwood committed Jan 18, 2012
View
@@ -3,3 +3,4 @@ ArtJs.ObjectUtils.init();
ArtJs.StringUtils.init();
ArtJs.ElementUtils.init();
ArtJs.Selector.init();
+ArtJs.ClassUtils.init();
@@ -5,6 +5,7 @@ ArtJs.globalize = function() {
delete copy.globalize;
delete copy.doInjection;
+ delete copy.artJsNavigators;
delete copy.VERSION;
delete copy.CLIENT;
@@ -1,9 +1,11 @@
ArtJs.MouseController = com.arthwood.events.MouseController = function(e) {
this.onOver = new ArtJs.CustomEvent('MouseController::onOver');
this.onOut = new ArtJs.CustomEvent('MouseController::onOut');
+ this.onClick = new ArtJs.CustomEvent('MouseController::onClick');
e.attachEvent('onmouseover', ArtJs.$DC(this, this._onOver));
e.attachEvent('onmouseout', ArtJs.$DC(this, this._onOut));
+ e.attachEvent('onclick', ArtJs.$DC(this, this._onClick));
this.element = e;
this.over = false;
@@ -26,6 +28,10 @@ ArtJs.MouseController.prototype = {
}
},
+ _onClick: function(e) {
+ this.onClick.fire(e, this);
+ },
+
getTargets: function(e, over) {
var originRelated = [e.fromElement, e.toElement];
@@ -0,0 +1,62 @@
+ArtJs.ScreenManager = com.arthwood.ui.ScreenManager = function(screens, dontShow) {
+ if (screens.length == 0) {
+ throw new Error('ScreenManager: invalid args');
+ }
+
+ this.screens = screens;
+ this.hideAll();
+
+ if (!dontShow) {
+ this.setScreenAt(0);
+ }
+};
+
+ArtJs.ScreenManager.prototype = {
+ next: function() {
+ this.index = Math.min(this.index + 1, this.screens.length);
+ this.switchScreens();
+ },
+
+ prev: function() {
+ this.index = Math.max(this.index - 1, 0);
+ this.switchScreens();
+ },
+
+ switchScreens: function() {
+ if (this.screen) {
+ this.hideScreen(this.screen);
+ }
+ this.screen = this.screens[this.index];
+ this.showScreen(this.screen);
+ },
+
+ hideAll: function() {
+ this.screens.each(this.hideScreen);
+ },
+
+ showAll: function() {
+ this.screens.each(this.showScreen);
+ },
+
+ setScreenAt: function(i) {
+ this.index = ArtJs.MathUtils.limit(i, 0, this.screens.length);
+ this.switchScreens();
+ },
+
+ setScreen: function(screen) {
+ var idx = this.screens.indexOf(screen);
+
+ if (idx == -1) {
+ throw new Error('ScreenManager: cannot set Screen ' + screen + ' as it is not included in screens collection.');
+ }
+ this.setScreenAt(idx);
+ },
+
+ showScreen: function(screen) {
+ ArtJs.ElementUtils.show(screen);
+ },
+
+ hideScreen: function(screen) {
+ ArtJs.ElementUtils.hide(screen);
+ }
+};
View
@@ -0,0 +1,108 @@
+ArtJs.Tabs = com.arthwood.ui.Tabs = function(tabs, screens, onTabOn, onTabOff) {
+ this.locked = false;
+ this.tabs = tabs;
+ this.tabScreenManager = new ArtJs.ScreenManager(screens, true);
+ this.tabOverToggler = new ArtJs.ClassToggler('over');
+ this.tabSelectToggler = new ArtJs.ClassToggler('active');
+ this.tabSelectToggler.onActivate.add(ArtJs.$D(this, this.onTab));
+ this.onTabOnCallback = onTabOn;
+ this.onTabOffCallback = onTabOff;
+ this.onTabOverD = ArtJs.$D(this, this.onTabOver);
+ this.onTabOutD = ArtJs.$D(this, this.onTabOut);
+ this.onTabClickD = ArtJs.$D(this, this.onTabClick);
+ this.updateTabCursorBind = ArtJs.$DC(this, this.updateTabCursor);
+ ArtJs.ArrayUtils.each(this.tabs, ArtJs.$DC(this, this.eachTab));
+ this.setTabAt(0);
+};
+
+ArtJs.Tabs.prototype = {
+ eachTab: function(tab) {
+ var mc = new ArtJs.MouseController(tab);
+
+ mc.onOver.add(this.onTabOverD);
+ mc.onOut.add(this.onTabOutD);
+ mc.onClick.add(this.onTabClickD);
+ },
+
+ onTabOver: function(e, mc) {
+ this.tabOverToggler.toggle(mc.getTargets(e).current);
+ },
+
+ onTabOut: function(e, mc) {
+ this.tabOverToggler.toggle(null);
+ },
+
+ onTabClick: function(e, mc) {
+ if (!this.locked) {
+ this.tabSelectToggler.toggle(mc.getTargets(e).current);
+ }
+
+ e.preventDefault();
+ },
+
+ onTab: function(ct) {
+ if (this.onTabOffCallback) this.onTabOffCallback(this);
+
+ this.tabScreenManager.setScreenAt(ArtJs.ArrayUtils.indexOf(this.tabs, ct.getCurrent()));
+
+ if (this.onTabOnCallback) this.onTabOnCallback(this);
+ },
+
+ currentIndex: function() {
+ return this.tabScreenManager.index;
+ },
+
+ currentTab: function() {
+ return this.tabSelectToggler.current;
+ },
+
+ currentScreen: function() {
+ return this.tabScreenManager.screen;
+ },
+
+ setTabAt: function(i) {
+ this.setTab(this.tabs[i]);
+ },
+
+ setTab: function(tab) {
+ this.tabSelectToggler.toggle(tab);
+ },
+
+ next: function() {
+ var ci = this.currentIndex();
+
+ if (ci < this.tabs.length - 1) {
+ this.tabSelectToggler.toggle(this.tabs[ci + 1]);
+ }
+ },
+
+ prev: function() {
+ var ci = this.currentIndex();
+
+ if (ci > 0) {
+ this.tabSelectToggler.toggle(this.tabs[ci - 1]);
+ }
+ },
+
+ setLocked: function(locked) {
+ this.locked = locked;
+ ArtJs.ArrayUtils.each(this.tabs, this.updateTabCursorBind);
+ },
+
+ updateTabCursor: function(tab) {
+ ArtJs.ElementUtils.setStyle(tab, {cursor: this.locked ? 'wait' : ''});
+ },
+
+ lock: function() {
+ this.setLocked(true);
+ },
+
+ unlock: function() {
+ this.setLocked(false);
+ },
+
+ length: function() {
+ return this.tabs.length;
+ }
+};
+
@@ -1,20 +1,30 @@
ArtJs.ClassToggler = com.arthwood.utils.ClassToggler = function(className) {
this.className = className;
- this.onD = new ArtJs.$D(this, this.on);
- this.offD = new ArtJs.$D(this, this.off);
- this.toggler = new Toggler(this.onD, this.offD);
+ this.toggler = new ArtJs.Toggler();
+ this.toggler.onActivate.add(ArtJs.$D(this, this._onActivate));
+ this.toggler.onDeactivate.add(ArtJs.$D(this, this._onDeactivate));
+ this.onActivate = new ArtJs.CustomEvent('ClassToggler::onActivate');
+ this.onDeactivate = new ArtJs.CustomEvent('ClassToggler::onDeactivate');
};
ArtJs.ClassToggler.prototype = {
toggle: function(item) {
this.toggler.toggle(item);
},
- on: function(item) {
- item.addClass(this.className);
+ _onActivate: function(t) {
+ if (t.current) t.current.addClass(this.className);
+
+ this.onActivate.fire(this);
},
- off: function(item) {
- item.removeClass(this.className);
+ _onDeactivate: function(t) {
+ if (t.current) t.current.removeClass(this.className);
+
+ this.onDeactivate.fire(this);
+ },
+
+ getCurrent: function() {
+ return this.toggler.current;
}
};
@@ -1,15 +1,15 @@
-ArtJs.Toggler = com.arthwood.utils.Toggler = function(onDelegate, offDelegate) {
+ArtJs.Toggler = com.arthwood.utils.Toggler = function() {
this.current = null;
- this.onDelegate = onDelegate;
- this.offDelegate = offDelegate;
+ this.onActivate = new ArtJs.CustomEvent('Toggler::onActivate');
+ this.onDeactivate = new ArtJs.CustomEvent('Toggler::onDeactivate');
};
ArtJs.Toggler.prototype = {
toggle: function(item) {
- if (this.current) this.offDelegate.invoke(this.current);
+ this.onDeactivate.fire(this);
this.current = item;
- if (this.current) this.onDelegate.invoke(this.current);
+ this.onActivate.fire(this);
}
};
View
@@ -28,6 +28,8 @@
ui/containers/ModalBox
ui/DatePicker
ui/Flash
+ ui/ScreenManager
+ ui/Tabs
tween/Base
tween/Fade
tween/Reveal

0 comments on commit 1359541

Please sign in to comment.