Diff of /monsters/licenses/Spaceship 2D | OpenGameArt.org_files/oga_theme.js [000000] .. [r2]  Maximize  Restore

Switch to unified view

a b/monsters/licenses/Spaceship 2D | OpenGameArt.org_files/oga_theme.js
1
/*
2
 *  oga_theme.js - functions specific to the OpenGameArt.org theme 
3
 *
4
 *  Written in 2009 by Bart Kelsey <bart@opengameart.org>
5
 *
6
 *  To the extent possible under law, the author(s) have dedicated all copyright and related 
7
 *  and neighboring rights to this software to the public domain worldwide. This software is 
8
 *  distributed without any warranty. 
9
 *
10
 *  You should have received a copy of the CC0 Public Domain Dedication along with this 
11
 *  software. If not, see <http://creativecommons.org/publicdomain/zero/1.0/>.
12
 */
13
14
(function($) {
15
  var oldWidth;
16
  var body_orig_width;
17
  var farright_orig_width;
18
19
  $(window).resize(function() {
20
    resize_bar(false);
21
  });
22
23
  $(function() {
24
    oldWidth = 0;
25
    body_orig_width = $('body').width();
26
    farright_orig_width = $('div#farright').width();
27
    resize_bar(true);
28
    $('.small-preview-title a').each(function() {
29
            var inner = $(this).html();
30
            if(inner.length > 16) {
31
                    inner = inner.substring(0, 15) + "...";
32
                    $(this).html(inner);
33
            }
34
    });
35
36
    $('.views-exposed-form select[multiple]').each(function() {
37
      replaceMultiSelect($(this));
38
    });
39
40
    $('.multi-select-replace input').click(function() {
41
      multiSelectToggle($(this));
42
    });
43
44
    $('.content').delegate('.play-button', 'click', function() {
45
      $('.stop-button').trigger('click');
46
      playButton(this);
47
    });
48
49
    $('.content').delegate('.stop-button', 'click', function() {
50
      stopButton(this);
51
    });
52
53
    $('.content').delegate('.subtree-toggle', 'click', function() {
54
      console.log('click');
55
      if($(this).hasClass('blank')) {
56
        return;
57
      }
58
        
59
      if($(this).hasClass('open')) {
60
        $(this).removeClass('open').addClass('closed');
61
      } else {
62
        $(this).removeClass('closed').addClass('open');
63
      }
64
        
65
      $(this).parent().children('ul').slideToggle('fast');
66
    });
67
    
68
    $('.content').delegate('.art-preview-title', 'mouseenter', function() {
69
      $(this).addClass('hover');
70
    });
71
    
72
    $('.content').delegate('.art-preview-title', 'mouseleave', function() {
73
      $(this).removeClass('hover');
74
    });
75
76
    $('body').delegate('.view-art ul.pager a', 'click', function() {
77
      console.log('scroll to top');
78
      $('body').scrollTop(0);
79
    }); 
80
    
81
    $('input#edit-submit').click(function() {
82
      var clicked = $(this).attr('data-clicked');
83
      if(clicked) {
84
        return false;        
85
      } else {
86
        $(this).attr('data-clicked', 1);
87
      }
88
    });
89
  });
90
91
  function resize_right() {
92
    $('#right:not(.nosidebar)').each(function() {
93
      resize($(this), 350, 575);
94
    });
95
96
    $('.right-side').each(function() {
97
      resize($(this), 350, 575);
98
    });
99
    
100
    $('.nosidebar .right-column').each(function() {
101
      resize($(this), 350, 575);
102
    });
103
  }
104
  
105
  function resize_bar(initial) {
106
    var width = $(window).width(); 
107
    var threshold = 1260;
108
    if(width >= threshold && (initial || oldWidth < threshold)) {
109
      $('body').width(threshold);
110
      
111
      if(!$('#page').hasClass('wide')) $('div#farright').width(296);
112
      if($('#farright').length > 0 && !$('#page').hasClass('wide')) {
113
        $('#farright').appendTo('#maincontent');        
114
      } else {
115
        $('#right:not(.nosidebar)').width(890);
116
      }
117
    } else if((initial || oldWidth >= threshold) && width < threshold) {
118
      $('body').width(body_orig_width);
119
      if(!$('#page').hasClass('wide')) $('div#farright').width(farright_orig_width);
120
      if($('#farright').length > 0 && !$('#page').hasClass('wide')) {
121
        $('#farright').appendTo('#left');
122
      } else {
123
        $('#right:not(.nosidebar)').width(590);
124
      }
125
    }
126
    oldWidth = width;
127
  }
128
  
129
  function resize(element, margin, minWidth) {
130
    var parentWidth = element.parent().width();
131
132
    var newWidth = parentWidth - margin;
133
    if(newWidth < minWidth) {
134
      newWidth = minWidth;
135
    }
136
137
    element.width(newWidth - 20);
138
  }
139
140
  function stopButton(b) {
141
    $(b).addClass('play-button');
142
    $(b).removeClass('stop-button');
143
144
145
    b.audioElement.currentTime = 0;
146
    b.audioElement.pause();
147
  }
148
149
  function playButton(b) {
150
    $(b).addClass('stop-button');
151
    $(b).removeClass('play-button');
152
153
    if(!(b.audioElement)) {
154
      
155
      b.audioElement = document.createElement('audio');
156
157
      if(b.audioElement.canPlayType) {
158
        var url;
159
        if(b.audioElement.canPlayType('audio/ogg; codecs="vorbis"')) {
160
          url = $(b).attr('data-ogg-url');
161
        } else if(b.audioElement.canPlayType('audio/mpeg')) {
162
          url = $(b).attr('data-mp3-url');
163
        }
164
        
165
        b.audioElement.setAttribute('src', url);
166
        b.audioElement.load();
167
      } else {
168
        // flash fallback
169
      }
170
    }
171
172
    if(b.audioElement.canPlayType) {
173
      b.audioElement.play();
174
    } else {
175
      // flash fallback
176
    }
177
  }
178
  
179
  function replaceMultiSelect(item) {
180
    //console.log('replacing multi select');
181
    
182
    item.hide();
183
    var id = item.attr('id');
184
    var newid = "checkboxes-" + id;
185
    var html = "<div id='" + newid + "' class='multi-select-replace' data-select='" + id + "'>";
186
    
187
    item.find('option').each(function() {
188
      html += "<div class='multi-select-checkbox'><input type='checkbox' value='" + $(this).val() + "'";
189
190
      if($(this).attr('selected')) {
191
        html += " checked='checked'";
192
      }
193
      
194
      html += "> " + $(this).html() + "</div>";
195
    });
196
    
197
    html += "</div>";
198
    item.after(html);
199
  }
200
201
  function multiSelectToggle(item) {
202
    var id = item.parent().parent().attr('data-select');
203
    //console.log('id: ' + id);
204
    var select = $('#' + id);
205
    if(item.attr('checked')) {
206
      select.find("option[value=" + item.val() + "]").attr('selected', 'selected');
207
    } else {
208
      select.find("option[value=" + item.val() + "]").removeAttr('selected');
209
    }
210
  }
211
  
212
213
})(jQuery);