Projet

Général

Profil

Paste
Télécharger (6,57 ko) Statistiques
| Branche: | Révision:

root / htmltest / sites / all / modules / sweaver / plugins / sweaver_plugin_advanced / sweaver_plugin_watchdog.js @ dc45a079

1

    
2
/**
3
 * Sweaver WatchDog
4
 * Plugin used to list all modification made in the editor
5
 * Each modification can be hidden or deleted then
6
 * A hidden property is not displayed but is still saved so that the user can, at any moment, activate it
7
 */
8

    
9
(function ($) {
10
    
11
Drupal.Sweaver = Drupal.Sweaver || {};
12

    
13
/**
14
 * Hook onload behavior
15
 */
16
$(document).ready(function() {  
17
  Drupal.Sweaver.writeModifications();
18
  
19
  $('#tab-sweaver_plugin_advanced').click(function(){
20
    Drupal.Sweaver.writeModifications();
21
  });
22

    
23
});
24

    
25
/**
26
 * A simple function to update the screen after a modification
27
 */
28
Drupal.Sweaver.reloadInterface = function() {
29
  Drupal.Sweaver.writeCss();
30
  Drupal.Sweaver.updateForm();
31
  Drupal.Sweaver.writeModifications();
32
}
33

    
34
/**
35
 * Write all modifications made in the plugin's tab
36
 */
37
Drupal.Sweaver.writeModifications = function() {
38
  var data = ''; // Contains all data that will be form the #scrollable_area
39
  var key_id = 0; // Get an ID for the key
40
  var properties_counted = 0; // Count all properties modified
41
  var hidden_properties_counted = 0; // Count all properties modified that are hidden
42
  
43
  data += '<table>';
44
  for (key in Drupal.Sweaver.css) {
45
    key_id++;
46
    var target = Drupal.Sweaver.css[key];
47
    var temp_data = '';
48
    var sub_properties_counted = 0;
49
    var sub_hidden_properties_counted = 0;
50
    
51
    for (prop in target) {
52
      properties_counted++;
53
      sub_properties_counted++;
54
      
55
      if (Drupal.Sweaver.properties[prop] && (target[prop]['value'] != '' || target[prop]['value'] == '0')) {        
56
        if (target[prop]['hidden'] == true){
57
          temp_data += '<tr class="hidden" onclick="Drupal.Sweaver.showKey(' + key_id +')">';
58
        }
59
        else {
60
          temp_data += '<tr onclick="Drupal.Sweaver.showKey(' + key_id +')">';
61
        }
62
        
63
        // Special case for transparent.
64
        if ((prop == 'background-color' && target[prop]['value'] == 'transparent') || (prop == 'background-image' && target[prop]['value'] == 'none')) {
65
          temp_data += '<td class="property">' + prop + ' : ' + target[prop]['value'] + '</td>';
66
        }
67
        else {
68
          temp_data += '<td class="property">' + prop + ' : ' + Drupal.Sweaver.properties[prop].prefix + target[prop]['value'] + Drupal.Sweaver.properties[prop].suffix + '</td>';
69
        }
70
        
71
        if (target[prop]['hidden'] == true){
72
          var hide_class = 'disabled';
73
          var show_class = '';
74
          hidden_properties_counted++;
75
          sub_hidden_properties_counted++;
76
        }
77
        else {
78
          var hide_class = '';
79
          var show_class = 'disabled';
80
        }
81
        
82
        temp_data += '<td class="operations">';        
83
        temp_data += '<span class="delete" onclick="Drupal.Sweaver.deleteProperty(\'' + key + '\', \'' + prop + '\'); Drupal.Sweaver.writeModifications();">' + 'Delete' + '</span>';
84
        temp_data += '<span class="hide ' + hide_class + '" onclick="Drupal.Sweaver.propertyHider(\'' + key + '\', \'' + prop + '\');">Hide</span>';
85
        temp_data += '<span class="show ' + show_class + '" onclick="Drupal.Sweaver.propertyHider(\'' + key + '\', \'' + prop + '\');">Show</span>';
86
        temp_data += '</td></tr>';
87
      }
88
    }
89
    
90
    if (sub_properties_counted == sub_hidden_properties_counted) {
91
      var hide_class = 'disabled';
92
      var show_class = '';
93
    }
94
    else if (sub_hidden_properties_counted == 0) {
95
      var hide_class = '';
96
      var show_class = 'disabled';
97
    }
98
    else {
99
      var hide_class = '';
100
      var show_class = '';
101
    }
102
    
103
    data += '<tr class="separator" onclick="Drupal.Sweaver.showKey(' + key_id +')"><th>' + key + '</th><td class="operations">';
104
    data += '<span class="title delete" onclick="Drupal.Sweaver.deleteKeyProperties(\'' + key + '\');">Delete</span>';
105
    data += '<span class="title hide ' + hide_class + '" onclick="Drupal.Sweaver.keyPropertiesHider(\'' + key + '\', true);">Hide</span>';
106
    data += '<span class="title show ' + show_class + '" onclick="Drupal.Sweaver.keyPropertiesHider(\'' + key + '\', false);">Show</span>';
107
    data += '</td></tr>';
108
    data += temp_data;
109
  }
110
  data += '</table>';
111
  $('#watchdog #scrollable_area').html(data);
112
  
113
  if (properties_counted == hidden_properties_counted) {
114
    $('#watchdog .header .operations .hide').addClass('disabled');
115
    $('#watchdog .header .operations .show').removeClass('disabled');
116
  }
117
  else if (hidden_properties_counted == 0) {
118
    $('#watchdog .header .operations .hide').removeClass('disabled');
119
    $('#watchdog .header .operations .show').addClass('disabled');
120
  }
121
  else {
122
    $('#watchdog .header .operations .hide').removeClass('disabled');
123
    $('#watchdog .header .operations .show').removeClass('disabled');
124
  }
125
}
126

    
127
/**
128
 * Select a container from a key_id
129
 * This container is selected on the screen (class sweaver-clicked)
130
 */
131
Drupal.Sweaver.showKey = function (key_id) {
132
  var counter = 0;
133
  for (key in Drupal.Sweaver.css) {
134
    counter++;
135
    if (counter ==  key_id) {
136
      $('.sweaver-clicked').removeClass('sweaver-clicked');
137
      $(key).addClass('sweaver-clicked');
138
    }
139
  }
140
  $('#watchdog tr').removeClass('active');
141
  $('#watchdog tr[onclick=Drupal.Sweaver.showKey(' + key_id + ')]').addClass('active');
142
}
143

    
144
/**
145
 * Delete all properties modified with the editor that are applied to a specified container (key)
146
 */
147
Drupal.Sweaver.deleteKeyProperties = function(key) {
148
  delete Drupal.Sweaver.css[key];
149
  
150
  Drupal.Sweaver.reloadInterface();
151
}
152

    
153
/**
154
 * Delete all properties modified with the editor
155
 */
156
Drupal.Sweaver.deleteAllProperties = function() {
157
  Drupal.Sweaver.css = new Object();
158
  
159
  Drupal.Sweaver.reloadInterface();
160
}
161

    
162
/**
163
 * Hide one property
164
 * key (string) the container
165
 * property (string) the property to hide
166
 */
167
Drupal.Sweaver.propertyHider = function(key, property) {
168
  var target = Drupal.Sweaver.css[key];
169
  for (prop in target) {
170
    if (prop == property) {
171
      Drupal.Sweaver.css[key][property]['hidden'] = !Drupal.Sweaver.css[key][property]['hidden'];
172
      
173
      Drupal.Sweaver.reloadInterface();
174
    }
175
  }
176
}
177

    
178
/**
179
 * Hide or Show (dependent on the value of hide) all properties that are in a specified container (key)
180
 */
181
Drupal.Sweaver.keyPropertiesHider = function(key, hide) {
182
  var target = Drupal.Sweaver.css[key];
183
  for (prop in target) {
184
    Drupal.Sweaver.css[key][prop]['hidden'] = hide;
185
  }
186
  
187
  Drupal.Sweaver.reloadInterface();
188
}
189

    
190
/**
191
 * Hide all properties made in the editor
192
 */
193
Drupal.Sweaver.cssHider = function(hide) {
194
  for (key in Drupal.Sweaver.css) {
195
    var target = Drupal.Sweaver.css[key];
196
    for (prop in target) {
197
      Drupal.Sweaver.css[key][prop]['hidden'] = hide;
198
    }
199
  }
200
  Drupal.Sweaver.reloadInterface();
201
}
202

    
203
})(jQuery);