From 431b4acb36a2087b58795f0951a786008dc3b943 Mon Sep 17 00:00:00 2001 From: Vjacheslav Trushkin Date: Tue, 22 Oct 2013 00:41:05 +0300 Subject: [PATCH] [ticket/11956] Move JS to reusable function Move JS to reusable function that can be ran for all content added with JavaScript such as results of AJAX forms PHPBB3-11956 --- phpBB/styles/prosilver/template/forum_fn.js | 1003 ++++++++++--------- 1 file changed, 527 insertions(+), 476 deletions(-) diff --git a/phpBB/styles/prosilver/template/forum_fn.js b/phpBB/styles/prosilver/template/forum_fn.js index a425e9e1ad..cb8ee2f9df 100644 --- a/phpBB/styles/prosilver/template/forum_fn.js +++ b/phpBB/styles/prosilver/template/forum_fn.js @@ -409,6 +409,532 @@ function insert_single_user(formId, user) self.close(); } +/** +* Parse document block +*/ +function parse_document(container) +{ + var test = document.createElement('div'), + oldBrowser = (typeof test.style.borderRadius == 'undefined'); + + delete test; + + /** + * Reset avatar dimensions when changing URL or EMAIL + */ + container.find('input[data-reset-on-edit]').bind('keyup', function() { + $(this.getAttribute('data-reset-on-edit')).val(''); + }); + + /** + * Pagination + */ + container.find('a.pagination-trigger').click(function() { + jumpto($(this)); + }); + + /** + * Adjust HTML code for IE8 and older versions + */ + if (oldBrowser) { + // Fix .linklist.bulletin lists + container.find('ul.linklist.bulletin li:first-child, ul.linklist.bulletin li.rightside:last-child').addClass('no-bulletin'); + + // Do not run functions below for old browsers + return; + } + + /** + * Resize navigation block to keep all links on same line + */ + container.find('.navlinks').each(function() { + var $this = $(this), + left = $this.children().not('.rightside'), + right = $this.children('.rightside'); + + if (left.length !== 1 || !right.length) return; + + function resize() { + var width = 0, + diff = left.outerWidth(true) - left.width(); + + right.each(function() { + width += $(this).outerWidth(true); + }); + left.css('max-width', Math.floor($this.width() - width - diff) + 'px'); + } + + resize(); + $(window).resize(resize); + }); + + /** + * Makes breadcrumbs responsive + */ + container.find('.breadcrumbs:not(.skip-responsive, .linklist.leftside .breadcrumbs)').each(function() { + var $this = $(this), + $body = $('body'), + links = $this.find('.crumb'), + length = links.length, + classes = ['wrapped-wide', 'wrapped-medium', 'wrapped-small'], + classesLength = classes.length, + maxHeight = 0, + lastWidth = false, + wrapped = false; + + // Test height by setting nowrap + $this.css('white-space', 'nowrap'); + maxHeight = $this.height() + 1; + $this.css('white-space', ''); + + // Set tooltips + $this.find('a').each(function() { + var $link = $(this); + $link.attr('title', $link.text()); + }); + + // Funciton that checks breadcrumbs + function check() { + var height = $this.height(), + width = $body.width(), + link, i, j; + + if (height <= maxHeight) { + if (!wrapped || lastWidth === false || lastWidth >= width) { + lastWidth = width; + return; + } + } + lastWidth = width; + + if (wrapped) { + $this.removeClass('wrapped').find('.crumb.wrapped').removeClass('wrapped ' + classes.join(' ')); + wrapped = false; + if ($this.height() <= maxHeight) { + return; + } + } + + wrapped = true; + $this.addClass('wrapped'); + if ($this.height() <= maxHeight) { + return; + } + + for (i = 0; i < classesLength; i ++) { + for (j = length - 1; j >= 0; j --) { + links.eq(j).addClass('wrapped ' + classes[i]); + if ($this.height() <= maxHeight) { + return; + } + } + } + } + + // Run function and set event + check(); + $(window).resize(check); + }); + + /** + * Adjust topiclist lists with check boxes + */ + container.find('ul.topiclist dd.mark').siblings('dt').children('.list-inner').addClass('with-mark'); + + /** + * Appends contents of all extra columns to first column in + * .topiclist lists for mobile devices. Copies contents as is. + * + * To add that functionality to .topiclist list simply add + * responsive-show-all to list of classes + */ + container.find('.topiclist.responsive-show-all > li > dl').each(function() { + var $this = $(this), + block = $this.find('dt .responsive-show:last-child'), + first = true; + + // Create block that is visible only on mobile devices + if (!block.length) { + $this.find('dt > .list-inner').append('