Skip to content
This repository has been archived by the owner on Jan 21, 2020. It is now read-only.

Commit

Permalink
add support for window resizing
Browse files Browse the repository at this point in the history
  • Loading branch information
keeper-vit authored and Ocramius committed Apr 16, 2014
1 parent b2c7c1c commit d596f08
Showing 1 changed file with 30 additions and 2 deletions.
32 changes: 30 additions & 2 deletions view/zend-developer-tools/toolbar/toolbar.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,16 @@
var container = document.getElementById("zend-developer-toolbar");
/** @type {number} */
var width = container.offsetWidth;
/** @type {number} */
var windowWidthDifference = window.innerWidth - width;
/** @type {HTMLElement} */
var toggleTrigger = document.getElementById("zdf-toolbar-toggle");
/** @type {boolean} */
var hidden;
/** @type {string} */
var cookieKeyHidden = "zdt-hidden";
/** @type {number} */
var widthHiddenState = 25;

self.toggle = function() {
!self.isHidden() ? self.hide() : self.show();
Expand All @@ -35,7 +40,7 @@
};

self.hide = function() {
slide((25 - width));
slide((widthHiddenState - width));

toggleTrigger.innerHTML = "►";
toggleTrigger.setAttribute("title", "Show Toolbar");
Expand Down Expand Up @@ -65,7 +70,8 @@
}

function initEvents() {
toggleTrigger.addEventListener("click", self.toggle);
bindEvent(toggleTrigger, "click", self.toggle);
bindEvent(window, "resize", resize);
}

/**
Expand Down Expand Up @@ -104,6 +110,28 @@
setTimeout(function() { slide(toPosition); }, 3);
}

/**
* @param {HTMLElement} node
* @param {string} event
* @param {function} handler
*/
function bindEvent(node, event, handler) {
if (node.attachEvent) {
node.attachEvent("on" + event, handler);
} else if (node.addEventListener) {
node.addEventListener(event, handler, false);
}
}

function resize() {
var newWidth = window.innerWidth - windowWidthDifference;

container.style.width = newWidth + "px";
width = newWidth;

self.isHidden() ? self.hide() : self.show();
}

return self;
};

Expand Down

0 comments on commit d596f08

Please sign in to comment.