Skip to content
This repository has been archived by the owner on Sep 6, 2021. It is now read-only.

Commit

Permalink
Cleanup changes for pull request review
Browse files Browse the repository at this point in the history
  • Loading branch information
jbalsas committed Oct 3, 2012
1 parent 5559cd3 commit c561ef0
Show file tree
Hide file tree
Showing 4 changed files with 58 additions and 59 deletions.
18 changes: 10 additions & 8 deletions src/language/JSLintUtils.js
Expand Up @@ -23,7 +23,7 @@


/*jslint vars: true, plusplus: true, devel: true, nomen: true, indent: 4, maxerr: 50 */
/*global define, $, JSLINT, PathUtils, document, window */
/*global define, $, JSLINT, PathUtils */

/**
* Allows JSLint to run on the current document and report results in a UI panel.
Expand All @@ -50,7 +50,11 @@ define(function (require, exports, module) {

var PREFERENCES_CLIENT_ID = module.id,
defaultPrefs = { height: 200, enabled: true };


// Height in pixels of the JSLint panel header. Hardcoded to avoid race
// condition when measuring it on htmlReady
var HEADER_HEIGHT = 27;

/**
* @private
* @type {PreferenceStorage}
Expand Down Expand Up @@ -219,16 +223,14 @@ define(function (require, exports, module) {
$jslintContent = $("#jslint-results .table-container");

$jslintResults.height(height);
$jslintContent.height(height - 27);
$jslintContent.height(height - HEADER_HEIGHT);

if (_enabled) {
EditorManager.resizeEditor();
}

$.when(Resizer.resizing($jslintResults)).progress(function (status, height) {
if (status === "end") {
_prefs.setValue("height", height);
}

$jslintResults.on("panelResizeEnd", function (event, height) {
_prefs.setValue("height", height);
});
});

Expand Down
14 changes: 8 additions & 6 deletions src/search/FindInFiles.js
Expand Up @@ -22,7 +22,7 @@
*/

/*jslint vars: true, plusplus: true, devel: true, nomen: true, regexp: true, indent: 4, maxerr: 50 */
/*global define, $, PathUtils, window, document */
/*global define, $, PathUtils, window */

/*
* Adds a "find in files" command to allow the user to find all occurances of a string in all files in
Expand Down Expand Up @@ -60,6 +60,10 @@ define(function (require, exports, module) {
var PREFERENCES_CLIENT_ID = module.id,
defaultPrefs = { height: 200 };

// Height in pixels of the JSLint panel header. Hardcoded to avoid race
// condition when measuring it on htmlReady
var HEADER_HEIGHT = 27;

// This dialog class was mostly copied from QuickOpen. We should have a common dialog
// class that everyone can use.

Expand Down Expand Up @@ -346,12 +350,10 @@ define(function (require, exports, module) {
height = prefs.getValue("height");

$searchResults.height(height);
$searchContent.height(height - 27);
$searchContent.height(height - HEADER_HEIGHT);

$.when(Resizer.resizing($("#search-results"))).progress(function (status, height) {
if (status === "end") {
prefs.setValue("height", height);
}
$searchResults.on("panelResizeEnd", function (event, height) {
prefs.setValue("height", height);
});
});

Expand Down
4 changes: 0 additions & 4 deletions src/styles/brackets.less
Expand Up @@ -62,14 +62,10 @@ html, body {
body {
.vbox;

/* This appears to be necessary in Firefox when body is set to display: box. */
width: 100%;
&.resizing a, &.resizing #projects a, &.resizing .main-view, &.resizing .CodeMirror-lines {
cursor: col-resize;
}

/* This appears to be necessary in Firefox when body is set to display: box. */
height: 100%;
&.ver-resizing a, &.ver-resizing #projects a, &.ver-resizing .main-view, &.ver-resizing .CodeMirror-lines {
cursor: row-resize;
}
Expand Down
81 changes: 40 additions & 41 deletions src/utils/Resizer.js
@@ -1,23 +1,47 @@
/*
* Copyright (c) 2012 Adobe Systems Incorporated. All rights reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
* DEALINGS IN THE SOFTWARE.
*
*/

/*jslint vars: true, plusplus: true, devel: true, nomen: true, indent: 4, maxerr: 50 */
/*global define, $, document, window */
/*global define, $, window */

