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

Commit

Permalink
Merge pull request #11212 from adobe/marcel/mb-ld-without-head
Browse files Browse the repository at this point in the history
Append remote script to the end of the doc in case no "head" tag is present
  • Loading branch information
busykai committed Jul 26, 2015
2 parents ed1617f + c1c5bb2 commit f4258b2
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -739,6 +739,7 @@ define(function (require, exports, module) {
orig = doc.getText(),
gen = "",
lastIndex = 0,
remoteScriptInserted = false,
markCache;

if (!dom) {
Expand Down Expand Up @@ -787,11 +788,11 @@ define(function (require, exports, module) {

// If we have a script to inject and this is the head tag, inject it immediately
// after the open tag.
// TODO: handle cases where explicit html/head are missing
if (remoteScript && node.tag === "head") {
if (remoteScript && !remoteScriptInserted && node.tag === "head") {
insertIndex = node.openEnd;
gen += orig.substr(lastIndex, insertIndex - lastIndex) + remoteScript;
lastIndex = insertIndex;
remoteScriptInserted = true;
}
}

Expand All @@ -803,6 +804,12 @@ define(function (require, exports, module) {
walk(dom);
gen += orig.substr(lastIndex);

if (remoteScript && !remoteScriptInserted) {
// if the remote script couldn't be injected before (e.g. due to missing "head" tag),
// append it at the end
gen += remoteScript;
}

return gen;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<!doctype html>
<meta charset="UTF-8">
<title>Simple Test</title>
<link rel="stylesheet" href="simpleShared.css">
<link rel="stylesheet" href="simple1.css">

<p id="testId" class="testClass">Brackets is awesome!</p>
<p id ="testId2" class="testClass2" >Red is bad. Green is good.</p>
13 changes: 13 additions & 0 deletions test/spec/LiveDevelopmentMultiBrowser-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,19 @@ define(function (require, exports, module) {
});
});

it("should establish a browser connection for an opened html file that has no 'head' tag", function () {
//open a file
runs(function () {
waitsForDone(SpecRunnerUtils.openProjectFiles(["withoutHead.html"]), "SpecRunnerUtils.openProjectFiles withoutHead.html", 1000);
});

waitsForLiveDevelopmentToOpen();

runs(function () {
expect(LiveDevelopment.status).toBe(LiveDevelopment.STATUS_ACTIVE);
});
});

it("should find an index.html in a parent directory", function () {
runs(function () {
waitsForDone(SpecRunnerUtils.openProjectFiles(["sub/test.css"]), "SpecRunnerUtils.openProjectFiles sub/test.css", 1000);
Expand Down

0 comments on commit f4258b2

Please sign in to comment.