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
/
PersistenceManager.js
70 lines (55 loc) · 2.52 KB
/
PersistenceManager.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
/**
* @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 FileUtils = brackets.getModule("file/FileUtils"),
DocumentManager = brackets.getModule("document/DocumentManager");
var isFragmentModeOn = false;
var currentApplication = null;
var beautify_html = require('lib/beautify/beautify-html').html_beautify;
var CommonUtils = require("CommonUtils");
var config = JSON.parse(require('text!lib/beautify/config/defaults.json'));
function _isDOMSaveRequired(){
var domSaveReqd = false;
if(currentApplication && CommonUtils.isValidMarkupFile(FileUtils.getFileExtension(currentApplication))){
domSaveReqd = true;
}
return domSaveReqd;
}
$(document).on('html.save.dom',"#html-design-editor",function(event, doc){
var docText = '';
if(_isDOMSaveRequired()){
$("#html-design-editor").trigger('before.save.dom');
if(doc){
if(isFragmentModeOn === true){
docText = $(document.getElementById('htmldesignerIframe').contentWindow.document).find("#ad-fragment-container")[0].innerHTML;
} else {
docText = document.getElementById('htmldesignerIframe').contentWindow.document.documentElement.innerHTML;
}
}
var result = beautify_html(docText, config);
doc.setText(result);
$("#html-design-editor").trigger('after.save.dom');
}
});
$(document).on('html.element.dropped html.element.updated html.element.removed',"#html-design-editor",function(){
var currentDoc = DocumentManager.getCurrentDocument();
$("#html-design-editor").trigger('html.save.dom',[currentDoc]);
});
$(document).on('fragmentDesignModeon',"#html-design-editor",function(){
isFragmentModeOn = true;
});
/*$(document).on('design-dom-changed',"#html-design-editor",function(){
isFragmentModeOn = false;
});*/
$(document).on("application.context","#html-design-editor", function(event,applicationKey){
currentApplication = applicationKey;
isFragmentModeOn = false;
if(currentApplication){
currentApplication = currentApplication.split('?')[0];
}
});
});