Skip to content

Commit

Permalink
Added stock buttons (close and autohide) options and callbacks
Browse files Browse the repository at this point in the history
git-svn-id: http://ourlibrary.googlecode.com/svn/trunk@94 fad0cf9c-0ac3-11df-8f06-1508ab885915
  • Loading branch information
david-mark committed Apr 17, 2010
1 parent 4f06967 commit e0b396d
Show file tree
Hide file tree
Showing 2 changed files with 71 additions and 3 deletions.
2 changes: 1 addition & 1 deletion mylib-sidebar-min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

72 changes: 70 additions & 2 deletions mylib-sidebar.js
Expand Up @@ -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 api = API, getBodyElement = api.getBodyElement, showElement = api.showElement, createElement = api.createElement;
var body = getBodyElement(); var body = getBodyElement();
var oppositeSides = { left:'right', right:'left', top:'bottom', bottom:'top' }; 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) { if (body && API.isHostMethod(body, 'appendChild') && api.sideBar) {
api.enhanceSideBar = function(el, options, doc) { api.enhanceSideBar = function(el, options, doc) {
Expand All @@ -33,12 +55,58 @@ if (API && API.areFeatures && API.areFeatures('createElement', 'attachDocumentRe
} }
return null; return null;
}; };
if (createElement) { if (appendSideBarButton) {
api.createSideBar = function(options, doc) { api.createSideBar = function(options, doc) {
if (!options) {
options = {};
}
var el = createElement('div'); var el = createElement('div');
if (el) { if (el) {
API.setControlContent(el, options); 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; return null;
}; };
Expand Down

0 comments on commit e0b396d

Please sign in to comment.