[r2]: / monsters / licenses / Spaceship 2D | OpenGameArt.org_files / oga_theme.js  Maximize  Restore  History

Download this file

214 lines (173 with data), 5.9 kB

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
/*
 *  oga_theme.js - functions specific to the OpenGameArt.org theme 
 *
 *  Written in 2009 by Bart Kelsey <bart@opengameart.org>
 *
 *  To the extent possible under law, the author(s) have dedicated all copyright and related 
 *  and neighboring rights to this software to the public domain worldwide. This software is 
 *  distributed without any warranty. 
 *
 *  You should have received a copy of the CC0 Public Domain Dedication along with this 
 *  software. If not, see <http://creativecommons.org/publicdomain/zero/1.0/>.
 */

(function($) {
  var oldWidth;
  var body_orig_width;
  var farright_orig_width;

  $(window).resize(function() {
    resize_bar(false);
  });

  $(function() {
    oldWidth = 0;
    body_orig_width = $('body').width();
    farright_orig_width = $('div#farright').width();
    resize_bar(true);
    $('.small-preview-title a').each(function() {
            var inner = $(this).html();
            if(inner.length > 16) {
                    inner = inner.substring(0, 15) + "...";
                    $(this).html(inner);
            }
    });

    $('.views-exposed-form select[multiple]').each(function() {
      replaceMultiSelect($(this));
    });

    $('.multi-select-replace input').click(function() {
      multiSelectToggle($(this));
    });

    $('.content').delegate('.play-button', 'click', function() {
      $('.stop-button').trigger('click');
      playButton(this);
    });

    $('.content').delegate('.stop-button', 'click', function() {
      stopButton(this);
    });

    $('.content').delegate('.subtree-toggle', 'click', function() {
      console.log('click');
      if($(this).hasClass('blank')) {
	    return;
      }
		
	  if($(this).hasClass('open')) {
	    $(this).removeClass('open').addClass('closed');
	  } else {
		$(this).removeClass('closed').addClass('open');
	  }
		
      $(this).parent().children('ul').slideToggle('fast');
    });
	
	$('.content').delegate('.art-preview-title', 'mouseenter', function() {
      $(this).addClass('hover');
    });
    
    $('.content').delegate('.art-preview-title', 'mouseleave', function() {
      $(this).removeClass('hover');
    });

    $('body').delegate('.view-art ul.pager a', 'click', function() {
      console.log('scroll to top');
      $('body').scrollTop(0);
    }); 
    
    $('input#edit-submit').click(function() {
      var clicked = $(this).attr('data-clicked');
      if(clicked) {
        return false;        
      } else {
        $(this).attr('data-clicked', 1);
      }
    });
  });

  function resize_right() {
    $('#right:not(.nosidebar)').each(function() {
      resize($(this), 350, 575);
    });

    $('.right-side').each(function() {
      resize($(this), 350, 575);
    });
    
    $('.nosidebar .right-column').each(function() {
      resize($(this), 350, 575);
    });
  }
  
  function resize_bar(initial) {
    var width = $(window).width(); 
    var threshold = 1260;
    if(width >= threshold && (initial || oldWidth < threshold)) {
      $('body').width(threshold);
      
      if(!$('#page').hasClass('wide')) $('div#farright').width(296);
      if($('#farright').length > 0 && !$('#page').hasClass('wide')) {
        $('#farright').appendTo('#maincontent');        
      } else {
        $('#right:not(.nosidebar)').width(890);
      }
    } else if((initial || oldWidth >= threshold) && width < threshold) {
      $('body').width(body_orig_width);
      if(!$('#page').hasClass('wide')) $('div#farright').width(farright_orig_width);
      if($('#farright').length > 0 && !$('#page').hasClass('wide')) {
        $('#farright').appendTo('#left');
      } else {
        $('#right:not(.nosidebar)').width(590);
      }
    }
    oldWidth = width;
  }
  
  function resize(element, margin, minWidth) {
    var parentWidth = element.parent().width();

    var newWidth = parentWidth - margin;
    if(newWidth < minWidth) {
      newWidth = minWidth;
    }

    element.width(newWidth - 20);
  }

  function stopButton(b) {
    $(b).addClass('play-button');
    $(b).removeClass('stop-button');


    b.audioElement.currentTime = 0;
    b.audioElement.pause();
  }

  function playButton(b) {
    $(b).addClass('stop-button');
    $(b).removeClass('play-button');

    if(!(b.audioElement)) {
      
      b.audioElement = document.createElement('audio');

      if(b.audioElement.canPlayType) {
        var url;
        if(b.audioElement.canPlayType('audio/ogg; codecs="vorbis"')) {
          url = $(b).attr('data-ogg-url');
        } else if(b.audioElement.canPlayType('audio/mpeg')) {
          url = $(b).attr('data-mp3-url');
        }
        
        b.audioElement.setAttribute('src', url);
        b.audioElement.load();
      } else {
        // flash fallback
      }
    }

    if(b.audioElement.canPlayType) {
      b.audioElement.play();
    } else {
      // flash fallback
    }
  }
  
  function replaceMultiSelect(item) {
    //console.log('replacing multi select');
    
    item.hide();
    var id = item.attr('id');
    var newid = "checkboxes-" + id;
    var html = "<div id='" + newid + "' class='multi-select-replace' data-select='" + id + "'>";
    
    item.find('option').each(function() {
      html += "<div class='multi-select-checkbox'><input type='checkbox' value='" + $(this).val() + "'";

      if($(this).attr('selected')) {
        html += " checked='checked'";
      }
      
      html += "> " + $(this).html() + "</div>";
    });
    
    html += "</div>";
    item.after(html);
  }

  function multiSelectToggle(item) {
    var id = item.parent().parent().attr('data-select');
    //console.log('id: ' + id);
    var select = $('#' + id);
    if(item.attr('checked')) {
      select.find("option[value=" + item.val() + "]").attr('selected', 'selected');
    } else {
      select.find("option[value=" + item.val() + "]").removeAttr('selected');
    }
  }
  

})(jQuery);