[CLAMP-1] Initial ONAP CLAMP seed code commit
[clamp.git] / src / main / resources / META-INF / resources / designer / lib / index.js
1 $(function() {
2         var $wrapper = $('#wrapper');
3
4         // theme switcher
5         var theme_match = String(window.location).match(/[?&]theme=([a-z0-9]+)/);
6         var theme = (theme_match && theme_match[1]) || 'default';
7         var themes = ['default','legacy','bootstrap2','bootstrap3'];
8         $('head').append('<link rel="stylesheet" href="css/selectize.' + theme + '.css">');
9
10         var $themes = $('<div>').addClass('theme-selector').insertAfter('h1');
11         for (var i = 0; i < themes.length; i++) {
12                 $themes.append('<a href="?theme=' + themes[i] + '"' + (themes[i] === theme ? ' class="active"' : '') + '>' + themes[i] + '</a>');
13         }
14
15         // display scripts on the page
16         $('script', $wrapper).each(function() 
17         {
18                 var code = this.text;
19                 if (code && code.length) {
20                         var lines = code.split('\n');
21                         var indent = null;
22
23                         for (var i = 0; i < lines.length; i++) {
24                                 if (/^[  ]*$/.test(lines[i])) continue;
25                                 if (!indent) {
26                                         var lineindent = lines[i].match(/^([    ]+)/);
27                                         if (!lineindent) break;
28                                         indent = lineindent[1];
29                                 }
30                                 lines[i] = lines[i].replace(new RegExp('^' + indent), '');
31                         }
32
33                         var code = $.trim(lines.join('\n')).replace(/   /g, '    ');
34                         var $pre = $('<pre>').addClass('js').text(code);
35                         $pre.insertAfter(this);
36                 }
37         });
38
39         // show current input values
40         $('select.selectized,input.selectized', $wrapper).each(function() 
41     {
42                 var $container = $('<div>').addClass('value').html('Current Value: ');
43                 var $value = $('<span>').appendTo($container);
44                 var $input = $(this);
45                 var update = function(e) { $value.text(JSON.stringify($input.val())); }
46
47                 $(this).on('change', update);
48                 update();
49
50                 $container.insertAfter($input);
51         });
52 });