1 function getCommand() {
2 if(typeof String.prototype.trim !== 'function') {
3 String.prototype.trim = function() {
4 return this.replace(/^\s+|\s+$/g, '');
9 cmds = document.querySelector("#command_field").value.split(" ");
11 if (document.querySelector("#details_img").getAttribute("class") == "selected")
12 cleanCmd += "set details=true ";
13 for (var i = 0; i < cmds.length;i++) {
14 var trimmed = cmds[i].trim();
16 cleanCmd += trimmed + " ";
19 return cleanCmd.trim();
22 function moveCommandToDiv() {
24 var textInput = document.querySelector("#command_field");
25 var content = document.createTextNode(textInput.value);
26 var parContent = document.createElement("p");
27 var consoleDiv = document.querySelector("#console_area");
28 var commandCount = consoleDiv.querySelectorAll(".command").length;
29 parContent.setAttribute("class", "command");
30 parContent.appendChild(content);
31 consoleDiv.appendChild(parContent);
36 function printResponse(response) {
37 var parContent = document.createElement("p");
38 parContent.setAttribute("class", "response");
39 var preTag = document.createElement("pre");
40 parContent.appendChild(preTag);
41 var content = document.createTextNode(response);
42 preTag.appendChild(content);
43 var consoleDiv = document.querySelector("#console_area");
44 consoleDiv.appendChild(parContent);
46 consoleDiv.scrollTop = consoleDiv.scrollHeight;
49 function clearHistory() {
50 var consoleDiv = document.querySelector("#console_area");
52 while (curr=consoleDiv.firstChild) {
53 consoleDiv.removeChild(curr);
55 document.querySelector("#command_field").value = "";
59 function buttonChangeFontSize(direction) {
60 var slider = document.querySelector("#text_size_slider");
61 var currentSize = parseInt(slider.value);
63 if (direction == "inc") {
64 newSize = currentSize + 10;
66 newSize = currentSize - 10;
68 if (newSize > slider.max) newSize = parseInt(slider.max);
69 if (newSize < slider.min) newSize = parseInt(slider.min);
70 slider.value = newSize;
71 changeFontSize(newSize);
74 function changeFontSize(size) {
75 var consoleDiv = document.querySelector("#console_area");
76 consoleDiv.style.fontSize = size + "%";
79 function handleDivHiding(id, img) {
80 var options_link = document.querySelector("#options_link");
81 var divHeight = toggleVisibility(document.querySelector("#"+id));
83 if (id == 'options') {
84 if (options_link.getAttribute("class") == "open") {
85 changeImg(document.querySelector("#options_img"), "../../theme/onap/options_down.png");
86 options_link.setAttribute("class", "closed");
88 changeImg(document.querySelector("#options_img"), "../../theme/onap/options_up.png");
89 options_link.setAttribute("class", "open");
91 moveToggleImg(options_link, divHeight);
92 } else { //id=text_slider
93 selectOption(img,divHeight);
98 function selectOption(img, divHeight) {
99 var options_link = document.querySelector("#options_link");
101 if (img.getAttribute("class") != "selected") {
102 anySelected = document.querySelectorAll(".selected").length>0;
103 if (anySelected == false)
105 img.setAttribute("class", "selected");
107 img.setAttribute("class", "");
108 anySelected = document.querySelectorAll(".selected").length>0;
109 if (anySelected == false)
114 moveToggleImg(options_link, divHeight);
117 function toggleVisibility(element) {
119 if(element.style.display == 'block') {
120 divHeight = 0 - element.clientHeight;
121 element.style.display = 'none';
123 element.style.display = 'block';
124 divHeight = element.clientHeight;
129 function moveToggleImg(element, height) {
130 var curTop = (element.style.top == "" ? 0 : parseInt(element.style.top));
131 element.style.top = curTop + height;
134 function changeImg(img, loc) {
139 function keyPressed() {
140 document.querySelector("#command_field").onkeyup=function(e) {
141 if (!e) e = window.event;
142 var keyCode = e.which || e.keyCode;
143 if (keyCode == 38 || keyCode == 40 || keyCode == 13 || keyCode == 27) {
144 var cmdHistoryList = document.querySelectorAll(".command");
149 if (getCommand().toLowerCase()=="clear") {
152 currentCmd = cmdHistoryList.length + 1;
153 document.querySelector("#submit").click();
159 currentCmd = cmdHistoryList.length;
160 document.querySelector("#command_field").value = "";
167 if (cmdHistoryList.length != 0)
168 document.querySelector("#command_field").value = cmdHistoryList[currentCmd].innerHTML;
173 currentCmd = (currentCmd == cmdHistoryList.length) ? currentCmd : currentCmd + 1;
174 if (currentCmd < cmdHistoryList.length)
175 cmdText = cmdHistoryList[currentCmd].innerHTML;
177 document.querySelector("#command_field").value = cmdText;
184 function saveToFile() {
185 var commands = document.querySelectorAll(".command");
186 var responses = document.querySelectorAll(".response");
187 var textToWrite = "";
188 for (var i = 0; i < commands.length; i++) {
189 textToWrite += "> " + commands[i].innerHTML + "\r\n";
190 textToWrite += prettyResponse(responses[i].firstChild.innerHTML);
193 var ie = navigator.userAgent.match(/MSIE\s([\d.]+)/);
194 var ie11 = navigator.userAgent.match(/Trident\/7.0/) && navigator.userAgent.match(/rv:11/);
195 var ieVer=(ie ? ie[1] : (ie11 ? 11 : -1));
197 // if (ie && ieVer<10) {
198 // console.log("No blobs on IE ver<10");
202 var textFileAsBlob = new Blob([textToWrite], {type:'text/plain'});
203 var fileName = "AAFcommands.log";
206 // window.navigator.msSaveBlob(textFileAsBlob, fileName);
207 window.navigator.msSaveOrOpenBlob(textFileAsBlob, fileName);
209 var downloadLink = document.createElement("a");
210 downloadLink.download = fileName;
211 downloadLink.innerHTML = "Download File";
212 if (window.webkitURL != null) {
213 // Chrome allows the link to be clicked
214 // without actually adding it to the DOM.
215 downloadLink.href = window.webkitURL.createObjectURL(textFileAsBlob);
217 // Firefox requires the link to be added to the DOM
218 // before it can be clicked.
219 downloadLink.href = window.URL.createObjectURL(textFileAsBlob);
220 downloadLink.onclick = destroyClickedElement;
221 downloadLink.style.display = "none";
222 document.body.appendChild(downloadLink);
225 downloadLink.click();
229 function prettyResponse(response) {
230 var lines = response.split('\n');
231 var cleanResponse = "";
232 for (var i=0; i < lines.length; i++) {
233 cleanResponse += lines[i] + "\r\n";
235 cleanResponse = cleanResponse.replace(/(<)/g,"<").replace(/(>)/g,">");
236 return cleanResponse;
239 function destroyClickedElement(event){
240 document.body.removeChild(event.target);
243 function fakePlaceholder() {
244 document.querySelector("#command_field").setAttribute("value", "Type your AAFCLI commands here");
247 function maximizeConsole(img) {
248 var footer = document.querySelector("#footer");
249 var console_area = document.querySelector("#console_area");
250 var content = document.querySelector("#content");
251 var input_area = document.querySelector("#input_area");
252 var help_msg = document.querySelector("#help_msg");
253 var console_space = document.documentElement.clientHeight;
254 console_space -= input_area.outerHeight;
255 console_space -= help_msg.outerHeight;
256 var height = getStyle(console_area,'paddingTop') + getStyle(console_area,'paddingBottom');
257 console_space -= height;
260 if (content.getAttribute("class") != "maximized") {
261 content.setAttribute("class", "maximized");
262 footer.style.display="none";
263 console_area.style.resize="none";
264 console_area.style.height=console_space.toString()+"px";
266 content.removeAttribute("class");
267 footer.style.display="";
268 console_area.style.resize="vertical";
269 console_area.style.height="300px";