Skip to content

Instantly share code, notes, and snippets.

@bsatrom
Created November 7, 2011 18:28
Show Gist options
  • Save bsatrom/1345741 to your computer and use it in GitHub Desktop.
Save bsatrom/1345741 to your computer and use it in GitHub Desktop.
Pinify Update to support hidding thumbbar buttons by default
createThumbbarButtons: function (options) {
var defaultOptions;
if (!siteModeSupported()) {
return this;
}
defaultOptions = {
buttons: []
};
options = $.extend({}, defaultOptions, options);
return callWindowExternalSafely(function () {
var ButtonStyle, buttons, clickCurrent;
if (window.external.msIsSiteMode()) {
buttons = [];
ButtonStyle = (function () {
function ButtonStyle() { }
ButtonStyle.prototype.button = null;
ButtonStyle.prototype.alternateStyle = null;
ButtonStyle.prototype.activeStyle = 0;
ButtonStyle.prototype.click = null;
ButtonStyle.prototype.hidden = false;
return ButtonStyle;
})();
clickCurrent = function (btn) {
var curr, newStyle;
curr = buttons[btn.buttonID];
curr.click();
if (curr.alternateStyle) {
newStyle = curr.activeStyle === 0 ? curr.alternateStyle : 0;
window.external.msSiteModeShowButtonStyle(curr.button, newStyle);
return curr.activeStyle = newStyle;
}
};
$.each(options.buttons, function (key, value) {
var altBtn, btn, buttonStyle, style;
btn = window.external.msSiteModeAddThumbBarButton(value.icon, value.name);
if (value.alternateStyle) {
style = value.alternateStyle;
altBtn = window.external.msSiteModeAddButtonStyle(btn, style.icon, style.name);
}
buttonStyle = new ButtonStyle;
buttonStyle.button = btn;
buttonStyle.alternateStyle = altBtn;
buttonStyle.click = value.click;
buttonStyle.hidden = value.hidden || false;
buttons[btn] = buttonStyle;
if (document.addEventListener) {
return document.addEventListener('msthumbnailclick', clickCurrent, false);
} else if (document.attachEvent) {
return document.attachEvent('onmsthumbnailclick', clickCurrent);
}
});
window.onunload = function () {
var key, value;
for (key in buttons) {
if (!__hasProp.call(buttons, key)) continuel;
value = buttons[key];
window.external.msSiteModeUpdateThumbBarButton(value.button, true, false);
}
};
window.onload = function () {
var key, value;
for (key in buttons) {
if (!__hasProp.call(buttons, key)) continue;
value = buttons[key];
if (!value.hidden) {
window.external.msSiteModeUpdateThumbBarButton(value.button, true, true);
}
}
};
return window.external.msSiteModeShowThumbBar();
}
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment