1
2jQuery(document).ready(function() {
3
4jQuery('.help-btn').on('click', function(e) {
5  jQuery('#help-modal .modal-body').load(jQuery(this).data('help'), function(){
6    jQuery.getScript('../script.js');
7  });
8});
9
10var $component = jQuery('#component'),
11    $output    = jQuery('#output'),
12    $preview   = jQuery('#preview');
13
14$component.val(jQuery('ul.nav .active a').data('component'));
15
16jQuery('ul.nav a').on('click', function() {
17
18  $component.val(jQuery(this).data('component'));
19  jQuery('.preview-box').removeClass('hide');
20
21  jQuery(document).trigger('popup:reset');
22  jQuery(document).trigger('popup:buildTag');
23
24});
25
26jQuery(document).on('popup:reset', function() {
27  jQuery('form').each(function(){
28    jQuery(this)[0].reset();
29  });
30  $output.val('');
31  $preview.text('');
32});
33
34jQuery(document).on('popup:buildTag', function() {
35
36  var component = $component.val(),
37      tag       = [ '<', component ];
38
39  jQuery('#tab-'+component+' .attribute').each(function() {
40
41    var $attribute = jQuery(this),
42        data       = $attribute.data();
43
44    if (data.attributeType == 'boolean') {
45      if ($attribute.find('input:checked').val()) {
46        tag.push(' '+ data.attributeName + '="true"');
47      }
48    } else {
49      if ($attribute.find('input,select').val()) {
50        tag.push(' '+ data.attributeName + '="' + $attribute.find('input,select').val() + '"');
51      }
52    }
53
54  });
55
56  tag.push('></'+component+'>');
57
58  $output.val(tag.join(''));
59  $preview.text(tag.join(''));
60
61});
62
63jQuery('#btn-reset').on('click', function() {
64  jQuery(document).trigger('popup:reset');
65  jQuery(document).trigger('popup:buildTag');
66});
67
68jQuery('form input,form select').on('change', function() {
69  jQuery(document).trigger('popup:buildTag');
70});
71
72jQuery('#btn-preview, #btn-insert').on('click', function() {
73
74  jQuery(document).trigger('popup:buildTag');
75
76  if (jQuery(this).attr('id') === 'btn-insert') {
77    opener.insertAtCarret('wiki__text', $output.val());
78    opener.focus();
79  }
80
81});
82
83});