Permalink
Browse files

Added stock buttons (close and autohide) options and callbacks

git-svn-id: http://ourlibrary.googlecode.com/svn/trunk@94 fad0cf9c-0ac3-11df-8f06-1508ab885915
  • Loading branch information...
1 parent 4f06967 commit e0b396d4e734f6e70695ad757c5e5332ef884d04 @david-mark committed Apr 17, 2010
Showing with 71 additions and 3 deletions.
  1. +1 −1 mylib-sidebar-min.js
  2. +70 −2 mylib-sidebar.js
View
Oops, something went wrong.
View
@@ -9,6 +9,28 @@ if (API && API.areFeatures && API.areFeatures('createElement', 'attachDocumentRe
var api = API, getBodyElement = api.getBodyElement, showElement = api.showElement, createElement = api.createElement;
var body = getBodyElement();
var oppositeSides = { left:'right', right:'left', top:'bottom', bottom:'top' };
+ var attachListener = api.attachListener, getElementParentElement = api.getElementParentElement, callInContext = api.callInContext;
+ var appendSideBarButton;
+
+ if (createElement && attachListener) {
+ appendSideBarButton = function(elSideBar, v, fn) {
+ var elButton = createElement('input');
+
+ if (elButton) {
+ elButton.type = 'button';
+ elButton.className = 'commandbutton';
+ elButton.value = v;
+ elSideBar.appendChild(elButton);
+
+ attachListener(elButton, 'click', function() {
+ return fn(getElementParentElement(this), this);
+ });
+ elButton = elSideBar = null;
+ return true;
+ }
+ return false;
+ };
+ }
if (body && API.isHostMethod(body, 'appendChild') && api.sideBar) {
api.enhanceSideBar = function(el, options, doc) {
@@ -33,12 +55,58 @@ if (API && API.areFeatures && API.areFeatures('createElement', 'attachDocumentRe
}
return null;
};
- if (createElement) {
+ if (appendSideBarButton) {
api.createSideBar = function(options, doc) {
+ if (!options) {
+ options = {};
+ }
var el = createElement('div');
if (el) {
API.setControlContent(el, options);
- return enhanceSideBar(el, options, doc);
+ if (options.buttons) {
+ var onclose = options.onclose;
+
+ if (API.showSideBar) {
+ appendSideBarButton(el, 'Close', function() {
+ API.showSideBar(el, false, {
+ effects:options.effects,
+ side:options.side,
+ duration:options.duration,
+ ease:options.ease,
+ fps:options.fps,
+ removeOnHide:true
+ });
+ API.unSideBar(el);
+ if (onclose) {
+ callInContext(onclose, options.callbackContext || API, el);
+ }
+ });
+ }
+
+ var onautohidecollision = options.onautohidecollision, onautohide = options.onautohide;
+
+ if (API.autoHideSideBar) {
+ appendSideBarButton(el, 'Auto-hide', function(el, elButton) {
+ if (API.autoHideSideBar(el, true, { duration:options.duration, ease:options.ease, fps:options.fps })) {
+ el.className += ' autohide';
+ elButton.disabled = true;
+ if (onautohide) {
+ callInContext(onautohide, options.callbackContext || API, el);
+ }
+ } else {
+ var doAlert = true;
+
+ if (onautohidecollision) {
+ doAlert = callInContext(onautohidecollision, options.callbackContext || API, el) !== false;
+ }
+ if (doAlert && API.isHostMethod(global, 'alert')) {
+ global.alert('Only one sidebar per edge may be hidden.');
+ }
+ }
+ });
+ }
+ }
+ return API.enhanceSideBar(el, options, doc);
}
return null;
};

0 comments on commit e0b396d

Please sign in to comment.