This repository has been archived by the owner on Dec 8, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 90
/
DocumentFragmentHandler.js
97 lines (76 loc) · 3.51 KB
/
DocumentFragmentHandler.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
/**
* @author Swagatam Mitra
*/
/*jslint vars: true, plusplus: true, devel: true, nomen: true, indent: 4, maxerr: 50 */
/*global define, document, console, brackets, $, Mustache */
define(function (require, exports, module) {
"use strict";
var AppInit = brackets.getModule("utils/AppInit"),
FileUtils = brackets.getModule("file/FileUtils"),
CommandManager = brackets.getModule("command/CommandManager"),
DocumentManager = brackets.getModule("document/DocumentManager"),
EditorManager = brackets.getModule("editor/EditorManager");
var FileSystem = brackets.getModule("filesystem/FileSystem");
function _cleanUpMainMarkup(){
$(document.getElementById('htmldesignerIframe').contentWindow.document.body).find('*').not("link,script,style").hide();
}
function _loadFragment(){
var currentDoc = DocumentManager.getCurrentDocument();
var designDOM = document.getElementById('htmldesignerIframe').contentWindow.document.body;
var container = $(designDOM).find("#ad-fragment-container");
if(container.length === 0){
$('<div id="ad-fragment-container"></div>').appendTo(designDOM);
container = $(designDOM).find("#ad-fragment-container");
}
container.html(currentDoc.getText(true));
$("#html-design-editor").trigger("design-editor-shown");
}
function _loadFragmentInMainContext(){
$("#html-design-editor").trigger("deselect.all");
_cleanUpMainMarkup();
_loadFragment();
$("#htmldesignerIframe").show();
$("#html-design-editor").trigger("fragmentDesignModeon");
$("#html-design-editor").trigger("design-dom-changed");
}
function _setFramePath(){
$("#htmldesignerIframe")[0].src = $("#main-doc-path")[0].value;
//$("#htmldesignerShadowIframe")[0].src = $("#main-doc-path")[0].value;
_hideLinkPanel();
window.setTimeout(_loadFragmentInMainContext,6000);
}
function _handleFragmentLoading(){
//$("#htmldesignerIframe").hide();
$("#htmldesignerIframe")[0].src = "about:blank";
//$("#htmldesignerShadowIframe")[0].src = "about:blank";
window.setTimeout(_setFramePath,2000);
}
function _hideLinkPanel(){
$("#fragment-link-panel").hide();
}
$(document).on("targetdom.element.click","#html-design-editor", _hideLinkPanel);
$(document).on("change","#main-doc-path", _handleFragmentLoading);
function _showFragmentLinkPanel(){
$("#main-doc-path")[0].value = "";
$("#fragment-link-panel").show();
}
$(document).on("launch-fragment-linker","#html-design-editor", function(event){
_showFragmentLinkPanel();
});
$(document).on("click", "#browse-main-doc", function(event){
FileSystem.showOpenDialog(false, false, "Please Select file", '', null,
function (err, files) {
if (!err) {
$("#main-doc-path").val(files[0]);
$("#main-doc-path").trigger('change');
} else {
// result.reject();
}
});
});
$(document).on("click", "#close-fragment-link-panel", _hideLinkPanel);
$(document).on("click", "#load-as-fragment", _showFragmentLinkPanel);
AppInit.appReady(function () {
CommandManager.register("Launch fragment link", "launch.fragment.linker", _showFragmentLinkPanel);
});
});