]> git.0d.be Git - panikweb.git/blob - panikweb_templates/static/js/specifics.js
display picture legends
[panikweb.git] / panikweb_templates / static / js / specifics.js
1 var urlParams;
2 (window.onpopstate = function () {
3     var match,
4         pl     = /\+/g,  // Regex for replacing addition symbol with a space
5         search = /([^&=]+)=?([^&]*)/g,
6         decode = function (s) { return decodeURIComponent(s.replace(pl, " ")); },
7         query  = window.location.search.substring(1);
8
9     urlParams = {};
10     while (match = search.exec(query))
11        urlParams[decode(match[1])] = decode(match[2]);
12 })();
13
14 $(function() {
15
16         doLog = function(aTextToLog, type){
17                 var aLog = $('<div>',{'class':"log "+type,html:aTextToLog});
18                 aLog.hide().prependTo($log).show('fast').delay(3000).hide('fast', function() { 
19                         $(this).remove(); 
20                 });
21         }
22         var $main = $("#Changing");
23         var $metaNav = $("#metaNav");
24         var $log = $("#userLog");
25         tooltip_options = {
26                 position: {
27                         my: "center bottom-5",
28                         at: "center top",
29                         using: function( position, feedback ) {
30                                 $( this ).css( position );
31                                 $( "<div>" )
32                                 .addClass( "arrow" )
33                                 .addClass( feedback.vertical )
34                                 .addClass( feedback.horizontal )
35                                 .appendTo( this );
36                         }
37                 }
38         };
39
40         $('.newsRoll').tooltip(tooltip_options);
41         $('#metaNav').tooltip(tooltip_options);
42
43         $('body').css({'min-height':$(window).height() + $('#Commons').height()});
44         /****************************************************/
45         /**** AJAX UTILITIES FOR REQUESTS ****/
46         /****************************************************/
47         String.prototype.decodeHTML = function() {
48                 return $("<div>", {html: "" + this}).html();
49         };
50         var loadPage_request = null;
51         afterLoad = function(html, textStatus, XMLHttpRequest) {
52                 loadPage_request = null;
53                 if (textStatus == "error") {
54                         doLog('Sorry! And error occur when loading page content','error');
55                 }
56                 new_html = $.parseHTML(html);
57                 new_content = $(new_html).find('#Changing>*');
58                 $main.hide().empty().append(new_content).show();
59
60                 /* calling onpopstate here is necessary to get urlParams to be
61                  * updated */
62                 window.onpopstate();
63
64                 canonical_href_node = $.grep($(new_html), function(elem, idx) {
65                         return (elem.nodeName === "LINK" && elem.attributes['rel'].value == "canonical");
66                 })[0];
67                 if (canonical_href_node) {
68                         canonical_href = canonical_href_node.attributes['href'].value;
69                         history.replaceState({}, '', canonical_href);
70                 }
71
72                 new_menu = $($.parseHTML(html)).find('#metaNav>*');
73                 $metaNav.empty().append(new_menu);
74
75                 var newTitle = html?html.match(/<title>(.*?)<\/title>/):'';
76                 if(newTitle){document.title = newTitle[1].trim().decodeHTML();}
77
78                 /*
79                 Quite UGLY but needed for styling the whole body with ID
80                 Feel free to correct and find a better way
81                 According to this link the probles is that $(html).filter('body').Attr('id') will not work!
82                 http://www.devnetwork.net/viewtopic.php?f=13&t=117065
83                 */
84                 if(sectionName = $(html).find('[data-section]').attr('data-section')){
85                         $('body').attr('id',sectionName);
86                 }else{
87                         var bodyID = html.match(/<body id="(.*?)">/);   
88                         if(bodyID){$('body').attr('id',bodyID[1].trim());}      
89                 }
90                 $("#Changing").css({'min-height':$(window).height()});
91                 $.scrollTo('#Changing',1000,{offset:-$('#metaNav').height()+2});
92                 init();
93
94                 if (typeof (Piwik) == 'object') {
95                         piwikTracker = Piwik.getAsyncTracker();
96                         if (typeof (piwikTracker.trackPageView) == 'function') {
97                                 piwikTracker.setDocumentTitle(document.title);
98                                 piwikTracker.setCustomUrl(window.location.href);
99                                 piwikTracker.trackPageView();
100                                 $('.audio a').each(function() {
101                                         piwikTracker.addListener(this);
102                                 });
103                         }
104                 }
105
106         };
107
108         function afterLoadError(xhr, text, error) {
109                 afterLoad(xhr.responseText, 'error', xhr);
110         };
111
112         $(window).on("popstate", function(e) {
113                 if (e.originalEvent.state !== null) {loadPage(location.href, false);}
114         });
115
116         loadPage = function(href, push_state) {
117                 if (push_state !== false) {
118                         history.pushState({}, '', href);
119                 }
120                 if (loadPage_request !== null) {
121                         loadPage_request.abort();
122                 }
123                 loadPage_request = $.ajax({
124                         url: href,
125                         success: afterLoad,
126                         error: afterLoadError,
127                         dataType: 'html'});
128         };
129         $.fn.ajaxifyClick = function(params) {
130                 if ($('#df-wpr-sidebar').length > 0) {
131                         /* this is fiber sidebar, it doesn't work well with
132                          * seamless page loading */
133                         return;
134                 }
135                 this.each(function() {
136                         $(this).unbind('click');
137                         $(this).bind('click',function(e){
138                                 var href = $(this).attr("href");
139                                 if (href.match('\.(pdf|odt|ods|doc|xls|docx|xlsx|rtf)$')) {
140                                         /* open files */
141                                         window.open(href, '_blank');
142                                         return false;
143                                 }
144                                 if (e.which == 2) {
145                                         window.open(href, '_blank');
146                                         return false;
147                                 }
148                                 $(this).addClass('loading');
149                                 /* this checks the link points to a local document, be
150                                  * it because it's just a path, or because the server
151                                  * part points to the same domain */
152                                 if (!href) {
153                                         doLog('No href attributes, unable to load content','error');
154                                         $("#All a, #All area").removeClass('loading');
155                                         return false;
156                                 }else if (!$(this).attr('target') && (
157                                                 href.indexOf(document.domain) > -1 ||href.indexOf(':') === -1 || href.indexOf(':') > 5
158                                         )) {
159                                         loadPage(href);
160                                         return false;
161                                 }else{
162                                         $(this).attr('target','_blank');
163                                         $("#All a, #All area").removeClass('loading');
164                                         return true;
165                                 }
166                         });
167                 });
168         };
169         /****************************************************/
170         /**** AUDIOPLAYER ****/
171         /****************************************************/
172
173         var timer = null;
174         var refresh_onair_interval = 25000;
175         var ticker_interval = null;
176         /*
177         //TODO: mini icon version for player, (playpause only)
178         $('#togglePlayer').on('click',function(e) {
179                 e.preventDefault();
180                 if($(this).is('.icon-double-angle-left')){
181                         $("#player").fadeOut('fast',function(){
182                                 $("#player-container").toggleClass('minimized');                        
183                                 $('#togglePlayer').toggleClass('icon-double-angle-left icon-double-angle-right');
184                         });                     
185                 }else{
186                         $("#player").fadeIn('fast',function(){
187                                 $("#player-container").toggleClass('minimized');                        
188                                 $('#togglePlayer').toggleClass('icon-double-angle-left icon-double-angle-right');
189                         });     
190                 }
191                 return false;
192         });
193         */
194         $('#WhatsOnAir').on('load',function(){
195                 var WhatsOnAir = $(this);
196                 $('#RefreshWhatsOnAir').addClass('spinning');
197                 $.getJSON('/onair.json', function(onair) {
198                         setTimeout(function() { $('#RefreshWhatsOnAir').removeClass('spinning'); }, 5000);
199                         var onairContainer = $('<span>');
200                         if(onair.data.episode || onair.data.emission) {
201                                 if(onair.data.emission){
202                                         $('<a>',{href:onair.data.emission.url,html:onair.data.emission.title}).appendTo(onairContainer).ajaxifyClick();
203                                 }
204                                 if(onair.data.episode){
205                                         $('<span> - </span>').appendTo(onairContainer);
206                                         $('<a>',{href:onair.data.episode.url,html:onair.data.episode.title}).appendTo(onairContainer).ajaxifyClick();
207                                 }
208                         } else if (onair.data.nonstop) {
209                                 onairContainer = $('<span>' + onair.data.nonstop.title + '</span>');
210                                 if (onair.data.track_title) {
211                                         $('<span> - </span>').appendTo(onairContainer);
212                                         $('<span class="nonstop-track-title">' + onair.data.track_title + '</span>').appendTo(onairContainer);
213                                         if (onair.data.track_artist) {
214                                                 $('<span> </span>').appendTo(onairContainer)
215                                                 $('<span class="nonstop-track-artist">(' + onair.data.track_artist + ')</span>').appendTo(onairContainer);
216                                         }
217                                 }
218                         }
219                         else {
220                                 onairContainer = $('<span>Unknown (Probably Non-Stop)</span>');
221                         }
222                         var current_html = WhatsOnAir.html();
223                         var new_html = '<span>' + onairContainer.html() + '</span>';
224                         if (new_html !== current_html) {
225                                 WhatsOnAir.fadeOut();
226                                 WhatsOnAir.empty().append(onairContainer);
227                                 WhatsOnAir.fadeIn();
228                         }
229                 });
230         });
231         $('#RefreshWhatsOnAir').on('activate',function(e){
232                 $('#WhatsOnAir').trigger('load');
233                 timer = setInterval( "$('#WhatsOnAir').trigger('load');", refresh_onair_interval);
234         }).on('deactivate',function(e){
235                 $(this).removeClass('spinning');
236                 $('#WhatsOnAir').removeClass('active');
237                 clearInterval(timer);
238         }).on('click',function(e){
239                 $(this).toggleClass('active');
240                 if($(this).is('.active')){
241                         $(this).trigger('deactivate');
242                 }else{
243                         $(this).trigger('activate');
244                 }
245                 return false;
246         }).trigger('activate');
247         $("#DirectStreamPanikControler").on('click',function(e) {
248                 e.preventDefault();
249                 var stream = $('#DirectStreamPanik').get(0);
250                 if (stream.paused == false){
251                         stream.pause();
252                 }else{
253                         if (typeof (_paq) == 'object') {
254                                 _paq.push(['trackEvent', 'Audio', 'Play Stream']);
255                         }
256                         stream.play();
257                 }
258                 return false;
259         });
260         $('#DirectStreamPanik').on('play',function(){
261                 $('audio:not(#DirectStreamPanik)').each(function(){this.pause();});
262                 $('#streamSymbol').removeClass('icon-volume-up').addClass('icon-pause');
263                 $('#RefreshWhatsOnAir').trigger('activate');
264         }).on('pause',function(){
265                 //$('audio:not(#DirectStreamPanik)').each(function(){this.pause();});
266                 $('#streamSymbol').addClass('icon-volume-up').removeClass('icon-pause');
267         });
268         if($('#player-container').offset()){
269                 var topPosition = 0;
270                 topPosition = $('#mainHeader > div').offset().top + $('#mainHeader > div').height();
271                 $(window).bind('scroll load',function (event) {
272                         //$('#player-container').removeClass('fixed');
273                         var y = $(this).scrollTop() + 40;
274                         if (topPosition!== 0 && y >= topPosition) {
275                                 $('#player-container').addClass('fixed').removeClass('normal');
276                         } else {
277                                 $('#player-container').removeClass('fixed').addClass('normal');
278                         }
279                 });
280         }
281
282         var $localList = $('#localList').playlist({
283                 controlContainer: $('<div>',{'class':"playListControls"}).sortable(),
284                 playlistContainer: $('<ol>',{id:"myPlaylist",'class':"custom"}).sortable(),
285                 onLoad:function(self){
286                         $('#toggleList').on('click',function(){ 
287                                 self.playlistContainer.toggleClass('deploy');
288                         });
289                         $('#emptyList').on('click',function(){ 
290                                 self._reset();
291                         });
292
293                         if(self.isActive){
294                                 self.playlistContainer.scrollTo(self.isActive, 800 );
295                                 self.isActive.find('audio').attr('preload',"preload")
296                         }
297                         self.controlButtons['playpause'].addClass('resymbol');
298                 },
299                 onPlay:function(self){
300                         $('#DirectStreamPanik')[0].pause();
301                         self.playlistContainer.scrollTo(self.isActive, 800 );
302                 },
303                 onAdd:function(self){
304                         //self.isLastAdd[0].scrollIntoView();
305                         self.isLastAdd.find('a').ajaxifyClick();
306                         self.playlistContainer.scrollTo(self.isLastAdd, 800).delay(1000).scrollTo(self.isActive, 800 ).clearQueue();
307
308                         if (typeof (_paq) == 'object') {
309                                 _paq.push(['trackEvent', 'Audio', 'Add to playlist']);
310                         }
311                 },
312                 onUpdate:function(self){
313                         //doLog(JSON.stringify(self.playlist, null, '\t'));     
314                         if(self.playlist.length >= 1){
315                                 self.element.show();
316                                 $('#Player').addClass('withPlaylist').removeClass('withoutPlaylist');
317                         }else{
318                                 self.element.hide();
319                                 $('#Player').removeClass('withPlaylist').addClass('withoutPlaylist');
320                         }
321                 }
322         });
323
324         init = function() {
325                 $("#All a, #All area").removeClass('loading');
326                 $("#All a, #All area").ajaxifyClick();
327                 $("#search-form").unbind('submit').on('submit', function(event) {
328                         event.preventDefault();
329                         $(this).addClass('loading');
330                         loadPage($(this).attr('action') + '?' + $(this).serialize());
331                 });
332                 $(".tabs").each(function() {
333                         var self = $(this);
334                         var about= $($(this).attr("data-tab-about"));
335                         var current = $(this).find("[data-tab].active")[0];
336                         var dftShowSelector = current?".active":":first";
337                         var activeTab = $(this).find("[data-tab]"+dftShowSelector+"").addClass("active");
338                         $(this).find("[data-tab]").each(function() {
339                             $(this).on('click load',function (e) {  
340                                 e.preventDefault();
341                                 self.find(".active").removeClass("active");  
342                                 $(this).addClass("active");  
343                                 about.find("[data-tabbed]").hide();  
344                                 $($(this).attr("data-tab")).fadeIn();  
345                 
346                             });  
347                         });  
348                         activeTab.trigger('load');
349                 });
350                 $('[data-player-action]').on('click',function(){
351                         var audio = $('#'+$(this).attr('data-player-audio'));
352                         var sound_id = audio.data('sound-id');
353                         if($(this).attr('data-player-action') == "registerAudio"){
354                                 $localList.playlist("registerAudio",audio,doLog(audio.attr('title')+' has been added to your playlist.','ok'));
355                         }else if($(this).attr('data-player-action') == "playAudio"){
356                                 $localList.playlist("registerAudio",audio,doLog(audio.attr('title')+' will play soon.','ok'));
357                                 $localList.playlist("playSoundId", sound_id);
358                                 if ($(this).parent().find('.icon-pause').length) {
359                                         $(this).hide();
360                                         $(this).parent().find('.icon-pause').show();
361                                 }
362                         }else if ($(this).attr('data-player-action') == "pauseSounds") {
363                                 if ($(this).parent().find('.icon-play-sign').length) {
364                                         $(this).hide();
365                                         $(this).parent().find('.icon-play-sign').show();
366                                 }
367                                 $localList.playlist($(this).attr('data-player-action'));
368                         }else{
369                                 $localList.playlist($(this).attr('data-player-action'));
370                         }
371                 });
372                 $('[data-player-control]').each(function(){
373                         var audio = $('#'+$(this).attr('data-player-audio'));
374                         $localList.playlist("bindControl",$(this).attr('data-player-control'),audio,$(this));
375                 });
376
377                 $('[data-highlight]').on('check',function(){
378                         $($(this).attr('data-about')).find($(this).attr('data-highlight')).addClass('highlighted').removeClass('normal');
379                 }).on('uncheck',function(){
380                         $($(this).attr('data-about')).find($(this).attr('data-highlight')).removeClass('highlighted').addClass('normal');
381                 }).on('click',function(){
382                         $(this).toggleClass('icon-check icon-check-empty');
383                         if($(this).hasClass('icon-check')){$(this).trigger('check');
384                         }else{  $(this).trigger('uncheck');}
385                 });
386                 $('[data-highlight].icon-check-empty').each(function(){
387                         $(this).trigger('uncheck');
388                 });
389                 $('[data-toggle]').on('check',function(){
390                         /* make sure all other unchecked items are hidden */
391                         $('[data-toggle].icon-check-empty').each(function() {
392                                 $($(this).attr('data-about')).find($(this).attr('data-toggle')).hide();
393                         });
394                         $($(this).attr('data-about')).find($(this).attr('data-toggle')).show();
395                 }).on('uncheck',function(){
396                         $($(this).attr('data-about')).find($(this).attr('data-toggle')).hide();
397                         if ($('[data-toggle].icon-check').length == 0) {
398                                 /* special case the situation where all toggles
399                                  * are unchecked, as we want that to mean
400                                  * "everything", not "nothing".
401                                  */
402                                 $('[data-toggle].icon-check-empty').each(function() {
403                                         $($(this).attr('data-about')).find($(this).attr('data-toggle')).show();
404                                 });
405                         }
406                 }).on('click',function(){
407                         $(this).toggleClass('icon-check icon-check-empty');
408                         if($(this).hasClass('icon-check')){$(this).trigger('check');
409                         }else{  $(this).trigger('uncheck');}
410                 });
411                 $('[data-toggle].icon-check-empty').each(function(){
412                         $(this).trigger('uncheck');
413                 });
414
415                 initial_enabled_toggles = {};
416                 if (typeof(urlParams.q) == 'string') {
417                         urlParams.q.split('|').forEach(function(a) { initial_enabled_toggles[a] = 1; })
418                 }
419                 $('[data-toggle]').each(function() {
420                         if ($(this).data('toggle').substring(1) in initial_enabled_toggles) {
421                                 $(this).trigger('click');
422                         }
423                 });
424
425                 $('[data-popup-href]').on('click', function() {
426                         $.ajax({
427                                 url: $(this).data('popup-href'),
428                                 success: function (html, textStatus, jqXhr) {
429                                         $(html).appendTo($('body'));
430                                 }
431                         });
432                         return false;
433                 });
434
435                 if ($('input#id_q').val() == '') {
436                         $('input#id_q').focus();
437                 }
438
439                 $('#ticker li:not(:first)');
440                 if (ticker_interval) clearInterval(ticker_interval);
441                 function tick(){
442                     $('#ticker li:first').animate({'opacity':0}, 200, function () {
443                         $(this).appendTo($('#ticker')).css('opacity', 1);
444                     });
445                 }
446                 $("#roller button").on('click',function(e){
447                     clearInterval(ticker_interval);
448                     e.preventDefault();
449                     $($(this).attr('data-about')).prependTo('#ticker');
450                     return false;
451                 });
452                 ticker_interval = setInterval(function(){tick();  }, 20000);/**/
453
454                 function navsearch_click(event) {
455                         event.preventDefault();
456                         var query = $('#nav-search input').val();
457                         var form = $('#nav-search form');
458                         var href = '';
459                         if (query == '') {
460                                 href = $(form).attr('action');
461                         } else {
462                                 href = $(form).attr('action') + '?' + $(form).serialize();
463                         }
464                         if (event.which == 2) {
465                                 window.open(href, '_blank');
466                         } else {
467                                 $(this).addClass('loading');
468                                 loadPage(href);
469                         }
470                         return false;
471                 }
472                 $('#nav-search a').unbind('click').on('click', navsearch_click);
473                 $('#nav-search form').unbind('submit').on('submit', navsearch_click);
474
475                 $('[data-toggle-img]').bind('click', function() {
476                         var src = $(this).data('toggle-img');
477                         $(this).data('toggle-img', $(this).attr('src'));
478                         $(this).attr('src', src);
479                         $(this).toggleClass('right marged');
480                 });
481
482                 $('#Main #Emission-tabs-detail audio, div.soundcell audio').each(function(index, audio) {
483                         var audio_src = $(audio).find('source')[0];
484                         var sound_id = $(audio).data('sound-id');
485                         var $waveform = $(audio).next();
486                         $.getJSON(audio_src.src.replace('.ogg', '.waveform.json'), function(data) {
487                                 $waveform.empty();
488                                 $waveform.append('<i class="duration">' + $waveform.data('duration-string') + '</i>');
489                                 $.each(data, function(k, val) {
490                                         var val = val * 0.5;
491                                         $waveform.append('<span data-tick-index="' + k + '" style="height: ' + val + 'px;"></span>');
492                                 });
493                                 $waveform.show();
494                                 $waveform.find('span').on('click', function() {
495                                         /* if there's been something loaded */
496                                         var matching_audio = $('audio[data-sound-id=' + sound_id + ']');
497                                         if (matching_audio.length == 0) return;
498                                         matching_audio = matching_audio[0];
499                                         if (matching_audio.paused || matching_audio.ended) {
500                                                 /* ignore */
501                                                 return;
502                                         }
503                                         /* try to set time */
504                                         var total_duration = parseFloat($waveform.data('duration'));
505                                         var nb_ticks = $(this).parent().find('span').length;
506                                         var tick_index = $(this).data('tick-index');
507                                         matching_audio.currentTime = total_duration * tick_index / nb_ticks;
508                                 });
509                         });
510                 });
511
512                 $('#nav-language span').click(function() {
513                         document.cookie = 'panikweb_language=' + $(this).data('lang') + '; path=/';
514                         window.location = window.location;
515                         return false;
516                 });
517
518                 if (document.cookie.indexOf('panikdb=on') != -1) {
519                         panikdb_path = null;
520                         if (window.location.pathname.indexOf('/emissions/') == 0) {
521                                 panikdb_path = window.location.pathname;
522                         } else if (window.location.pathname.indexOf('/news/') == 0) {
523                                 panikdb_path = '/emissions' + window.location.pathname;
524                         }
525                         if (panikdb_path) {
526                                 $('<a id="panikdb" href="http://panikdb.radiopanik.org' + panikdb_path + '">Voir dans PanikDB</a>').appendTo($main);
527                         }
528                 }
529
530                 $('.gallery').each(function() {
531                   var $gallery = $(this);
532                   $gallery.find('span.image').on('click', function() {
533                     if ($(this).find('img').hasClass('portrait')) {
534                         $(this).parents('.gallerycell').addClass('portrait');
535                     } else {
536                         $(this).parents('.gallerycell').removeClass('portrait');
537                     }
538                     $gallery.find('div.first img').attr('src', $(this).data('image-large'));
539                     $gallery.find('div.first span.gallery-legend').text($(this).find('img').attr('title'));
540                     $gallery.find('div.first').show('fade');
541                     return false;
542                   });
543                   $gallery.find('div.first').on('click', function() { $(this).toggle('fade'); return false; });
544                 });
545
546         }
547         init();
548
549         if (! document.createElement('audio').canPlayType('audio/ogg') &&
550                 document.createElement('audio').canPlayType('audio/aac') ) {
551                 $('#ogg-m3u').hide().removeClass('resymbol');
552                 $('#aac-m3u').addClass('resymbol').show();
553         }
554
555         var konami = new Konami('/party');
556
557         $(document).on('panik:timeupdate', function(ev, data) {
558                 $waveform = $('#Main div.waveform[data-sound-id="' + data.sound_id + '"]');
559                 var elems = $waveform.find('span');
560                 var total_elems = elems.length;
561                 var done = total_elems * data.position;
562                 $waveform.find('span').each(function(k, elem) {
563                   if (k < done) {
564                         $(elem).addClass('done').removeClass('current');
565                   } else {
566                         $(elem).removeClass('done');
567                   }
568                 });
569                 $waveform.find('span.done:last').addClass('current');
570         });
571
572         $("body").keydown(function(e) {
573           var $visible_element = $('div.first:visible img');
574           if ($visible_element.length == 0) {
575             return true;
576           }
577           if ($visible_element.length > 1) {
578             /* remove all but last */
579             $visible_element.parent().find('img:not(:last)').remove();
580           }
581           var $visible_element = $('div.first:visible img');
582           var img_url = $visible_element.attr('src');
583           var all_img = $('div.gallery span[data-image-large] img');
584           var active_img = $('div.gallery span[data-image-large="' + img_url + '"] img');
585           var idx = all_img.index(active_img);
586           if (e.which == 37) { // left
587             idx--;
588             if (idx == -1) {
589               idx = all_img.length-1;
590             }
591           } else if (e.which == 39) { // right
592             idx++;
593             if (idx == all_img.length) {
594               idx = 0;
595             }
596           } else if (e.which == 27) { // escape
597             $visible_element.parent().toggle('fade');
598             return true;
599           } else {
600             return true;
601           }
602           /* create a new <img> with the new image but opacity 0, then display
603            * it using a css transition */
604           if (e.which == 37) { $visible_element.css('transform-origin', 'bottom right'); }
605           if (e.which == 39) { $visible_element.css('transform-origin', 'bottom left'); }
606           var new_img = $visible_element.clone().appendTo($visible_element.parent());
607           $(new_img).css('opacity', 0).attr('src', $(all_img[idx]).parent().data('image-large'));
608           $(new_img).css('transform', 'scale(0, 1)');
609           $(new_img)[0].offsetHeight; /* trigger reflow */
610           $(new_img).css('opacity', 1).css('transform', 'scale(1)');
611           $(new_img).parents('.gallery').find('span.gallery-legend').text($(all_img[idx]).attr('title'));
612           if ($(all_img[idx]).hasClass('portrait')) {
613             if (! $(new_img).parents('.gallerycell').hasClass('portrait')) {
614               $visible_element.parent().find('img:not(:last)').remove();
615               $(new_img).parents('.gallerycell').addClass('portrait');
616             }
617           } else {
618             if ($(new_img).parents('.gallerycell').hasClass('portrait')) {
619               $visible_element.parent().find('img:not(:last)').remove();
620               $(new_img).parents('.gallerycell').removeClass('portrait');
621             }
622           }
623           return false;
624         });
625
626 });