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

Rename LoadEvents to AppIinit #1464

Merged
merged 4 commits into from
Aug 28, 2012
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions src/brackets.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ define(function (require, exports, module) {

// Load dependent modules
var Global = require("utils/Global"),
LoadEvents = require("utils/LoadEvents"),
AppInit = require("utils/AppInit"),
ProjectManager = require("project/ProjectManager"),
DocumentManager = require("document/DocumentManager"),
EditorManager = require("editor/EditorManager"),
Expand Down Expand Up @@ -153,7 +153,7 @@ define(function (require, exports, module) {
doneLoading : false
};

LoadEvents.ready(function () {
AppInit.appReady(function () {
brackets.test.doneLoading = true;
});
}
Expand Down Expand Up @@ -258,10 +258,10 @@ define(function (require, exports, module) {
ProjectManager.openProject(initialProjectPath).done(function () {
_initTest();

// WARNING: LoadEvents.ready won't fire if ANY extension fails to
// WARNING: AppInit.appReady won't fire if ANY extension fails to
// load or throws an error during init. To fix this, we need to
// make a change to _initExtensions (filed as issue 1029)
_initExtensions().always(LoadEvents._dispatchEvent(LoadEvents.READY));
_initExtensions().always(AppInit._dispatchReady(AppInit.APP_READY));
});

// Check for updates
Expand All @@ -272,7 +272,7 @@ define(function (require, exports, module) {

// Localize MainViewHTML and inject into <BODY> tag
$('body').html(Mustache.render(MainViewHTML, Strings));
LoadEvents._dispatchEvent(LoadEvents.HTML_CONTENT_LOAD_COMPLETE);
AppInit._dispatchReady(AppInit.HTML_READY);

$(window.document).ready(_onReady);

Expand Down
4 changes: 2 additions & 2 deletions src/htmlContent/main-view.html
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@


<!--
This is the HTML for the body tag of index.html. It is loaded dynamically by the
htmlContentLoad module and localized using a combination of mustache.js and i18n.js.
HTML template for the body tag of index.html. It is rendered dynamically in
brackets.js with Mustache and localized with the i18n RequireJS plugin.

LOCALIZATION NOTE:
All display text for this file must use templating so the text can be localized.
Expand Down
8 changes: 4 additions & 4 deletions src/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -58,10 +58,10 @@

<!-- HTML content is dynamically loaded and rendered by brackets.js.
Any modules that depend on or modify HTML during load should
require the "utils/LoadEvents" modules and install an event handler
for "htmlContentLoadComplete" (e.g. LoadEvents.htmlContentLoadComplete(handler))
before touching the DOM. -->

require the "utils/Ready" modules and install a callback for
"htmlReady" (e.g. AppInit.htmlReady(handler)) before touching the DOM.
-->
<!-- All other scripts are loaded through require. -->
<script src="thirdparty/require.js" data-main="brackets"></script>

Expand Down
6 changes: 3 additions & 3 deletions src/project/ProjectManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ define(function (require, exports, module) {
require("thirdparty/jstree_pre1.0_fix_1/jquery.jstree");

// Load dependent modules
var LoadEvents = require("utils/LoadEvents"),
var AppInit = require("utils/AppInit"),
NativeFileSystem = require("file/NativeFileSystem").NativeFileSystem,
PreferencesManager = require("preferences/PreferencesManager"),
DocumentManager = require("document/DocumentManager"),
Expand All @@ -63,7 +63,7 @@ define(function (require, exports, module) {
/**
* @private
* Reference to the tree control container div. Initialized by
* htmlContentLoadComplete handler
* htmlReady handler
* @type {jQueryObject}
*/
var $projectTreeContainer;
Expand Down Expand Up @@ -933,7 +933,7 @@ define(function (require, exports, module) {


// Initialize variables and listeners that depend on the HTML DOM
LoadEvents.htmlContentLoadComplete(function () {
AppInit.htmlReady(function () {
$projectTreeContainer = $("#project-files-container");

$("#open-files-container").on("contentChanged", function () {
Expand Down
6 changes: 3 additions & 3 deletions src/project/SidebarView.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
define(function (require, exports, module) {
"use strict";

var LoadEvents = require("utils/LoadEvents"),
var AppInit = require("utils/AppInit"),
ProjectManager = require("project/ProjectManager"),
WorkingSetView = require("project/WorkingSetView"),
CommandManager = require("command/CommandManager"),
Expand All @@ -43,7 +43,7 @@ define(function (require, exports, module) {
var PREFERENCES_CLIENT_ID = "com.adobe.brackets.SidebarView",
defaultPrefs = { sidebarWidth: 200, sidebarClosed: false };

// These vars are initialized by the htmlContentLoadComplete handler
// These vars are initialized by the htmlReady handler
// below since they refer to DOM elements
var $sidebar,
$sidebarMenuText,
Expand Down Expand Up @@ -234,7 +234,7 @@ define(function (require, exports, module) {
}

// Initialize items dependent on HTML DOM
LoadEvents.htmlContentLoadComplete(function () {
AppInit.htmlReady(function () {
$sidebar = $("#sidebar");
$sidebarMenuText = $("#menu-view-hide-sidebar span");
$sidebarResizer = $("#sidebar-resizer");
Expand Down
119 changes: 119 additions & 0 deletions src/utils/AppInit.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,119 @@
/*
* 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 */

/**
* Defines hooks to assist with module initialization.
*
* This module defines 2 methods for client modules to attach callbacks:
* - htmlReady - When the main application template is rendered
* - appReady - When Brackets completes loading all modules and extensions
*
* These are *not* jQuery events. Each method is similar to $(document).ready
* in that it will call the handler immediately if brackets is already done
* loading.
*/
define(function (require, exports, module) {
"use strict";

// Fires when the base htmlContent/main-view.html is loaded
var HTML_READY = "htmlReady";

// Fires when all extensions are loaded
var APP_READY = "appReady";

var status = { HTML_READY : false, APP_READY : false },
callbacks = {};

callbacks[HTML_READY] = [];
callbacks[APP_READY] = [];

function _callHandler(handler) {
try {
// TODO (issue 1034): We *could* use a $.Deferred for this, except deferred objects enter a broken
// state if any resolution callback throws an exception. Since third parties (e.g. extensions) may
// add callbacks to this, we need to be robust to exceptions
handler();
} catch (e) {
console.log("Exception when calling a 'brackets done loading' handler");
console.log(e);
}
}

function _dispatchReady(type) {
var i,
myHandlers = callbacks[type];

// mark this status complete
status[type] = true;

for (i = 0; i < myHandlers.length; i++) {
_callHandler(myHandlers[i]);
}

// clear all callbacks after being called
callbacks[type] = [];
}

function _addListener(type, callback) {
if (status[type]) {
_callHandler(callback);
} else {
callbacks[type].push(callback);
}
}

/**
* Adds a callback for the ready hook. Handlers are called after
* htmlReady is done, the initial project is loaded, and all extensions are
* loaded.
* @param {function} handler
*/
function appReady(callback) {
// WARNING: "ready" won't fire if ANY extension fails to load or
// throws an error during init. To fix this, we need to make a change
// to _initExtensions (filed as issue 1029)
_addListener(APP_READY, callback);
}

/**
* Adds a callback for the htmlReady hook. Handlers are called after the
* main application html template is rendered.
* @param {function} handler
*/
function htmlReady(callback) {
_addListener(HTML_READY, callback);
}

exports.appReady = appReady;
exports.htmlReady = htmlReady;

exports.HTML_READY = HTML_READY;
exports.APP_READY = APP_READY;

// internal use only
exports._dispatchReady = _dispatchReady;
});
2 changes: 1 addition & 1 deletion src/utils/Global.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
* Initializes the global "brackets" variable and it's properties.
* Modules should not access the global.brackets object until either
* (a) the module requires this module, i.e. require("utils/Global") or
* (b) the module receives a "ready" event from the utils/LoadEvents module.
* (b) the module receives a "ready" callback from the utils/AppReady module.
*/
define(function (require, exports, module) {
"use strict";
Expand Down
118 changes: 0 additions & 118 deletions src/utils/LoadEvents.js

This file was deleted.