/**
* Resizer is a Module utility to inject resizing capabilities to any element
* inside Brackets.
*
* On initialization, Resizer discovers all nodes tagged as "ver-resizable"
* and "hor-resizable" to add the resizer handler. Additionally, "top-resizer",
* "bottom-resizer", "left-resizer" and "right-resizer" classes control de
* "bottom-resizer", "left-resizer" and "right-resizer" classes control the
* position of the resizer on the element.
*
* An element can be made resizable at any time using the `makeResizable` API
*
* The `makeResizable` and `resizing` APIs return a promise that can be used to
* get updates about the resizing operations. The associated deferred object is
* notified on resize start, progress and completion. This can be used to create
* performance optimizations (such as hiding/showing elements while resizing),
* custom or internal resizes and save the final resized value into local storage
* for example.
* The resizable elements trigger a panelResizeStart, panelResizeUpdate and panelResizeEnd
* event that can be used to create performance optimizations (such as hiding/showing elements
* while resizing), custom or internal resizes and save the final resized value into local
* storage for example.
*
* TODO Trigger panelResizeStart and panelResizeUpdate as required. They aren't needed
* currently.
*/
define(function (require, exports, module) {
"use strict";
Expand All @@ -39,9 +63,6 @@ define(function (require, exports, module) {

var $mainView;

// Map of resize promises
var resizePromises = {};

/**
* Adds resizing capabilities to a given html element.
*
Expand All @@ -53,33 +74,29 @@ define(function (require, exports, module) {
* - Top ("top") or bottom ("bottom") for vertical resizing
* - Left ("left") or right ("right") for horizontal resizing
*
* A resize operation notifies its associated deferred object at:
* - start: When the resize starts
* - update: On resize updates (every time it is redrawn)
* - end: When the resize ends
* A resizable element triggers the following events while resizing:
* - panelResizeStart: When the resize starts
* - panelResizeUpdate: On resize updates (every time it is redrawn)
* - panelResizeEnds: When the resize ends
*
* @param {DOMNode} element Html element which should be made resizable.
* @param {string} direction The direction of the resize action. Must be "hor" or "ver".
* @param {string} position The position of the resizer on the element. Can be "top" or "bottom"
* for vertical resizing and "left" or "right" for horizontal resizing.
* for vertical resizing and "left" or "right" for horizontal resizing.
* @param {int} minSize Minimum size (width or height) of the element.
* @return {$.Promise} jQuery Promise object that is never resolved, but gets
* notified anytime the resize starts, updates or ends.
*/
function makeResizable(element, direction, position, minSize) {

var $resizer = $('<div class="' + direction + '-resizer"></div>'),
$element = $(element),
$resizableElement = $($element.find(".resizable-content:first")[0]),
$body = $(document.body),
$deferred = $.Deferred(),
$body = $(window.document.body),
animationRequest = null,
directionProperty = direction === DIRECTION_HORIZONTAL ? "clientX" : "clientY",
elementSizeFunction = direction === DIRECTION_HORIZONTAL ? $element.width : $element.height,
contentSizeFunction = null;

minSize = minSize || 0;
resizePromises[$element.attr("id")] = $deferred.promise();

$element.prepend($resizer);

Expand All @@ -90,9 +107,7 @@ define(function (require, exports, module) {
baseSize = 0,
doResize = true,
isMouseDown = true;

$deferred.notifyWith($element, ["start", elementSizeFunction.apply($element)]);


if ($resizableElement !== undefined) {
$element.children().not(".hor-resizer, .ver-resizer, .resizable-content").each(function (index, child) {
if (direction === DIRECTION_HORIZONTAL) {
Expand Down Expand Up @@ -125,8 +140,6 @@ define(function (require, exports, module) {
}

EditorManager.resizeEditor();

$deferred.notifyWith($element, ["update", elementSizeFunction.apply($element)]);
}

animationRequest = window.webkitRequestAnimationFrame(doRedraw);
Expand All @@ -144,7 +157,7 @@ define(function (require, exports, module) {
isMouseDown = false;
$mainView.off("mousemove");
$body.toggleClass(direction + "-resizing");
$deferred.notifyWith($element, ["end", elementSizeFunction.apply($element)]);
$element.trigger("panelResizeEnd", [elementSizeFunction.apply($element)]);
}
}

Expand All @@ -153,19 +166,6 @@ define(function (require, exports, module) {

e.preventDefault();
});

return $deferred.promise();
}

/**
* Gets the resize promise for an element
*
* @param {DOMNode} element Already resizable html element
* @return {$.Promise} jQuery The associated promise object or a new one
* if the element is not registered as resizable.
*/
function resizing(element) {
return resizePromises[element.attr("id")] || new $.Deferred().promise();
}

// Scan DOM for hor-resizable and ver-resizable classes and make them resizable
Expand Down Expand Up @@ -196,5 +196,4 @@ define(function (require, exports, module) {
});

exports.makeResizable = makeResizable;
exports.resizing = resizing;
});

0 comments on commit c561ef0

Please sign in to comment.