From 3e728fd7f13af2d42303aa550fdcef09349b6935 Mon Sep 17 00:00:00 2001 From: Markus Bartz Date: Thu, 21 Jul 2011 17:59:58 +0200 Subject: [PATCH] Implemented "the JS version of {pages}". --- .../install/files/acp/templates/header.tpl | 5 +- wcfsetup/install/files/js/WCF.js | 415 ++++++++++++++++++ 2 files changed, 419 insertions(+), 1 deletion(-) diff --git a/wcfsetup/install/files/acp/templates/header.tpl b/wcfsetup/install/files/acp/templates/header.tpl index 31218c6569..dcad2f8b15 100644 --- a/wcfsetup/install/files/acp/templates/header.tpl +++ b/wcfsetup/install/files/acp/templates/header.tpl @@ -55,7 +55,10 @@ 'wcf.global.date.relative.hours': '{capture assign=relativeHours}{lang}wcf.global.date.relative.hours{/lang}{/capture}{@$relativeHours|encodeJS}', 'wcf.global.date.relative.pastDays': '{capture assign=relativePastDays}{lang}wcf.global.date.relative.pastDays{/lang}{/capture}{@$relativePastDays|encodeJS}', 'wcf.global.date.dateTimeFormat': '{lang}wcf.global.date.dateTimeFormat{/lang}', - '__days': [ '{lang}wcf.global.date.day.sunday{/lang}', '{lang}wcf.global.date.day.monday{/lang}', '{lang}wcf.global.date.day.tuesday{/lang}', '{lang}wcf.global.date.day.wednesday{/lang}', '{lang}wcf.global.date.day.thursday{/lang}', '{lang}wcf.global.date.day.friday{/lang}', '{lang}wcf.global.date.day.saturday{/lang}' ] + '__days': [ '{lang}wcf.global.date.day.sunday{/lang}', '{lang}wcf.global.date.day.monday{/lang}', '{lang}wcf.global.date.day.tuesday{/lang}', '{lang}wcf.global.date.day.wednesday{/lang}', '{lang}wcf.global.date.day.thursday{/lang}', '{lang}wcf.global.date.day.friday{/lang}', '{lang}wcf.global.date.day.saturday{/lang}' ], + 'wcf.global.thousandsSeparator': '{capture assign=thousandsSeparator}{lang}wcf.global.thousandsSeparator{/lang}{/capture}{@$thousandsSeparator|encodeJS}', + 'wcf.global.page.next': '{capture assign=pageNext}{lang}wcf.global.page.next{/lang}{/capture}{@$pageNext|encodeJS}', + 'wcf.global.page.previous': '{capture assign=pagePrevious}{lang}wcf.global.page.previous{/lang}{/capture}{@$pagePrevious|encodeJS}' }); new WCF.Date.Time(); }); diff --git a/wcfsetup/install/files/js/WCF.js b/wcfsetup/install/files/js/WCF.js index b99e2cb630..432134e57f 100644 --- a/wcfsetup/install/files/js/WCF.js +++ b/wcfsetup/install/files/js/WCF.js @@ -1084,6 +1084,40 @@ WCF.String = { */ ucfirst: function(string) { return string.substring(0, 1).toUpperCase() + string.substring(1); + }, + + /** + * Adds thousands separators to a given number. + * + * @param mixed number + * @return string + */ + addThousandsSeparator: function(number) { + var $numberString = String(number); + if (number >= 1000 || number <= -1000) { + var $negative = false; + if (number <= -1000) { + $negative = true; + $numberString = $numberString.substring(1); + } + var $separator = this.options.thousandsSeparator; + + if ($separator != null && $separator != '') { + var $numElements = new Array(); + var $firstPart = $numberString.length % 3 + if ($firstPart == 0) $firstPart = 3; + for (var $i = 0; $i < Math.ceil($numberString.length / 3); $i++) { + if ($i == 0) $numElements.push($numberString.substring(0, $firstPart)); + else { + var $start = (($i - 1) * 3) + $firstPart + $numElements.push($numberString.substring($start, $start + 3)); + } + } + $numberString = (($negative) ? ('-') : ('')) + $numElements.join($separator); + } + } + + return $numberString; } }; @@ -1391,6 +1425,387 @@ $.widget('ui.wcfTabs', $.ui.tabs, { } }); +/** + * jQuery widget implementation of the wcf pagination. + */ +$.widget( "ui.wcfPages", { + SHOW_LINKS: 11, + SHOW_SUB_LINKS: 20, + + options: { + // vars + activePage: 1, + maxPage: 1, + + // icons + previousIcon: RELATIVE_WCF_DIR + 'icon/previousS.png', + previousDisabledIcon: RELATIVE_WCF_DIR + 'icon/previousDisabledS.png', + arrowDownIcon: RELATIVE_WCF_DIR + 'icon/arrowDown.png', + nextIcon: RELATIVE_WCF_DIR + 'icon/nextS.png', + nextDisabledIcon: RELATIVE_WCF_DIR + 'icon/nextDisabledS.png', + + // language + // we use options here instead of language variables, because the paginator is not only usable with pages + nextPage: null, + previousPage: null, + }, + + /** + * Creates the pages widget. + */ + _create: function() { + if (this.options.nextPage === null) this.options.nextPage = WCF.Language.get('wcf.global.page.next'); + if (this.options.previousPage === null) this.options.previousPage = WCF.Language.get('wcf.global.page.previous'); + + this.element.addClass('pageNavigation'); + + this._render(); + }, + + /** + * Destroys the pages widget. + */ + destroy: function() { + $.Widget.prototype.destroy.apply(this, arguments); + + this.element.children().remove(); + }, + + /** + * Renders th pages widget. + */ + _render: function() { + // only render if we have more than 1 page + if (!this.options.disabled && this.options.maxPage > 1) { + // make sure pagination is visible + if (this.element.hasClass('hidden')) { + this.element.removeClass('hidden'); + } + this.element.show(); + + this.element.children().remove(); + + var $pageList = $(''); + this.element.append($pageList); + + var $previousElement = $('
  • '); + $pageList.append($previousElement); + + if (this.options.activePage > 1) { + var $previousLink = $(''); + $previousElement.append($previousLink); + this._bindSwitchPage($previousLink, this.options.activePage - 1); + + var $previousImage = $(''); + $previousLink.append($previousImage); + } + else { + var $previousImage = $(''); + $previousElement.append($previousImage); + } + $previousElement.addClass('skip'); + + // add first page + $pageList.append(this._renderLink(1)); + + // calculate page links + var $maxLinks = this.SHOW_LINKS - 4; + var $linksBefore = this.options.activePage - 2; + if ($linksBefore < 0) $linksBefore = 0; + var $linksAfter = this.options.maxPage - (this.options.activePage + 1); + if ($linksAfter < 0) $linksAfter = 0; + if (this.options.activePage > 1 && this.options.activePage < this.options.maxPage) $maxLinks--; + + var $half = $maxLinks / 2; + var $left = this.options.activePage; + var $right = this.options.activePage; + if ($left < 1) $left = 1; + if ($right < 1) $right = 1; + if ($right > this.options.maxPage - 1) $right = this.options.maxPage - 1; + + if ($linksBefore >= $half) { + $left -= $half; + } + else { + $left -= $linksBefore; + $right += $half - $linksBefore; + } + + if ($linksAfter >= $half) { + $right += $half; + } + else { + $right += $linksAfter; + $left -= $half - $linksAfter; + } + + $right = Math.ceil($right); + $left = Math.ceil($left); + if ($left < 1) $left = 1; + if ($right > this.options.maxPage) $right = this.options.maxPage; + + // left ... links + if ($left > 1) { + if ($left - 1 < 2) { + $pageList.append(this._renderLink(2)); + } + else { + var $leftChildren = $('
  • '); + $pageList.append($leftChildren); + + var $leftChildrenLink = $(''); + $leftChildren.append($leftChildrenLink); + $leftChildrenLink.click($.proxy(this._startInput, this)); + + var $leftChildrenImage = $(''); + $leftChildrenLink.append($leftChildrenImage); + + var $leftChildrenInput = $(''); + $leftChildren.append($leftChildrenInput); + $leftChildrenInput.keydown($.proxy(this._handleInput, this)); + $leftChildrenInput.keyup($.proxy(this._handleInput, this)); + $leftChildrenInput.blur($.proxy(this._stopInput, this)); + + var $leftChildrenContainer = $('
    '); + $leftChildren.append($leftChildrenContainer); + + var $leftChildrenList = $('