# HG changeset patch # User rt@lightning # Date 2013-09-23 23:10:53 # Node ID b5b2e3a65ff430ae2db3e5adc97b7684a62e4b6d # Parent 5b2002ce1d59f77406e2c0f0759e75acf03ba64b Rewriting gallery mode. diff --git a/boards/static/js/thread.js b/boards/static/js/thread.js --- a/boards/static/js/thread.js +++ b/boards/static/js/thread.js @@ -1,78 +1,28 @@ -var image_mode = 0; -var normal_dom, table_dom; - -function add_panel(after) -{ - var nav_top = $(after); - if (nav_top.length === 0) return; - nav_top = nav_top[0]; - - var tab_bar = $('
'); - - var tab; - - tab = $(''); - tab.on("change", tab_handler); - - var label_normal = gettext('Normal'); - tab = $('').prepend(tab); - tab_bar.append(tab); - - tab = $(''); - tab.on("change", tab_handler); - - var label_gallery = gettext('Gallery'); - tab = $('').prepend(tab); - tab_bar.append(tab); - - tab_bar.insertAfter(nav_top); -} - -function tab_handler(ev) -{ - var current_el = $(this); - - if (!current_el.prop('checked')) return; +function addGalleryPanel() { + var gallery = $('a[class="thumb"]').clone(true), + normal = $('.post').clone(true); - var new_mode = parseInt(current_el.val(), 10); - if (new_mode === image_mode) return; - image_mode = new_mode; - - make_normal_dom(); - make_table_dom(); - - switch(new_mode) { - case 0: - $('#posts-table').replaceWith(normal_dom); - break; - case 1: - $('#posts').replaceWith(table_dom); - break; - } + $('.navigation_panel').filter(':first').after( + '
' + + '' + + '' + + '
' + ); - //TODO: временно - addImgPreview(); -} - -function make_normal_dom() -{ - if (typeof normal_dom === 'undefined') { - normal_dom = $('#posts').clone(true); - } -} - -function make_table_dom() -{ - if (typeof table_dom !== 'undefined') return; - - table_dom = $('
'); - $('#posts > .post > .image > a').each( - function(){ - table_dom.append( - $(this).clone().attr('target', '_blank') + $('input[name="image-mode"]').change(function() { + //gallery mode + if($(this).val() === '1') { + $('#posts').replaceWith( + $('
').append(gallery) ); } - ); + //normal mode + else { + $('#posts-table').replaceWith( + $('
').append(normal) + ); + } + }); } function moveCaretToEnd(el) { @@ -101,6 +51,6 @@ function addQuickReply(postId) { $(document).ready(function(){ - add_panel('.navigation_panel'); + addGalleryPanel(); addRefLinkMap(); });