1 /*******************************************************************************
2 * Copyright (c) 2016 AT&T Intellectual Property. All rights reserved.
3 *******************************************************************************/
4 function getCommand() {
5 if(typeof String.prototype.trim !== 'function') {
6 String.prototype.trim = function() {
7 return this.replace(/^\s+|\s+$/g, '');
12 cmds = document.querySelector("#command_field").value.split(" ");
14 if (document.querySelector("#details_img").getAttribute("class") == "selected")
15 cleanCmd += "set details=true ";
16 for (var i = 0; i < cmds.length;i++) {
17 var trimmed = cmds[i].trim();
19 cleanCmd += trimmed + " ";
22 return cleanCmd.trim();
25 function moveCommandToDiv() {
27 var textInput = document.querySelector("#command_field");
28 var content = document.createTextNode(textInput.value);
29 var parContent = document.createElement("p");
30 var consoleDiv = document.querySelector("#console_area");
31 var commandCount = consoleDiv.querySelectorAll(".command").length;
32 parContent.setAttribute("class", "command");
33 parContent.appendChild(content);
34 consoleDiv.appendChild(parContent);
39 function printResponse(response) {
40 var parContent = document.createElement("p");
41 parContent.setAttribute("class", "response");
42 var preTag = document.createElement("pre");
43 parContent.appendChild(preTag);
44 var content = document.createTextNode(response);
45 preTag.appendChild(content);
46 var consoleDiv = document.querySelector("#console_area");
47 consoleDiv.appendChild(parContent);
49 consoleDiv.scrollTop = consoleDiv.scrollHeight;
52 function clearHistory() {
53 var consoleDiv = document.querySelector("#console_area");
55 while (curr=consoleDiv.firstChild) {
56 consoleDiv.removeChild(curr);
58 document.querySelector("#command_field").value = "";
62 function buttonChangeFontSize(direction) {
63 var slider = document.querySelector("#text_size_slider");
64 var currentSize = parseInt(slider.value);
66 if (direction == "inc") {
67 newSize = currentSize + 10;
69 newSize = currentSize - 10;
71 if (newSize > slider.max) newSize = parseInt(slider.max);
72 if (newSize < slider.min) newSize = parseInt(slider.min);
73 slider.value = newSize;
74 changeFontSize(newSize);
77 function changeFontSize(size) {
78 var consoleDiv = document.querySelector("#console_area");
79 consoleDiv.style.fontSize = size + "%";
82 function handleDivHiding(id, img) {
83 var options_link = document.querySelector("#options_link");
84 var divHeight = toggleVisibility(document.querySelector("#"+id));
86 if (id == 'options') {
87 if (options_link.getAttribute("class") == "open") {
88 changeImg(document.querySelector("#options_img"), "../../theme/options_down.png");
89 options_link.setAttribute("class", "closed");
91 changeImg(document.querySelector("#options_img"), "../../theme/options_up.png");
92 options_link.setAttribute("class", "open");
94 moveToggleImg(options_link, divHeight);
95 } else { //id=text_slider
96 selectOption(img,divHeight);
101 function selectOption(img, divHeight) {
102 var options_link = document.querySelector("#options_link");
104 if (img.getAttribute("class") != "selected") {
105 anySelected = document.querySelectorAll(".selected").length>0;
106 if (anySelected == false)
108 img.setAttribute("class", "selected");
110 img.setAttribute("class", "");
111 anySelected = document.querySelectorAll(".selected").length>0;
112 if (anySelected == false)
117 moveToggleImg(options_link, divHeight);
120 function toggleVisibility(element) {
122 if(element.style.display == 'block') {
123 divHeight = 0 - element.clientHeight;
124 element.style.display = 'none';
126 element.style.display = 'block';
127 divHeight = element.clientHeight;
132 function moveToggleImg(element, height) {
133 var curTop = (element.style.top == "" ? 0 : parseInt(element.style.top));
134 element.style.top = curTop + height;
137 function changeImg(img, loc) {
142 function keyPressed() {
143 document.querySelector("#command_field").onkeyup=function(e) {
144 if (!e) e = window.event;
145 var keyCode = e.which || e.keyCode;
146 if (keyCode == 38 || keyCode == 40 || keyCode == 13 || keyCode == 27) {
147 var cmdHistoryList = document.querySelectorAll(".command");
152 if (getCommand().toLowerCase()=="clear") {
155 currentCmd = cmdHistoryList.length + 1;
156 document.querySelector("#submit").click();
162 currentCmd = cmdHistoryList.length;
163 document.querySelector("#command_field").value = "";
170 if (cmdHistoryList.length != 0)
171 document.querySelector("#command_field").value = cmdHistoryList[currentCmd].innerHTML;
176 currentCmd = (currentCmd == cmdHistoryList.length) ? currentCmd : currentCmd + 1;
177 if (currentCmd < cmdHistoryList.length)
178 cmdText = cmdHistoryList[currentCmd].innerHTML;
180 document.querySelector("#command_field").value = cmdText;
187 function saveToFile() {
188 var commands = document.querySelectorAll(".command");
189 var responses = document.querySelectorAll(".response");
190 var textToWrite = "";
191 for (var i = 0; i < commands.length; i++) {
192 textToWrite += "> " + commands[i].innerHTML + "\r\n";
193 textToWrite += prettyResponse(responses[i].firstChild.innerHTML);
196 var ie = navigator.userAgent.match(/MSIE\s([\d.]+)/);
197 var ie11 = navigator.userAgent.match(/Trident\/7.0/) && navigator.userAgent.match(/rv:11/);
198 var ieVer=(ie ? ie[1] : (ie11 ? 11 : -1));
200 // if (ie && ieVer<10) {
201 // console.log("No blobs on IE ver<10");
205 var textFileAsBlob = new Blob([textToWrite], {type:'text/plain'});
206 var fileName = "AAFcommands.log";
209 // window.navigator.msSaveBlob(textFileAsBlob, fileName);
210 window.navigator.msSaveOrOpenBlob(textFileAsBlob, fileName);
212 var downloadLink = document.createElement("a");
213 downloadLink.download = fileName;
214 downloadLink.innerHTML = "Download File";
215 if (window.webkitURL != null) {
216 // Chrome allows the link to be clicked
217 // without actually adding it to the DOM.
218 downloadLink.href = window.webkitURL.createObjectURL(textFileAsBlob);
220 // Firefox requires the link to be added to the DOM
221 // before it can be clicked.
222 downloadLink.href = window.URL.createObjectURL(textFileAsBlob);
223 downloadLink.onclick = destroyClickedElement;
224 downloadLink.style.display = "none";
225 document.body.appendChild(downloadLink);
228 downloadLink.click();
232 function prettyResponse(response) {
233 var lines = response.split('\n');
234 var cleanResponse = "";
235 for (var i=0; i < lines.length; i++) {
236 cleanResponse += lines[i] + "\r\n";
238 cleanResponse = cleanResponse.replace(/(<)/g,"<").replace(/(>)/g,">");
239 return cleanResponse;
242 function destroyClickedElement(event){
243 document.body.removeChild(event.target);
246 function fakePlaceholder() {
247 document.querySelector("#command_field").setAttribute("value", "Type your AAFCLI commands here");
250 function maximizeConsole(img) {
251 var footer = document.querySelector("#footer");
252 var console_area = document.querySelector("#console_area");
253 var content = document.querySelector("#content");
254 var input_area = document.querySelector("#input_area");
255 var help_msg = document.querySelector("#help_msg");
256 var console_space = document.documentElement.clientHeight;
257 console_space -= input_area.outerHeight;
258 console_space -= help_msg.outerHeight;
259 var height = getStyle(console_area,'paddingTop') + getStyle(console_area,'paddingBottom');
260 console_space -= height;
263 if (content.getAttribute("class") != "maximized") {
264 content.setAttribute("class", "maximized");
265 footer.style.display="none";
266 console_area.style.resize="none";
267 console_area.style.height=console_space.toString()+"px";
269 content.removeAttribute("class");
270 footer.style.display="";
271 console_area.style.resize="vertical";
272 console_area.style.height="300px";