-
Notifications
You must be signed in to change notification settings - Fork 2
/
ProcessFileEdit.js
175 lines (149 loc) · 5.85 KB
/
ProcessFileEdit.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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
/*jslint this:true */
/*jslint browser:true */
/*jslint for:true */
/*global
$, window, parent
*/
$(document).ready(function () {
"use strict";
if (location.hash !== "") {
//var matchingLink = $(".php-file-tree .pft-d > a[data-p='" + location.hash + "'");
var matchingLink = $(".php-file-tree .pft-d > a[data-p='" + location.hash.substring(1) + "'");
matchingLink.parents(".pft-d").addClass("pft-d-open");
matchingLink.attr("tabIndex", "1").addClass("active").focus(); // bring into view
}
// Expand/collapse on click
$(".pft-d a").click(function (e) {
var parent = $(this).parent();
e.preventDefault();
// uncomment this line to disable auto-close other opened dirs (keeps current branch open)
$(".php-file-tree .pft-d-open").not($(this).parents()).removeClass("pft-d-open");
$(".php-file-tree a.active").removeClass("active");
if (!parent.hasClass("pft-d-open")) {
$(this).addClass("active");
}
var path = $(this).attr("data-p");
if (path && history.pushState) {
path = "#" + path;
//if (location.hash === encodeURI(path) || parent.hasClass("pft-d-open")) {
if (location.hash === path || parent.hasClass("pft-d-open")) {
if (parent.parents(".pft-d-open").length) {
path = path.replace($(this).text() + "/", "");
} else {
path = window.location.pathname + window.location.search;
}
}
//path = encodeURI(path);
history.replaceState(null, document.title, path);
}
parent.toggleClass("pft-d-open");
});
function setupCloneButton1() {
// this is a copy of main.js from admin theme default
if ($("body").is(".modal") === false) {
return; // prevent doubling in main.js
}
// if there are buttons in the format "a button" without ID attributes, copy them into the masthead
// or buttons in the format button.head_button_clone with an ID attribute.
// var $buttons = $("#content a[id=''] button[id=''], #content button.head_button_clone[id!='']");
// var $buttons = $("#content a:not([id]) button:not([id]), #content button.head_button_clone[id!=]");
var $buttons = $("button.pw-head-button, button.head-button, button.head_button_clone"); // head_button_clone is legacy or is it head-button?
if ($buttons.length === 0) {
return;
}
var $head = $("#head_button");
if ($head.length === 0) {
$head = $("#pw-content-head-buttons"); //MP for AdminThemeUikit
}
if ($head.length === 0) {
$head = $("<div id='head_button'></div>").prependTo("#content .container"); // now #pw-content .pw-container
}
$buttons.each(function () {
var $t = $(this);
var $a = $t.parent("a");
var $button;
if ($a.length > 0) {
$button = $t.parent("a").clone(true);
$head.prepend($button);
} else if ($t.hasClass("pw-head-button") || $t.hasClass("head_button_clone") || $t.hasClass("head-button")) {
$button = $t.clone(true);
$button.attr("data-from_id", $t.attr("id")).attr("id", $t.attr("id") + "_copy");
$button.click(function () {
$("#" + $(this).attr("data-from_id")).click();
return false;
});
$head.prepend($button);
}
});
$head.show();
}
// there is no head_button in modal view, so create it
setupCloneButton1();
var saveButton = $("#saveFile");
var isChanged = $("#change");
var closeBtn = parent.$(".ui-dialog-titlebar-close");
saveButton.on("click", function (e) {
e.preventDefault();
window.editor.save();
$.ajax({
url: saveButton.data("url"),
data: $("#editForm").serializeArray(),
type: "POST",
success: function (data) {
if (data === "") {
isChanged.html("");
$("#saveFile").addClass("ui-state-disabled");
$("#saveFile_copy").addClass("ui-state-disabled");
} else {
window.alert(data);
}
return false;
},
error: function (xhr, textStatus) {
window.alert("Ajax request failed: " + textStatus);
return false;
}
});
return false;
});
/*
$(document).on("keydown", function (e) {
e = e || window.event;
var closeBtnCurrent = parent.$(".ui-dialog-titlebar-close");
if (e.keyCode === 27 && closeBtnCurrent.length) {
closeBtnCurrent.trigger("mousedown");
}
});
*/
closeBtn.on("mousedown", function (e) {
if (isChanged.html() !== "") {
var confirm = window.confirm("File is not saved. Continue?");
if (!confirm) {
e.preventDefault();
return false;
}
isChanged.html("");
closeBtn.click();
}
});
//if (!!$.prototype.magnificPopup) {
if ($.prototype.magnificPopup) {
var magnificOptions = {
closeOnContentClick: true,
closeBtnInside: true,
image: {
titleSrc: function (item) {
return item.el.text();
}
},
callbacks: {
open: function () {
//
}
}
};
var magnificOptionsImage = $.extend(true, {}, magnificOptions);
magnificOptionsImage.type = "image";
$(".ext-jpg a, .ext-png a, .ext-gif a, .ext-bmp a").magnificPopup(magnificOptionsImage);
}
});