Skip to content
This repository was archived by the owner on Sep 6, 2021. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from 6 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
8 changes: 8 additions & 0 deletions src/LiveDevelopment/Documents/CSSDocument.js
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,14 @@ define(function CSSDocumentModule(require, exports, module) {
// "Instrumentation" is always enabled for CSS, we make no modifications
};

/**
* Returns true if document edits appear live in the connected browser
* @return {boolean}
*/
CSSDocument.prototype.isLiveEditingEnabled = function () {
return true;
};

/**
* Returns a JSON object with HTTP response overrides
* @returns {{body: string}}
Expand Down
10 changes: 9 additions & 1 deletion src/LiveDevelopment/Documents/HTMLDocument.js
Original file line number Diff line number Diff line change
Expand Up @@ -100,9 +100,17 @@ define(function HTMLDocumentModule(require, exports, module) {
this._instrumentationEnabled = enabled;
};

/**
* Returns true if document edits appear live in the connected browser
* @return {boolean}
*/
HTMLDocument.prototype.isLiveEditingEnabled = function () {
return this._instrumentationEnabled;
};

/**
* Returns a JSON object with HTTP response overrides
* @returns {{body: string}}
* @return {{body: string}}
*/
HTMLDocument.prototype.getResponseData = function getResponseData(enabled) {
var body;
Expand Down
52 changes: 32 additions & 20 deletions src/LiveDevelopment/LiveDevelopment.js
Original file line number Diff line number Diff line change
Expand Up @@ -151,9 +151,14 @@ define(function LiveDevelopment(require, exports, module) {

var _liveDocument; // the document open for live editing.
var _relatedDocuments; // CSS and JS documents that are used by the live HTML document
var _server; // current live dev server
var _openDeferred; // promise returned for each call to open()

/**
* Current live preview server
* @type {BaseServer}
*/
var _server;

function _isHtmlFileExt(ext) {
return (FileUtils.isStaticHtmlFileExt(ext) ||
(ProjectManager.getBaseUrl() && FileUtils.isServerHtmlFileExt(ext)));
Expand Down Expand Up @@ -185,23 +190,11 @@ define(function LiveDevelopment(require, exports, module) {
}

function getLiveDocForPath(path) {
var docsToSearch = [];
if (_relatedDocuments) {
docsToSearch = docsToSearch.concat(_relatedDocuments);
}
if (_liveDocument) {
docsToSearch = docsToSearch.concat(_liveDocument);
if (!_server) {
return undefined;
}
var foundDoc;
docsToSearch.some(function matchesPath(ele) {
if (ele.doc.file.fullPath === path) {
foundDoc = ele;
return true;
}
return false;
});

return foundDoc;

return _server.get(path);
}

function getLiveDocForEditor(editor) {
Expand Down Expand Up @@ -1106,10 +1099,29 @@ define(function LiveDevelopment(require, exports, module) {
}
}

/** Triggered by a document saved from the DocumentManager */
/**
* Triggered by a documentSaved event from DocumentManager.
* @param {$.Event} event
* @param {Document} doc
*/
function _onDocumentSaved(event, doc) {
if (doc && Inspector.connected() && _classForDocument(doc) !== CSSDocument &&
agents.network && agents.network.wasURLRequested(doc.url)) {
if (!Inspector.connected() || !_server) {
return;
}

var absolutePath = doc.file.fullPath,
liveDocument = absolutePath && _server.get(absolutePath),
liveEditingEnabled = liveDocument && liveDocument.isLiveEditingEnabled && liveDocument.isLiveEditingEnabled();

// Skip reload if the saved document has live editing enabled
if (liveEditingEnabled) {
return;
}

var documentUrl = _server.pathToUrl(absolutePath),
wasRequested = agents.network && agents.network.wasURLRequested(documentUrl);

if (wasRequested) {
// Unload and reload agents before reloading the page
reconnect();

Expand Down
18 changes: 14 additions & 4 deletions src/LiveDevelopment/Servers/BaseServer.js
Original file line number Diff line number Diff line change
Expand Up @@ -160,8 +160,8 @@ define(function (require, exports, module) {
return true;
};

BaseServer.prototype._documentKey = function (liveDocument) {
return "/" + encodeURI(this._pathResolver(liveDocument.doc.file.fullPath));
BaseServer.prototype._documentKey = function (absolutePath) {
return "/" + encodeURI(this._pathResolver(absolutePath));
};

/**
Expand All @@ -170,7 +170,7 @@ define(function (require, exports, module) {
*/
BaseServer.prototype.add = function (liveDocument) {
// use the project relative path as a key to lookup requests
var key = this._documentKey(liveDocument);
var key = this._documentKey(liveDocument.doc.file.fullPath);

this._setDocInfo(liveDocument);
this._liveDocuments[key] = liveDocument;
Expand All @@ -181,13 +181,23 @@ define(function (require, exports, module) {
* @param {Object} liveDocument
*/
BaseServer.prototype.remove = function (liveDocument) {
var key = this._liveDocuments[this._documentKey(liveDocument)];
var key = this._liveDocuments[this._documentKey(liveDocument.doc.file.fullPath)];

if (key) {
delete this._liveDocuments[key];
}
};

/**
* Lookup a live document using it's full path key
* @param {string} path Absolute path to covert to a URL
* @param {?Object} liveDocument Returns a live document or undefined if a
* document does not exist for the path.
*/
BaseServer.prototype.get = function (path) {
return this._liveDocuments[this._documentKey(path)];
};

/**
* Clears all live documents currently attached to the server
*/
Expand Down
4 changes: 1 addition & 3 deletions test/SpecRunner.js
Original file line number Diff line number Diff line change
Expand Up @@ -382,12 +382,10 @@ define(function (require, exports, module) {
window.document.body.addEventListener("click", function (e) {
// Check parents too, in case link has inline formatting tags
var node = e.target, url;
console.log(1);

while (node) {
console.log(node.tagName);
if (node.tagName === "A") {
url = node.getAttribute("href");
console.log(url);
if (url && url.match(/^http/)) {
NativeApp.openURLInDefaultBrowser(url);
e.preventDefault();
Expand Down
1 change: 1 addition & 0 deletions test/spec/LiveDevelopment-test-files/simple1.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
<title>Simple Test</title>
<link rel="stylesheet" href="simpleShared.css">
<link rel="stylesheet" href="simple1.css">
<script type="text/javascript" src="simple1.js"></script>
</head>

<body class="testClass">
Expand Down
Empty file.
Loading