8f1f9973411f5c44ceea23ac24cf564369403e7d
[platform/core/uifw/vc-webview-js.git] / js / vc-webview.js
1 /**
2  *   Copyright 2017 Samsung Electronics Co., Ltd.
3  *
4  *   Licensed under the Flora License, Version 1.1 (the "License");
5  *   you may not use this file except in compliance with the License.
6  *   You may obtain a copy of the License at
7  *
8  *       http://floralicense.org/license/
9  *
10  *   Unless required by applicable law or agreed to in writing, software
11  *   distributed under the License is distributed on an "AS IS" BASIS,
12  *   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  *   See the License for the specific language governing permissions and
14  *   limitations under the License.
15  */
16
17 /**
18  * vc-webview.js
19  *
20  *  This source code is a base script of web voice touch.
21  */
22
23  /**
24  * vc_docs holds analysed documents' first hint number and last hint number
25  * @member doc  document elements.
26  * @member start  the first tooltip number in @doc.
27  * @member end  the last tooltip number in @doc.
28  */
29 var vc_docs = [],
30
31 vc_conflict_timer = null,
32
33 /**
34  * vc_conflict_links holds references to links that match the same keyword
35  */
36 vc_conflict_links = [];
37
38 /**
39  * vc_scr holds info about screen and website
40  * @member top  coordinate of the top boundary.
41  * @member left  coordinate of the left boundary.
42  * @member bottom  coordinate of the bottom boundary.
43  * @member right  coordinate of the right boundary.
44  */
45 var vc_scr = {
46         top : 0,
47         left : 0,
48         bottom : window.innerHeight,
49         right : window.innerWidth
50 },
51
52 /**
53  * vc_xpath_query is a query that processes DOM tree to get clickable objects.
54  * It analyses HTML tree as it is XML and returns matching objects in one of selected forms.
55  */
56 vc_xpath_query = ".//xhtml:input[not(@type='hidden')] | .//xhtml:a | .//xhtml:area | .//xhtml:textarea | .//xhtml:button | .//xhtml:*[" +
57         "@role='link' or @role='button' or @role='checkbox' or @role='combobox' or @role='radio'] |" +
58         " .//xhtml:div[contains(@class, 'ui-btn')] | .//xhtml:div[contains(@class, 'sideBarButton')] | .//xhtml:div[contains(@class, 'buttonCaption')]",
59
60 /**
61  * vc_page_hints holds all hints on website
62  */
63 vc_page_hints = [],
64
65 /**
66  * vc_hint_div is a DIV that gathers all hints
67  */
68 vc_hint_div,
69
70 /**
71  * vc_high_div is a DIV that gathers red highlight boxes
72  */
73 vc_high_div,
74
75 /**
76  * vc_hint_num is used to numerate hints from 1 on every screen they're displayed
77  */
78 vc_hint_num,
79
80 /**
81  * vc_visible_hints holds all hints that are currently visible
82  */
83 vc_visible_hints = [],
84
85 /**
86  * vc_bad_iframes holds iframes that should be highlighted with red color
87  */
88 vc_bad_iframes = [],
89
90 /**
91  * vc_log_area is a textarea element for log texts.
92  */
93 vc_log_area = document.createElement('textarea'),
94
95 /**
96  * vc_html_area is a textarea element to read raw source code of html document in TV.
97  */
98 vc_html_area = undefined,
99
100 /**
101  * vc_asr_result is a div element shows the asr result for debugging.
102  */
103 vc_asr_result = undefined,
104
105 /**
106  * vc_rec_result is a div element shows the recognition result of document searching for debugging.
107  */
108 vc_rec_result = undefined,
109
110 /**
111  * vc_flag_log is a flag variable. If it is true, vc_log_area is created. Otherwise, vc_log_area is nothing.
112  */
113 vc_flag_log = false,
114
115 /**
116  * vc_all_elem is a array that includes whole element in html document for text searching.
117  */
118 vc_all_elem = undefined,
119
120 /**
121  * vc_flag_conflict is a flag variable. When multiple elements are selected, it is true. Otherwise, it is false.
122  */
123 vc_flag_conflict = false,
124
125 /**
126  * vc_flag_hint_exist is a flag variable. When tooltips are already exist, it is true. Otherwise, it is false.
127  */
128 vc_flag_hint_exist = false,
129
130 /**
131  * vc_flag_make_tooltip is a flag variable. When creating tooltip is set, it is true. Otherwise, it is false.
132  */
133 vc_flag_make_tooltip = true,
134
135 /**
136  * vc_text_indicators is an array that contains text indicator elements
137  */
138 vc_text_indicators = [],
139
140 /**
141  * vc_made_hint shows the state tooltip making.
142  */
143 vc_made_hint = false,
144
145 /**
146  * vc_tag_index stores index number of the set of tooltips in web page.
147  * this variable prevents making duplicated tooltips.
148  */
149 vc_tag_index = 0;
150
151 /**
152  * prototypes of overridable custom function
153  */
154 function vc_custom_pre_generate_hints() {
155         vc_print_log('No custom script');
156 }
157
158 function vc_custom_pre_show_hints() {
159         vc_print_log('No custom script');
160 }
161
162 function vc_custom_pre_remove_hints() {
163         vc_print_log('No custom script');
164 }
165
166 function vc_custom_pre_hide_hints() {
167         vc_print_log('No custom script');
168 }
169 /* ======================== */
170
171 /**
172  * vc_custom_add_xpath_query functino adds given condition to xpath query
173  *
174  * @param className  the name of the class of DOM elements
175  * @param DOMtype(optional)  the type name of DOM element
176  *
177  * @remind this function must be called in page specific script
178  */
179 function vc_custom_add_xpath_query(className, DOMtype) {
180         if (undefined == DOMtype) {
181                 DOMtype = 'div';
182         }
183
184         vc_xpath_query += " | .//xhtml:" + DOMtype + "[contains(@class, '" + className + "')]";
185 }
186
187 /**
188  * vc_is_child check if element is a child of other element
189  *
190  * @param child  child to check the parent of
191  * @param parent  to test to
192  *
193  * @return true if elements are related, false otherwise
194  */
195 function vc_is_child(child, parent) {
196         var node = child.parentNode;
197         while (node && node != document.body) {
198                 if (node === parent) {
199                         return true;
200                 }
201                 node = node.parentNode;
202         }
203         return false;
204 }
205
206 /**
207  * vc_is_hidden function checks if the element given as parameter is hidden due to its CSS style
208  *
209  * @param elem element to be checked
210  * @param predecessor predecessor of elem to check visibility if elementFromPoint doesn't return elem
211  *
212  * @return true if element is invisible, false otherwise
213  */
214 function vc_is_hidden(elem, predecessor) {
215         if (elem == undefined) {
216                 return true;
217         }
218
219         /* if predecesor is no found assume parent is one */
220         if (!predecessor && elem.parentNode) {
221                 predecessor = elem.parentNode;
222         }
223         /* check visibility in css style */
224         var doc = elem.ownerDocument,
225         win = doc.defaultView,
226         computedStyle = win.getComputedStyle(elem, null);
227
228         if (computedStyle.getPropertyValue('visibility') !== 'visible' || computedStyle.getPropertyValue('display') === 'none') {
229                 return true;
230         }
231
232         /* object is visible check if it is on current screen */
233         var rect = elem.getBoundingClientRect(),
234         x = rect.left + (rect.width / 2),
235         y = rect.top + (rect.height / 2),
236         point;
237
238         if (y < 0 && x >= 0) {
239                 y = 0;
240         } else if (y < 0 && x < 0) {
241                 x = y = 0;
242         } else if (y >= 0 && x < 0) {
243                 x = 0;
244         }
245
246         point = doc.elementFromPoint(x, y);
247         /* if elementFromPoint returns HTMLBodyElement it probably is a scroll left/right list and it is hidden */
248         if (point === doc.body) {
249                 return true;
250         }
251         /* if elementFromPoint returns predecessor it is visible */
252         if (point && predecessor && vc_is_child(point, predecessor)) {
253                 return false;
254         }
255
256         return true;
257 }
258
259 /**
260  * vc_is_visible function checks if the element provided as argument is currently visible on screen
261  *
262  * @param elem  element to be checked
263  * @param scr  screen information
264  * @param isTextLink  determines if the element is text link
265  *
266  * @return true if visible false otherwise
267  */
268 function vc_is_visible(elem, scr, isTextLink) {
269         if (elem == undefined) {
270                 return false;
271         }
272
273         if (!scr) {
274                 scr = {
275                         top : 0,
276                         left : 0,
277                         bottom : window.innerHeight,
278                         right : window.innerWidth
279                 };
280         }
281         // if only two parameters passed to function assume isTextLink is false
282         isTextLink = typeof isTextLink !== 'undefined' ? isTextLink : false;
283
284         var docy = elem.ownerDocument,
285         win = docy.defaultView,
286         computedStyle = win.getComputedStyle(elem, null);
287
288         /* element is not visible if it is fully transparent except select box  */
289         if (parseFloat(computedStyle.getPropertyValue('opacity')) === 0.0) {
290                 return false;
291         }
292
293         var rect = elem.getBoundingClientRect();
294
295         /* element is not visible if it is not on screen */
296         if (!rect || rect.top >= scr.bottom || rect.bottom <= scr.top || rect.left >= scr.right ||
297                 rect.right <= scr.left) {
298                 return false;
299         }
300
301         /* element is not visible if it is hidden and it is not a text hyperlink */
302         if (!isTextLink && vc_is_hidden(elem, null)) {
303                 return false;
304         }
305
306         return true;
307 }
308
309 /**
310  * vc_make_hint procedure creates invisible hint for element provided as argument
311  *
312  * @param elem  element for which hint is to be created
313  * @param child  if child is passed, the hint will be positioned according to position of child
314  */
315 function vc_make_hint(elem, child) {
316         // vc_print_log(elem);
317         if (false == vc_flag_make_tooltip) {
318                 return;
319         }
320
321         var rect;
322
323         rect = child.getBoundingClientRect();
324
325         if (!rect || elem.vc_tag_index == vc_tag_index) {
326                 return;
327         }
328
329         elem.vc_tag_index = vc_tag_index;
330
331         var doc = elem.ownerDocument;
332
333         /** hint object holds clickable element, type of element and created hint (HTMLSpanElement)
334          * @member elem  clickable target element.
335          * @member type  the type of @elem.
336          * @member child  child element of @elem
337          * @member span  tooltip element of @elem
338          */
339         var hint = {
340                 elem : elem,
341                 type : 'normal',
342                 child : child,
343                 span : null
344         };
345
346         if(elem instanceof HTMLAreaElement){
347                 hint.type = 'area';
348         }
349
350         /* not all input objects are supported */
351         if (elem instanceof HTMLInputElement) {
352                 if (elem.type === 'text' || elem.type === 'password' || elem.type === 'datetime' || elem.type === 'email' ||
353                         elem.type === 'search' || elem.type === 'number' || elem.type === 'url') {
354                         hint.type = 'input';
355                 } else if (elem.type !== 'button' && elem.type !== 'submit' && elem.type !== 'color' && elem.type !== 'radio' &&
356                         elem.type !== 'checkbox' && elem.type !== 'file' && elem.type !== 'submit' && elem.type !== 'image') {
357                         return;
358                 }
359         /* consider TextArea element as input element */
360         } else if (elem instanceof HTMLTextAreaElement) {
361                 hint.type = 'input';
362         }
363
364         /** span object is the visual representation of hint */
365         var span = doc.createElement('span');
366         span.id = 'vc_tooltip';
367         span.className = 'vc_number_tag_normal vc_tooltip_' + hint.type;
368
369         if (hint.type == 'input') {
370                 span.classList.add('vc_tip_tier_first');
371         } else if (rect.height > 30) {
372                 span.classList.add('vc_tip_tier_second');
373         } else {
374                 span.classList.add('vc_tip_tier_third');
375         }
376
377         hint.span = span;
378
379         /* appends hint to vc_hint_div container */
380         vc_hint_div.appendChild(hint.span);
381         vc_page_hints.push(hint);
382 }
383
384 /**
385  * nsResolver function that is used for resolving namespace in webpage document
386  *
387  * @param prefix  prefix of the namespace
388  *
389  * @return namespace url
390  */
391 function nsResolver(prefix) {
392         var namespace = {
393                 'xhtml' : 'http://www.w3.org/1999/xhtml' //add other namespaces if needed
394         };
395         return namespace[prefix] || null;
396 }
397
398 /**
399  * vc_generate_hints function creates hints for all clickable elements on web page
400  *
401  * @param win  window element (can be different if we analyse iframe)
402  */
403 function vc_generate_hints(win) {
404         vc_print_log('== start generate hints' + win);
405         vc_tag_index++;
406
407         /* if win is not passed assume the global window variable */
408         if (!win) {
409                 win = window;
410         }
411
412         var doc;
413
414         try {
415                 doc = win.document;
416         } catch (e) {
417                 vc_print_log('== some error occured in win.document' + e);
418                 return;
419         }
420
421         /* Custom pre process to generate hints */
422         vc_custom_pre_generate_hints();
423
424         var start = vc_page_hints.length;
425
426         vc_hint_div = doc.createElement('div');
427         vc_hint_div.id = 'vc_tooltip_area';
428         vc_hint_div.style.display = 'block';
429
430         vc_text_indicators = [];
431
432         /* return result as snapshot not iterator, due to problems with undefined objects */
433         vc_print_log('== start doc.evaluate');
434         var snapshot = doc.evaluate(vc_xpath_query, doc.body, nsResolver, XPathResult.ORDERED_NODE_SNAPSHOT_TYPE, null);
435         vc_print_log('== snapshot length : ' + snapshot.snapshotLength);
436
437         /* set current screen dimensions */
438         vc_scr = {
439                 top : 0,
440                 left : 0,
441                 bottom : win.innerHeight,
442                 right : win.innerWidth
443         };
444
445         /* analyse if a hint is needed for each returned object */
446         for (var i = 0; i < snapshot.snapshotLength; i++) {
447                 var element = snapshot.snapshotItem(i),
448                 rect = element.getBoundingClientRect();
449
450                 vc_made_hint = false;
451                 /* executed very rarely */
452                 if (rect.width === 0 || rect.height === 0) {
453                         for (var j = 0; j < element.childNodes.length; j++) {
454                                 if (element.childNodes[j].nodeType !== 1) {
455                                         continue;
456                                 }
457
458                                 var style = doc.defaultView.getComputedStyle(element.childNodes[j], null);
459                                 if (style && style.getPropertyValue('float') !== 'none' && vc_is_visible(element.childNodes[j], vc_scr)) {
460                                         vc_make_hint(element, element.childNodes[j]);
461                                         vc_made_hint = true;
462                                         break;
463                                 }
464                         }
465
466                         if (vc_made_hint) {
467                                 continue;
468                         }
469                 }
470
471                 if (vc_is_visible(element, vc_scr) && !element.attributes.disabled) {
472                         if ((element instanceof HTMLButtonElement || element.classList.contains('ui-btn') || element.getAttribute('role') == 'button')) {
473                                 if (element.textContent.trim().replace(/[ `~!‘’@#$%^&*()_|+\-=?;:'",.<>\{\}\[\]\\\/]/gi, '').length > 0) {
474                                         vc_text_indicators[vc_text_indicators.length] = element;
475                                 } else {
476                                         vc_make_hint(element, element);
477                                         vc_made_hint = true;
478                                 }
479                         } else if (element.getAttribute('role') == 'radio' || element.getAttribute('role') == 'checkbox' || element.getAttribute('role') == 'combobox') {
480                                 vc_make_hint(element, element);
481                                 vc_made_hint = true;
482                         /* if the element is an anchor without text, make hint */
483                         } else if (element instanceof HTMLAnchorElement) {
484                                 if (element.textContent.trim().length > 0) {
485                                         vc_text_indicators[vc_text_indicators.length] = element;
486                                 }
487
488                                 var cStyle = window.getComputedStyle(element, false);
489                                 if (cStyle.backgroundImage !== 'none' && cStyle.backgroundImage !== 'inherit') {
490                                         vc_make_hint(element, element);
491                                         vc_made_hint = true;
492                                 } else if (element.textContent.trim().length == 0) {
493                                         /* if element has child with background or image element*/
494                                         if (!vc_made_hint) {
495                                                 var childs = element.querySelectorAll('*');
496                                                 for (var sp = 0; sp < childs.length; ++sp) {
497                                                         if (vc_is_visible(childs[sp], vc_scr)) {
498                                                                 var cstyle = win.getComputedStyle(childs[sp], false);
499                                                                 if (childs[sp].nodeName == 'IMG' || cstyle.overflow == 'hidden'
500                                                                         || (cstyle.backgroundImage !== 'none' && cstyle.backgroundImage !== 'inherit')) {
501                                                                         vc_make_hint(element, childs[sp]);
502                                                                         vc_made_hint = true;
503                                                                         break;
504                                                                 }
505                                                         }
506                                                 }
507                                         }
508
509                                         if (!vc_made_hint) {
510                                                 vc_make_hint(element, element);
511                                                 vc_made_hint = true;
512                                                 continue;
513                                         }
514                                 } else {
515                                         if (isNaN(element.textContent.trim())) {
516                                                 vc_find_img_element(element, null, element);
517                                         }
518                                 }
519                         } else if (element instanceof HTMLAreaElement || element.nodeName == 'INPUT') {
520                                 vc_make_hint(element, element);
521                         } else {
522                                 vc_find_img_element(element, null, element);
523                                 if (vc_made_hint == false) {
524                                         vc_make_hint(element, element);
525                                 }
526                         }
527                 }
528         }
529
530         /* append whole div with hints to body */
531         if (doc.body) {
532                 doc.body.insertBefore(vc_hint_div, doc.body.firstChild);
533
534                 //append all text indicators to body
535                 vc_docs.push({
536                         doc : doc,
537                         start : start,
538                         end : vc_page_hints.length - 1
539                 });
540         }
541
542         /* analyse iframes of the website */
543         if (win === window) {
544                 var frames = document.querySelectorAll('iframe');
545                 for (var f = 0; f < frames.length; f++) {
546                         var elem;
547                         try {
548                                 elem = frames[f].contentWindow.document;
549                         } catch (e) {
550                                 vc_bad_iframes.push(frames[f]);
551                                 continue;
552                         }
553                         vc_scr = {
554                                 top : 0,
555                                 left : 0,
556                                 bottom : win.innerHeight,
557                                 right : win.innerWidth
558                         };
559                         if (elem == undefined) {
560                                 vc_bad_iframes.push(frames[f]);
561                                 continue;
562                         }
563                         if (elem != undefined && !vc_is_visible(frames[f], vc_scr)) {
564                                 continue;
565                         }
566                         // vc_generate_hints(frames[f].contentWindow);
567                 }
568         }
569
570         vc_flag_hint_exist = true;
571         vc_print_log('== end');
572 }
573
574 /**
575  * vc_find_img_element function find element containing image. if found then call a function to make a tooltip.
576  *
577  * @param elem  element to search for text
578  * @param parent  parent element of the @elem
579  * @param snapshotElem  the first @elem when vc_generate_hints calls this function
580  */
581 function vc_find_img_element(elem, parent, snapshotElem) {
582         if (!vc_made_hint) {
583                 if (elem.nodeType == 1) {
584                         var cStyle = document.defaultView.getComputedStyle(elem, false);
585                         if ((vc_is_visible(elem, vc_scr) && cStyle && cStyle.backgroundImage != 'none' && cStyle.backgroundImage != 'inherit' || elem.nodeName == 'IMG')) {
586                                 vc_make_hint(snapshotElem, elem);
587                                 vc_made_hint = true;
588                                 return;
589                         }
590                 }
591
592                 var children = elem.childNodes;
593                 for (var ch = 0; !vc_made_hint && ch < children.length; ch++) {
594                         vc_find_img_element(children[ch], elem, snapshotElem);
595                 }
596         }
597
598 }
599
600 /**
601  * vc_show_hints function displays hints numbering from 1
602  */
603 function vc_show_hints() {
604         /* Custom pre process to show hints */
605         vc_custom_pre_show_hints();
606
607         if (vc_flag_log == true) {
608                 if (vc_asr_result == undefined) {
609                         vc_asr_result = document.createElement('div');
610                         vc_asr_result.id = 'vc_asr_result';
611                         vc_asr_result.innerHTML = 'ASR Result';
612                         document.body.appendChild(vc_asr_result);
613                 }
614
615                 if (vc_rec_result == undefined) {
616                         vc_rec_result = document.createElement('div');
617                         vc_rec_result.id = 'vc_rec_result';
618                         document.body.appendChild(vc_rec_result);
619                 }
620         }
621
622         vc_hint_num = 1;
623         for (var d = 0; d < vc_docs.length; d++) {
624                 var doc = vc_docs[d];
625                 for (var i = doc.start; i <= doc.end; i++) {
626                         var win = doc.doc.defaultView,
627                         hint = vc_page_hints[i],
628                         rect = hint.child.getClientRects()[0];
629
630                         vc_scr = {
631                                 top : 0,
632                                 left : 0,
633                                 bottom : win.innerHeight,
634                                 right : win.innerWidth
635                         };
636
637                         hint.span.style.display = 'block';
638
639                         if (null == rect) {
640                                 continue;
641                         }
642
643                         var leftPos,
644                         topPos,
645                         position_factor_top,
646                         position_factor_left;
647
648                         if (vc_flag_conflict) {
649                                 position_factor_top = 18;
650                                 position_factor_left = 18;
651                                 hint.span.className = 'vc_text_indicator_conflict_normal vc_tooltip_normal vc_tip_tier_second';
652                         } else {
653                                 position_factor_top = 15;
654                                 position_factor_left = 15;
655                         }
656
657                         if (rect.top < position_factor_top) {
658                                 topPos = win.pageYOffset;
659                         } else {
660                                 topPos = rect.top + win.pageYOffset - position_factor_top;
661                         }
662
663                         if (rect.left < position_factor_left) {
664                                 leftPos = win.pageXOffset;
665                         } else {
666                                 leftPos = rect.left + win.pageXOffset - position_factor_left;
667                         }
668
669                         if (hint.type == 'area') {
670                                 coord = hint.elem.coords.split(',');
671                                 leftPos = parseFloat(leftPos) + parseFloat(coord[0]);
672                                 topPos = parseFloat(topPos) + parseFloat(coord[1]);
673                         }
674                         hint.span.style.top = topPos + 'px';
675                         hint.span.style.left = leftPos + 'px';
676                         hint.span.textContent = vc_hint_num;
677
678                         hint.span.style.display = 'block';
679
680                         if (-1 == vc_visible_hints.indexOf(hint)) {
681                                 vc_visible_hints.push(hint);
682                         }
683
684                         vc_hint_num++;
685                 }
686         }
687
688         // for (var bf = 0; bf < vc_bad_iframes.length; ++bf) {
689         //      vc_result_highlight(vc_bad_iframes[bf]);
690         // }
691 }
692
693 /**
694  * vc_remove_hints function removes all hints in the web page. It deletes both visible and hidden hints
695  */
696 function vc_remove_hints() {
697         /* Custom pre process to remove hints */
698         vc_custom_pre_remove_hints();
699
700         vc_remove_highlight();
701
702         for (var d = 0; d < vc_docs.length; d++) {
703                 var doc = vc_docs[d].doc;
704                 var tooltipArea = doc.querySelector('#vc_tooltip_area');
705                 if (null !== tooltipArea && tooltipArea.parentNode) {
706                         tooltipArea.parentNode.removeChild(tooltipArea);
707                 }
708         }
709         vc_visible_hints = [];
710         vc_page_hints = [];
711         vc_docs = [];
712
713         /** if the rotation occured refresh the window information */
714         vc_scr = {
715                 top : 0,
716                 left : 0,
717                 bottom : window.innerHeight,
718                 right : window.innerWidth
719         };
720
721         vc_hint_div = null;
722         vc_flag_hint_exist = false;
723         vc_flag_conflict = false;
724 }
725
726 /**
727  * vc_hide_hints function hides the hints from the screen. Hints elements still exist
728  */
729 function vc_hide_hints() {
730         /* Custom pre process to hide hints */
731         vc_custom_pre_hide_hints();
732
733         for (var i = 0; i < vc_visible_hints.length; i++) {
734                 var hint = vc_visible_hints[i];
735                 if (hint.span.classList.contains('vc_tooltip_focus') == false) {
736                         hint.span.style.display = 'none';
737                         hint.span.style.top = 0;
738                         hint.span.style.left = 0;
739                 }
740         }
741 }
742
743 /**
744  * vc_remove_popup function removes popup.
745  * This function is safe to call if the popup doesnt exist.
746  */
747 function vc_remove_popup() {
748         var node = document.querySelector('#vc_popup');
749         if (null !== node && node.parentNode) {
750                 node.parentNode.removeChild(node);
751         }
752 }
753
754 /**
755  * vc_show_popup function displays a floating div over the web page with text in it for timout milliseconds
756  *
757  * @param text  text to be shown on the popup
758  * @param timeout  time for which the popup should be shown in milliseconds. If timeout is 0 popup must be deleted manually
759  */
760 function vc_show_popup(text, timeout) {
761         /* remove any existing popup */
762         vc_remove_popup();
763
764         /* overlay creates a light grey area over the whole website */
765         var overlay = document.createElement('div');
766         overlay.id = 'vc_popup';
767
768         /* vcpopup is the main popup window, that is centered over the overlay */
769         var vcpopup = document.createElement('div');
770         vcpopup.id = 'vc_popup_content';
771
772         /* content is used to display text and center it vertically inside vcpopup */
773         var content = document.createElement('div');
774         content.style.display = 'table-cell';
775         content.style.fontFamily = '"Open Sans", "Helvetica", sans-serif';
776         content.style.verticalAlign = 'middle';
777         content.innerHTML = text;
778
779         vcpopup.appendChild(content);
780         overlay.appendChild(vcpopup);
781         document.body.appendChild(overlay);
782
783         /* if timeout is set to 0, display popup until not deleted manually */
784         if (timeout !== 0) {
785                 setTimeout(function () {
786                         vc_remove_popup();
787                 }, timeout);
788         }
789
790         return;
791 }
792
793 /**
794  * vc_remove_highlight removes highlight from conflicting links
795  *
796  * @param selectedNum  the number of target tooltip
797  */
798 function vc_remove_highlight(selectedNum) {
799         if (selectedNum) {
800                 var high = document.querySelectorAll('#vc_highlight');
801                 for (var cn = 0; cn < high.length; cn++) {
802                         if ((cn + 1) != selectedNum) {
803                                 high[cn].parentNode.removeChild(high[cn]);
804                         }
805                 }
806         } else {
807                 var highlightArea = document.querySelector('#vc_highlight_area');
808                 if (highlightArea) {
809                         highlightArea.parentNode.removeChild(highlightArea);
810                 }
811         }
812 }
813
814 /**
815  * vc_result_highlight creates highlight box over elem
816  *
817  * @param elem  element to be highlighted
818  */
819 function vc_result_highlight(elem) {
820         var doc = elem.ownerDocument,
821         rect;
822
823         if (vc_is_visible(elem) == false && elem.querySelector('img')) {
824                 rect = elem.querySelector('img').getClientRects()[0];
825         } else {
826                 rect = elem.getClientRects()[0];
827         }
828
829         if (!rect) {
830                 return;
831         }
832
833         vc_high_div = document.querySelector('#vc_highlight_area');
834
835         if (!vc_high_div) {
836                 vc_high_div = doc.createElement('div');
837                 vc_high_div.id = 'vc_highlight_area';
838                 doc.body.appendChild(vc_high_div);
839         }
840
841         var high_span = doc.createElement('div');
842         high_span.id = 'vc_highlight';
843
844         /* top left position of the element */
845         var leftPos = (rect.left > vc_scr.left ? rect.left : vc_scr.left);
846         var topPos = (rect.top > vc_scr.top ? rect.top : vc_scr.top);
847
848         /* adjust top left position with page scroll */
849         topPos += window.pageYOffset - 3;
850         leftPos += window.pageXOffset - 3;
851
852         high_span.style.left = leftPos + 'px';
853         high_span.style.top = topPos + 'px';
854         high_span.style.width = rect.width + 'px';
855         high_span.style.height = (rect.height + 6) + 'px';
856
857         /* if element's dimensions are 0x0 create highlight for it's children */
858         if (rect.width === 0 || rect.height === 0) {
859                 var height = topPos + rect.height;
860                 var width = leftPos + rect.width;
861                 for (var i = 0; i < elem.children.length; i++) {
862                         var child = elem.children[i];
863                         var chRect = child.getClientRects()[0];
864                         if (!chRect) {
865                                 continue;
866                         }
867                         if (chRect.top + chRect.height > height) {
868                                 height = chRect.top + chRect.height;
869                         }
870                         if (chRect.left + chRect.width > width) {
871                                 width = chRect.left + chRect.width;
872                         }
873                 }
874                 high_span.style.height = height - topPos + 'px';
875                 high_span.style.width = width - leftPos + 'px';
876         }
877
878         vc_high_div.appendChild(high_span);
879 }
880
881 /**
882  * vc_generate_conflict_hints function creates hints for all conflicting highlighted hints
883  */
884 function vc_generate_conflict_hints() {
885         vc_hint_div = document.querySelector('#vc_tooltip_area');
886
887         if (!vc_hint_div) {
888                 vc_hint_div = document.createElement('div');
889                 vc_hint_div.id = 'vc_tooltip_area';
890                 document.body.insertBefore(vc_hint_div, document.body.firstChild);
891         }
892
893         vc_scr = {
894                 top : 0,
895                 left : 0,
896                 bottom : window.innerHeight,
897                 right : window.innerWidth
898         };
899
900         /* Conflict links */
901         var conflicts = vc_conflict_links;
902
903         for (var i = 0; i < conflicts.length; i++) {
904                 var elem = conflicts[i];
905                 var rect;
906
907                 vc_result_highlight(elem);
908                 if (vc_is_visible(elem, vc_scr) == false && elem.querySelector('img') != null) {
909                         rect = elem.querySelector('img').getClientRects()[0];
910                 } else {
911                         rect = elem.getClientRects()[0];
912                 }
913
914                 if (!rect) {
915                         return;
916                 }
917
918                 var leftPos,
919                 topPos,
920                 position_factor_top = 20, //[TODO]move at proper place
921                 position_factor_left = 28,
922                 hint = {},
923                 span = document.createElement('span');
924                 span.id = 'vc_tooltip';
925
926                 if (rect.top < position_factor_top) {
927                         topPos = window.pageYOffset + 'px';
928                 } else {
929                         topPos = rect.top + window.pageYOffset - position_factor_top + 'px';
930                 }
931
932                 if (rect.left < position_factor_left) {
933                         leftPos = window.pageXOffset + 'px';
934                 } else {
935                         leftPos = rect.left + window.pageXOffset - position_factor_left + 'px';
936                 }
937
938                 /* tooltip style, !please keep styles sorted */
939                 hint.span = span;
940                 hint.span.style.top = topPos;
941                 hint.span.style.left = leftPos;
942                 vc_hint_div.appendChild(hint.span);
943
944                 hint.elem = elem;
945                 hint.child = vc_high_div.childNodes[i];
946                 vc_page_hints[vc_page_hints.length] = hint;
947         }
948
949         vc_docs.push({
950                 doc : document,
951                 start : 0,
952                 end : vc_page_hints.length - 1
953         });
954
955         vc_flag_hint_exist = true;
956         vc_flag_conflict = true;
957         vc_conflict_timer = setTimeout(vc_remove_hints, 5000);
958
959         vc_show_hints();
960 }
961
962 /**
963  * vc_trigger_event function makes custom DOM event
964  *
965  * @param node  target element taking event
966  * @param eventType  type of the custom event
967  */
968 function vc_trigger_event(node, eventType) {
969         try {
970                 var clickEvent = new Event(eventType);
971                 node.dispatchEvent(clickEvent);
972         } catch (e) {
973                 console.log('error ouccured', e);
974         }
975 }
976
977 /**
978  * vc_do_action function creates event for selected element.
979  *
980  * @param targetElem  selected element
981  * @param numberTag  number of selected tooltip
982  * @param value(option)  text entered into selected input element
983  *
984  * @return array including coordinates of the @targetElem and the number of targetElem.
985  */
986 function vc_do_action(targetElem, numberTag, value) {
987         vc_print_log('=== Inside vc_do_action');
988         vc_print_log(targetElem.elem.outerHTML);
989
990         var elem = targetElem.elem,
991         type = targetElem.type,
992         position,
993         effect;
994
995         if (!targetElem) {
996                 return;
997         }
998
999         /* Create click effect element */
1000         effect = document.createElement('div');
1001         effect.id = 'vc_click_effect';
1002
1003         if (numberTag != undefined) {
1004                 position = numberTag.getBoundingClientRect();
1005                 effect.style.left = (position.left + (position.width / 2) - 35) + 'px'
1006                 effect.style.top = (position.top + (position.height / 2) - 35) + 'px'
1007
1008                 numberTag.classList.add('vc_tooltip_focus');
1009                 numberTag.style.display = 'block';
1010
1011                 //conflicts
1012                 if (vc_flag_conflict) {
1013                         vc_remove_highlight(numberTag.textContent.trim());
1014                 }
1015                 vc_hide_hints();
1016         } else {
1017                 position = elem.getClientRects()[0];
1018                 effect.style.left = (position.left - 35) + 'px'
1019                 effect.style.top = (position.top - 35) + 'px'
1020
1021                 //text indicators
1022                 vc_result_highlight(elem);
1023                 elem.classList.add('vc_text_focus');
1024
1025                 vc_text_indicators[vc_text_indicators.length] = elem;
1026         }
1027
1028         document.body.insertBefore(effect, document.body.firstChild);
1029
1030         /* Occurring events */
1031         try {
1032                 if (type == 'input' && value != undefined) {
1033                         setTimeout(function () {
1034                                 elem.value = value;
1035                                 vc_trigger_event(elem, 'keyup');
1036                                 vc_trigger_event(elem, 'input');
1037                                 try {
1038                                         elem.form.submit();
1039                                 } catch (e) {
1040                                         console.log(e);
1041                                 }
1042
1043                                 document.body.removeChild(effect);
1044                                 vc_remove_hints();
1045                         }, 1500);
1046
1047                         return [0, 0, 0]
1048                 }
1049
1050                 setTimeout(function () {
1051                         if (vc_asr_result != undefined) {
1052                                 vc_asr_result.parentElement.removeChild(vc_asr_result);
1053                                 vc_asr_result = undefined;
1054                         }
1055                         if (vc_rec_result != undefined) {
1056                                 vc_rec_result.parentElement.removeChild(vc_rec_result);
1057                                 vc_rec_result = undefined;
1058                         }
1059
1060                         if (numberTag == undefined) {
1061                                 elem.classList.remove('vc_text_focus');
1062                         }
1063
1064                         document.body.removeChild(effect);
1065                         vc_remove_hints();
1066
1067                         elem.blur();
1068                         elem.focus();
1069
1070                         vc_print_log('=== Click Finish');
1071                 }, 2000);
1072
1073                 var rect = elem.getClientRects()[0],
1074                 x = rect.left + (rect.width / 2),
1075                 y = rect.top + (rect.height / 2);
1076                 if (null == rect) {
1077                         vc_print_log('[ERROR] Target element is not valid')
1078                         return [-1, 0, 0];
1079                 }
1080
1081                 if (x < 0) {
1082                         x = 0;
1083                 }
1084                 if (y < 0) {
1085                         y = 0;
1086                 }
1087                 return [1, x / window.innerWidth, y / window.innerHeight];
1088         } catch (e) {
1089                 console.log(e);
1090                 return [-1, 0, 0];
1091         }
1092 }
1093
1094 /**
1095  * vc_click function triggers click on element connected to cmd and param. Assumption is made that tooltips are numbers!
1096  *
1097  * @param cmd  tooltip tag number from voice-control
1098  * @param param  text parameter from voice-control
1099  */
1100 function vc_click(cmd, param) {
1101         vc_print_log('== start click cmd = ' + cmd + ', param = ' + param + ', visible tags = ' + vc_visible_hints.length);
1102
1103         if (vc_flag_log == true) {
1104                 if (vc_asr_result != undefined) {
1105                         vc_asr_result.innerHTML = param;
1106                 }
1107
1108                 setTimeout(function () {
1109                         if (vc_asr_result != undefined) {
1110                                 vc_asr_result.parentElement.removeChild(vc_asr_result);
1111                                 vc_asr_result = undefined;
1112                         }
1113                         if (vc_rec_result != undefined) {
1114                                 vc_rec_result.parentElement.removeChild(vc_rec_result);
1115                                 vc_rec_result = undefined;
1116                         }
1117                 }, 2500);
1118         }
1119
1120         /* pre-defined rule checker */
1121         if (vc_check_web_control(param) == true) {
1122                 vc_remove_hints();
1123
1124                 return [0, 0, 0];
1125         }
1126
1127         // if cmd has a numerical value
1128         if (isNaN(cmd) == false) {
1129                 vc_print_log('== numbering tag click');
1130
1131                 // when cmd is floating point value without parameter
1132                 // search exactly the same text
1133                 if (Number.isInteger(cmd) == false && param == '') {
1134                         for (var i = 0; i < vc_text_indicators.length; ++i) {
1135                                 if (vc_text_indicators[i].textContent.trim().indexOf(cmd) != -1) {
1136                                         return vc_do_action({
1137                                                 elem : vc_text_indicators[i]
1138                                         });
1139                                 }
1140                         }
1141
1142                         var list = vc_selector([cmd.toString()]);
1143
1144                         for (var i = 0; i < list.length; i++) {
1145                                 if (list[i].childElementCount == 0 && list[i].textContent.trim().indexOf(cmd) != -1) {
1146                                         return vc_do_action({
1147                                                 elem : list[i]
1148                                         });
1149                                 }
1150                         }
1151                 }
1152
1153                 // when cmd is valid integer value
1154                 if (Number.isInteger(cmd) == true && cmd <= vc_visible_hints.length) {
1155                         var hint = vc_visible_hints[cmd - 1];
1156
1157                         // insert text into input element
1158                         if (hint.type === 'input' && param != '') {
1159                                 return vc_do_action(hint, hint.span, param);
1160                         } else if (param == '') {
1161                                 if (!vc_flag_conflict) {
1162                                         vc_conflict_links = [];
1163                                         vc_conflict_links.push(hint.elem);
1164
1165                                         for (var i = 0; i < vc_text_indicators.length; ++i) {
1166                                                 if (vc_text_indicators[i].textContent.trim() == cmd) {
1167                                                         vc_conflict_links.push(vc_text_indicators[i]);
1168                                                 }
1169                                         }
1170
1171                                         if (vc_conflict_links.length > 1) {
1172                                                 vc_remove_hints();
1173                                                 vc_generate_conflict_hints();
1174                                                 return [vc_conflict_links.length, 0, 0];
1175                                         }
1176                                 }
1177
1178                                 return vc_do_action(hint, hint.span);
1179                         }
1180                 }
1181
1182                 // when there is no matched tooltip
1183                 vc_remove_hints();
1184
1185                 return vc_search_text(cmd.toString().concat(' ', param).trim());
1186         } else {
1187                 vc_remove_hints();
1188
1189                 return vc_search_text(param);
1190         }
1191 }
1192
1193 /**
1194  * vc_search_text function search the element that include same text with @param.
1195  *
1196  * @param param  param from voice-control.
1197  */
1198 function vc_search_text(param) {
1199         /* phase 1. search full text in the webpage */
1200         /* first, compare with links in html documents */
1201         vc_print_log('=== start searching(text level)');
1202
1203         if (vc_flag_log == true) {
1204                 vc_rec_result.style.background = 'rgba(0, 200, 100, 1)';
1205         }
1206
1207         vc_scr = {
1208                 top : 0,
1209                 left : 0,
1210                 bottom : window.innerHeight,
1211                 right : window.innerWidth
1212         };
1213
1214         vc_conflict_links = [];
1215
1216         for (var i = 0; i < vc_text_indicators.length; ++i) {
1217                 if (vc_is_visible(vc_text_indicators[i], vc_scr, true) &&
1218                         vc_text_indicators[i].textContent.replace(/[ `~!‘’@#$%^&*()_|+\-=?;:'",.<>\{\}\[\]\\\/]/gi, '').toLowerCase().indexOf(param.replace(/ /g, '').toLowerCase()) !== -1) {
1219                         vc_conflict_links.push(vc_text_indicators[i]);
1220                 }
1221         }
1222
1223         if (vc_conflict_links.length == 1) {
1224                 /* if there is one result */
1225                 return vc_do_action({
1226                         elem : vc_conflict_links[0]
1227                 });
1228         } else if (vc_conflict_links.length > 1) {
1229                 vc_generate_conflict_hints();
1230
1231                 return [vc_conflict_links.length, 0, 0];
1232         }
1233
1234         /* second, compare with whole text of elements in html documents */
1235         var resultTokenArr = param.replace(/[`~!‘’@#$%^&*()_|+\-=?;:'",.<>\{\}\[\]\\\/]/gi, '').split(' '),
1236         el = vc_selector(resultTokenArr),
1237         preStr = '******';
1238
1239         for (var i = 0; el.length > i; i++) {
1240                 var temp = el[i];
1241
1242                 if (temp.childElementCount === 0) {
1243                         var curStr = temp.textContent.replace(/[`~!‘’@#$%^&*()_|+\-=?;:'",.<>\{\}\[\]\\\/]/gi, '');
1244                         if (curStr == preStr || vc_is_visible(temp) == false) {
1245                                 continue;
1246                         }
1247
1248                         preStr = curStr;
1249
1250                         vc_conflict_links.push(temp);
1251                 }
1252         }
1253
1254         if (vc_conflict_links.length == 1) {
1255                 return vc_do_action({
1256                         elem : vc_conflict_links[0]
1257                 });
1258         } else if (vc_conflict_links.length > 1) {
1259                 vc_generate_conflict_hints();
1260
1261                 return [vc_conflict_links.length, 0, 0];
1262         } else {
1263                 /*
1264                  * vc_search_word depend on the voice control language.
1265                  * This function increase the accuracy of the searching result using word and letter level searching.
1266                  * If the language is changed, the definition of the function will be changed by reloading the .js file.
1267                  */
1268                 temp = vc_search_word(param, true);
1269                 if (temp != undefined) {
1270                         return vc_do_action({
1271                                 elem : temp
1272                         });
1273                 } else {
1274                         //vc_show_popup('There is no such kind of string.<br>(' + param + ')', 1500);
1275                         vc_remove_hints();
1276
1277                         return [-1, 0, 0];
1278                 }
1279         }
1280 }
1281
1282 /**
1283  * vc_scroll_event_firing function move the scroll.
1284  *
1285  * @param evt  keyword to move the scroll.
1286  */
1287 function vc_scroll_event_firing(evt) {
1288         if (evt == 'DOWN') {
1289                 window.scrollBy(0, 500);
1290         } else if (evt == 'UP') {
1291                 window.scrollBy(0, -500);
1292         } else if (evt == 'TOP') {
1293                 window.scrollTo(0, 0);
1294         }
1295 }
1296
1297 /**
1298  * vc_print_html function print out log on vc_log_area and console for debug.
1299  * If vc_flag_log is not true, then the logs will only print on console.
1300  *
1301  * @param text  log text to print out.
1302  */
1303 function vc_print_log(text) {
1304         var d = new Date();
1305         var time = d.getHours() + ':' + d.getMinutes() + ':' + d.getSeconds() + ':' + d.getMilliseconds();
1306         console.log(time, '[', vc_print_log.caller.name, ']', text);
1307
1308         if (vc_flag_log == true) {
1309                 vc_log_area.value += time + ' [' + vc_print_log.caller.name + '] ' + text + '\n';
1310         }
1311 }
1312
1313 /**
1314  * vc_print_html function print out raw source of the html document for debug.
1315  */
1316 function vc_print_html() {
1317         if (vc_html_area == undefined) {
1318                 vc_html_area = document.createElement('textarea');
1319                 vc_html_area.disabled = true;
1320                 vc_html_area.id = 'vc_html_area';
1321
1322                 document.body.appendChild(vc_html_area);
1323
1324                 vc_html_area.value = location.href.toString() + '\n' + document.querySelector('html').innerHTML;
1325         } else {
1326                 document.body.removeChild(vc_html_area);
1327                 vc_html_area = undefined;
1328         }
1329 }
1330
1331 /**
1332  * vc_search_text function is called by voice-control-webview.cpp.
1333  * this function call some group of functions refered to @phase.
1334  *
1335  * @param phase  key value to call a group of functions.
1336  * @param data  function data from voice-control-webview.cpp.
1337  */
1338 function vc_request_action(phase, data) {
1339         vc_print_log('phase :' + phase + ',data :' + data);
1340         if ('SHOW_TOOLTIP' == phase) {
1341                 clearTimeout(vc_conflict_timer);
1342
1343                 /* create & show tooltips to recognize the voice */
1344                 if (!vc_flag_conflict && false == vc_flag_hint_exist) {
1345                         vc_remove_hints();
1346                         vc_generate_hints();
1347                 }
1348                 vc_show_hints();
1349         } else if ('HIDE_TOOLTIP' == phase) {
1350                 /* hide tooltips */
1351                 if (!vc_flag_conflict) {
1352                         vc_hide_hints();
1353                 } else {
1354                         clearTimeout(vc_conflict_timer);
1355                         vc_conflict_timer = setTimeout(vc_remove_hints, 5000);
1356                 }
1357         } else if ('RESULT' == phase) {
1358                 /* do action by the result */
1359                 vc_all_elem = document.querySelectorAll('body *:not(script)');
1360                 var result = vc_correct_parameter(data);
1361
1362                 return vc_click(result.cmd, result.param);
1363         } else if ('REMOVE_TOOLTIP' == phase) {
1364                 clearTimeout(vc_conflict_timer);
1365                 vc_remove_hints();
1366         } else {
1367                 return false;
1368         }
1369         return true;
1370 }
1371
1372 /**
1373  * vc_selector function is a selector function to find the elements include whole text in @strArr.
1374  *
1375  * @param strArr  group of strings to find elements.
1376  *
1377  * ex) vc_selector(['abc', 'def']);
1378  */
1379 function vc_selector(strArr) {
1380         var result = [];
1381         for (var i = 0; i < vc_all_elem.length; i++) {
1382                 var temp = vc_all_elem[i].textContent.replace(/[`~!‘’@#$%^&*()_|+\-=?;:'",.<>\{\}\[\]\\\/]/gi, '').toLowerCase();
1383                 var j;
1384
1385                 for (j = 0; j < strArr.length; j++) {
1386                         if (temp.includes(strArr[j].toLowerCase()) == false) {
1387                                 break;
1388                         }
1389                 }
1390
1391                 if (strArr.length == j && vc_is_visible(vc_all_elem[i], null, true)) {
1392                         result.push(vc_all_elem[i]);
1393                 }
1394         }
1395
1396         return result;
1397 }
1398
1399 /**
1400  * vc_get_url_path function returns url path of the view.
1401  *
1402  * @return part of the url(host name + path name). it is used to read page specific script.
1403  */
1404 function vc_get_url_path() {
1405         var hostName = document.location.hostname;
1406         var pathName = document.location.pathname;
1407
1408         pathName = pathName.replace(/\//gi, '.');
1409
1410         return hostName + '/' + pathName;
1411 }
1412
1413 /**
1414  * vc_get_conflict_status function returns the conflict status.
1415  *
1416  * @return 1 if vc_flag_conflict is true. Otherwise 0.
1417  */
1418 function vc_get_conflict_status() {
1419         if (vc_flag_conflict) {
1420                 return 1;
1421         }
1422
1423         return 0;
1424 }
1425
1426 /**
1427  * vc_set_make_tooltip function sets the vc_flag_make_tooltip.
1428  *
1429  * @param makeTooltip  If it is 1, then set vc_flag_make_tooltip as true. Otherwise false.
1430  */
1431 function vc_set_make_tooltip(makeTooltip) {
1432         if (1 == makeTooltip) {
1433                 vc_flag_make_tooltip = true;
1434         } else {
1435                 vc_flag_make_tooltip = false;
1436         }
1437 }
1438
1439 /**
1440  * vc_init function initialize some elements and styles to use voice control.
1441  */
1442 function vc_init() {
1443         /* log element initialize */
1444         if (vc_flag_log) {
1445                 vc_log_area.disabled = true;
1446                 vc_log_area.id = 'vc_log_area';
1447                 vc_log_area.style.visibility = 'hidden';
1448
1449                 document.body.appendChild(vc_log_area);
1450         }
1451
1452         /* add tooltip style element */
1453         var vc_style_node = document.createElement('style');
1454         var vc_style_text = document.createTextNode(
1455                         '#vc_tooltip_area {\
1456                                 left : 0px;\
1457                                 position : absolute;\
1458                                 pointer-events: none;\
1459                                 top : 0px;\
1460                                 z-index : 2147483647;\
1461                         }\
1462                         #vc_html_area, #vc_log_area {\
1463                                 background-color : rgba(0, 0, 0, 0.5) !important;\
1464                                 color : white !important;\
1465                                 font-size : 14px;\
1466                                 height : 600px;\
1467                                 left : 50px;\
1468                                 padding : 10px 10px 10px 10px;\
1469                                 position : fixed;\
1470                                 top : 50px;\
1471                                 width : 800px;\
1472                                 z-index : 2147483647;\
1473                         }\
1474                         #vc_popup_content {\
1475                                 background-color : #87cff7;\
1476                                 bottom : 0px;\
1477                                 border-radius : 20px;\
1478                                 box-shadow : 0 2px 6px rgba(0, 0, 0, 0.3), 0 3px 8px rgba(0, 0, 0, 0.2);\
1479                                 color : white;\
1480                                 display : table;\
1481                                 font-size : 1.5em;\
1482                                 height : 100px;\
1483                                 left : 0px;\
1484                                 line-height : 1.5em;\
1485                                 margin : auto;\
1486                                 opacity : 1;\
1487                                 overflow : hidden;\
1488                                 position : absolute;\
1489                                 right : 0px;\
1490                                 text-align : center;\
1491                                 top : 0px;\
1492                                 width : 500px;\
1493                                 z-index : 2147483647;\
1494                         }\
1495                         #vc_popup {\
1496                                 background-color : rgba(0,0,0,0.2);\
1497                                 bottom : 0px;\
1498                                 left : 0px;\
1499                                 position : fixed;\
1500                                 right : 0px;\
1501                                 top : 0px;\
1502                                 z-index : 2147483647;\
1503                         }\
1504                         #vc_highlight_area {\
1505                                 left : 0px;\
1506                                 position : absolute;\
1507                                 pointer-events: none;\
1508                                 top : 0px;\
1509                                 z-index : 2147483646;\
1510                         }\
1511                         #vc_highlight {\
1512                                 border-radius: 5px;\
1513                                 font-size : 20px;\
1514                                 padding : 0 3px;\
1515                                 position : absolute;\
1516                                 pointer-events: none;\
1517                                 word-break : normal;\
1518                                 background-color: rgba(0, 234, 255, 0.2);\
1519                         }\
1520                         #vc_click_effect {\
1521                                 border-radius: 70px;\
1522                                 width: 70px;\
1523                                 height: 70px;\
1524                                 pointer-events: none;\
1525                                 position: fixed;\
1526                                 z-index : 2147483647;\
1527                                 background: linear-gradient(141deg, rgba(15, 185, 175, 0.6) 0%, rgba(30, 200, 220, 0.6) 51%, rgba(45, 180, 230, 0.6) 75%);\
1528                         }\
1529                         .vc_number_tag_normal {\
1530                                 border : 2px solid;\
1531                                 border-color : rgba(255, 255, 255, 0);\
1532                                 border-radius : 5px;\
1533                                 box-shadow : 0px 2px 2px rgba(0, 0, 0, 0.3);\
1534                                 position: absolute;\
1535                                 pointer-events: none;\
1536                                 text-align: center;\
1537                                 font-family: "Samsung0ne600";\
1538                                 color: #ffffff;\
1539                                 z-index : 2147483647;\
1540                                 word-break : normal;\
1541                         }\
1542                         .vc_text_indicator_conflict_normal {\
1543                                 border: 2px solid;\
1544                                 border-color: rgba(255, 255, 255, 0);\
1545                                 border-radius: 20px;\
1546                                 box-shadow: 0px 2px 2px rgba(0, 0, 0, 0.3);\
1547                                 position: absolute;\
1548                                 pointer-events: none;\
1549                                 text-align: center;\
1550                                 color: #ffffff;\
1551                                 font-family: "Samsung0ne600";\
1552                                 z-index: 2147483647;\
1553                         }\
1554                         .vc_tooltip_focus {\
1555                                 border-color: rgba(255, 255, 255, 1);\
1556                         }\
1557                         .vc_text_focus {\
1558                                 color: #ff0000 !important;\
1559                                 font-weight: bolder !important;\
1560                         }\
1561                         #vc_asr_result {\
1562                                 background : rgba(0, 0, 0, 0.8);\
1563                                 border-radius : 20px;\
1564                                 color : white;\
1565                                 font-size : 25px;\
1566                                 height : 35px;\
1567                                 padding-top : 10px;\
1568                                 padding-bottom : 10px;\
1569                                 position : absolute;\
1570                                 text-align : center;\
1571                                 top : 10px;\
1572                                 right : 10px;\
1573                                 width : 550px;\
1574                                 z-index : 2147483647;\
1575                         }\
1576                         #vc_rec_result {\
1577                                 border-radius : 40px;\
1578                                 height : 40px;\
1579                                 position : absolute;\
1580                                 top : 17px;\
1581                                 right : 510px;\
1582                                 width : 40px;\
1583                                 z-index : 2147483647;\
1584                         }\
1585                         .vc_tooltip_input {\
1586                                 background-color : rgba(60, 140, 250, 0.75);\
1587                         }\
1588                         .vc_tooltip_normal, .vc_tooltip_area {\
1589                                 background-color : rgba(60, 185, 165, 0.75);\
1590                         }\
1591                         .vc_tip_tier_first {\
1592                                 font-size: 22px;\
1593                                 line-height: 24px;\
1594                                 width: 32px;\
1595                                 height: 26px;\
1596                         }\
1597                         .vc_tip_tier_second {\
1598                                 font-size: 19px;\
1599                                 line-height: 22px;\
1600                                 width: 28px;\
1601                                 height: 22px;\
1602                         }\
1603                         .vc_tip_tier_third {\
1604                                 font-size: 14px;\
1605                                 line-height: 16px;\
1606                                 width: 21px;\
1607                                 height: 16px;\
1608                         }\
1609                         @keyframes vc_tooltip_show {\
1610                                 0% {\
1611                                         opacity: 0;\
1612                                 }\
1613                                 100% {\
1614                                         opacity: 1;\
1615                                 }\
1616                         }\
1617                         @keyframes vc_tooltip_click {\
1618                                 0% {\
1619                                         box-shadow: 0 0 8px 6px rgba(60, 220, 180, 0), 0 0 0px 0px rgba(255,255,255,1), 0 0 0px 0px rgba(60, 220, 180, 0);\
1620                                 }\
1621                                 10% {\
1622                                         box-shadow: 0 0 8px 6px rgba(60, 220, 180, 1), 0 0 3px 5px rgba(255,255,255,1), 0 0 6px 10px rgba(60, 220, 180, 1);\
1623                                 }\
1624                                 100% {\
1625                                         box-shadow: 0 0 8px 6px rgba(60, 220, 180, 0), 0 0 0px 20px rgba(255,255,255,0.5), 0 0 0px 20px rgba(60, 220, 180, 0);\
1626                                 }\
1627                         }\
1628                         @keyframes vc_click_effect {\
1629                                 0% {\
1630                                         transform: scale(0.3, 0.3);\
1631                                         opacity: 0;\
1632                                 }\
1633                                 10% {\
1634                                         transform: scale(0.5, 0.5);\
1635                                         opacity: 0.5;\
1636                                 }\
1637                                 100% {\
1638                                         transform: scale(1, 1);\
1639                                         opacity: 1;\
1640                                 }\
1641                         }');
1642         vc_style_node.appendChild(vc_style_text);
1643         document.head.appendChild(vc_style_node);
1644
1645         var frames = window.frames;
1646
1647         for (var i = 0; i < frames.length; i++) {
1648                 try {
1649                         var doc = frames[i].document;
1650                         var vc_frame_style_node = doc.createElement('style');
1651                         var vc_frame_style_text = doc.createTextNode(vc_style_node.textContent);
1652
1653                         vc_frame_style_node.appendChild(vc_frame_style_text);
1654                         doc.head.appendChild(vc_frame_style_node);
1655                 } catch (e) {
1656                         continue;
1657                 }
1658         }
1659
1660         /* remove indicators on scroll */
1661         window.addEventListener('scroll', function () { //[TODO] need to remove the listener
1662                 vc_remove_hints();
1663         }, false);
1664 }
1665
1666 vc_init();