「MediaWiki:Common.js」の版間の差分
(ページの作成:「→ここにあるすべてのJavaScriptは、すべてのページ読み込みですべての利用者に対して読み込まれます: //Tabs function tabs() {...」) |
|||
131行目: | 131行目: | ||
if ($('.Tabs')[0]) tabs(); | if ($('.Tabs')[0]) tabs(); | ||
+ | // Common.js port from Chinese version | ||
+ | (function($, mw) { | ||
+ | |||
+ | // Tabs | ||
+ | function tabs() { | ||
+ | var defaultStyle = { | ||
+ | purple: { | ||
+ | labelColor: ' ', //anti check | ||
+ | labelBackgroundColor: '#9070c0', | ||
+ | labelBorderColor: '#b090e0 #7050a0 #9070c0 #b090e0', | ||
+ | labelPadding: '.2em .3em .2em .3em', | ||
+ | textBorderColor: '#9070c0', | ||
+ | textBackgroundColor: '#f0edf5', | ||
+ | textPadding: '1em' | ||
+ | }, | ||
+ | green: { | ||
+ | labelColor: ' ', | ||
+ | labelBackgroundColor: '#75c045', | ||
+ | labelBorderColor: '#90d060 #60b030 #75c045 #90d060', | ||
+ | labelPadding: '.2em .3em .2em .3em', | ||
+ | textBorderColor: '#75c045 #60b030 #60b030 #75c045', | ||
+ | textBackgroundColor: '#f5fffa', | ||
+ | textPadding: '1em' | ||
+ | }, | ||
+ | red: { | ||
+ | labelColor: ' ', | ||
+ | labelBackgroundColor: '#FF0000', | ||
+ | labelBorderColor: '#FF8888 #CC0000 #FF0000 #FF8888', | ||
+ | labelPadding: '.2em .3em .2em .3em', | ||
+ | textBorderColor: '#FF0000 #CC0000 #CC0000 #FF0000', | ||
+ | textBackgroundColor: '#fffafa', | ||
+ | textPadding: '1em' | ||
+ | }, | ||
+ | blue: { | ||
+ | labelColor: ' ', | ||
+ | labelBackgroundColor: '#5b8dd6', | ||
+ | labelBorderColor: '#88abde #3379de #5b8dd6 #88abde', | ||
+ | labelPadding: '.2em .3em .2em .3em', | ||
+ | textBackgroundColor: '#f0f8ff', | ||
+ | textBorderColor: '#5b8dd6 #3379de #3379de #5b8dd6', | ||
+ | textPadding: '1em' | ||
+ | }, | ||
+ | yellow: { | ||
+ | labelColor: ' ', | ||
+ | labelBackgroundColor: '#ffe147', | ||
+ | labelBorderColor: '#ffe977 #ffd813 #ffe147 #ffe977', | ||
+ | labelPadding: '.2em .3em .2em .3em', | ||
+ | textBackgroundColor: '#fffce8', | ||
+ | textBorderColor: '#ffe147 #ffd813 #ffd813 #ffe147', | ||
+ | textPadding: '1em' | ||
+ | }, | ||
+ | orange: { | ||
+ | labelColor: ' ', | ||
+ | labelBackgroundColor: '#ff9d42', | ||
+ | labelBorderColor: '#ffac5d #ff820e #ff9d42 #ffac5d', | ||
+ | labelPadding: '.2em .3em .2em .3em', | ||
+ | textBackgroundColor: '#ffeedd', | ||
+ | textBorderColor: '#ff9d42 #ff820e #ff820e #ff9d42', | ||
+ | textPadding: '1em' | ||
+ | }, | ||
+ | black: { | ||
+ | labelColor: ' ', | ||
+ | labelBackgroundColor: '#7f7f7f', | ||
+ | labelBorderColor: '#999999 #4c4c4c #7f7f7f #999999', | ||
+ | labelPadding: '.2em .3em .2em .3em', | ||
+ | textBackgroundColor: '#e5e5e5', | ||
+ | textBorderColor: '#7f7f7f #4c4c4c #4c4c4c #7f7f7f', | ||
+ | textPadding: '1em' | ||
+ | } | ||
+ | }; | ||
+ | $('body').addClass('tab'); | ||
+ | // A Class | ||
+ | function StyleSheet() {} | ||
+ | StyleSheet.prototype.getOwnPropertyNamesLength = function getOwnPropertyNamesLength() { | ||
+ | return Object.getOwnPropertyNames(this).length; | ||
+ | }; | ||
+ | String.prototype.toLowerFirstCase = function toLowerFirstCase() { | ||
+ | return this[0].toLowerCase() + this.substring(1); | ||
+ | }; | ||
+ | $('.Tabs').each(function(i) { | ||
+ | if ($(this).children('.TabLabel')[0]) return true; | ||
+ | var self = $(this), | ||
+ | data = $.extend({ | ||
+ | labelPadding: null, | ||
+ | labelBorderColor: null, | ||
+ | labelColor: null, | ||
+ | labelBackgroundColor: $('#content').css('background-color'), | ||
+ | textPadding: null, | ||
+ | textBorderColor: null, | ||
+ | textBackgroundColor: null, | ||
+ | defaultTab: 1, | ||
+ | }, self.attr('class').length > 4 ? defaultStyle[self.attr('class').slice(5)] || {} : {}, this.dataset || {}), | ||
+ | tabLabel = self.append('<div class="TabLabel"></div>').children('.TabLabel'), | ||
+ | tabContent = self.append('<div class="TabContent"></div>').children('.TabContent'), | ||
+ | labelPadding = data.labelPadding, | ||
+ | labelColor = data.labelColor, | ||
+ | styleSheet = { | ||
+ | label: new StyleSheet(), | ||
+ | text: new StyleSheet() | ||
+ | }, | ||
+ | defaultTab = parseInt(data.defaultTab); | ||
+ | self.children('.Tab').each(function() { | ||
+ | $(this).children('.TabLabelText').appendTo(tabLabel); | ||
+ | $(this).children('.TabContentText').appendTo(self.children('.TabContent')); | ||
+ | $(this).remove(); | ||
+ | }); | ||
+ | if (isNaN(defaultTab) || defaultTab <= 0 || defaultTab > tabLabel.children('.TabLabelText').length) defaultTab = 1; | ||
+ | tabLabel.children('.TabLabelText').on('click', function() { | ||
+ | var label = $(this); | ||
+ | label.addClass('selected').siblings().removeClass('selected').css({ | ||
+ | 'border-color': '#aaa', | ||
+ | 'background-color': 'inherit' | ||
+ | }); | ||
+ | tabContent.children('.TabContentText').eq(tabLabel.children('.TabLabelText').index(label)).addClass('selected').siblings().removeClass('selected').removeAttr('style'); | ||
+ | if (styleSheet.label.getOwnPropertyNamesLength()) label.css(styleSheet.label); | ||
+ | if (label.is(':visible')) tabLabel.height(label.height() + parseFloat(label.css('padding-top')) + parseFloat(label.css('padding-bottom')) + 2); | ||
+ | else tabLabel.removeAttr('style'); | ||
+ | }).eq(defaultTab - 1).click(); | ||
+ | if (labelPadding) tabLabel.children('.TabLabelText').css('padding', labelPadding); | ||
+ | ['labelBorderColor', 'labelBackgroundColor', 'textPadding', 'textBorderColor', 'textBackgroundColor'].forEach(function(n) { | ||
+ | var target = /^label/.test(n) ? 'label' : 'text', | ||
+ | key = n.replace(target, '').toLowerFirstCase(); | ||
+ | styleSheet[target][key] = data[n]; | ||
+ | }); | ||
+ | if (labelColor) styleSheet.label.borderTopColor = labelColor; | ||
+ | else if (styleSheet.label.borderColor) styleSheet.label.borderTopColor = 'green'; | ||
+ | tabLabel.find('.selected').click(); | ||
+ | if (styleSheet.text.getOwnPropertyNamesLength()) tabContent.css(styleSheet.text); | ||
+ | if (data.autoWidth == 'yes') self.css('display', 'inline-block'); | ||
+ | }); | ||
+ | } | ||
+ | |||
+ | // Tab invocation | ||
+ | if ($('.Tabs')[0]) tabs(); | ||
+ | |||
+ | // Safari Fix | ||
+ | if (!/chrome/i.test(navigator.userAgent) && | ||
+ | /safari/i.test(navigator.userAgent)) { | ||
+ | $('.heimu').on('click', function() { | ||
+ | $(this).toggleClass('off'); | ||
+ | }); | ||
+ | } | ||
+ | |||
+ | })(jQuery, mediaWiki); |
2017年12月27日 (水) 00:00時点における版
/* ここにあるすべてのJavaScriptは、すべてのページ読み込みですべての利用者に対して読み込まれます */ //Tabs function tabs() { var defaultStyle = { purple: { labelColor: ' ', //anti check labelBackgroundColor: '#9070c0', labelBorderColor: '#b090e0 #7050a0 #9070c0 #b090e0', labelPadding: '.2em .3em .2em .3em', textBorderColor: '#9070c0', textBackgroundColor: '#f0edf5', textPadding: '1em' }, green: { labelColor: ' ', labelBackgroundColor: '#75c045', labelBorderColor: '#90d060 #60b030 #75c045 #90d060', labelPadding: '.2em .3em .2em .3em', textBorderColor: '#75c045 #60b030 #60b030 #75c045', textBackgroundColor: '#f5fffa', textPadding: '1em' }, red: { labelColor: ' ', labelBackgroundColor: '#FF0000', labelBorderColor: '#FF8888 #CC0000 #FF0000 #FF8888', labelPadding: '.2em .3em .2em .3em', textBorderColor: '#FF0000 #CC0000 #CC0000 #FF0000', textBackgroundColor: '#fffafa', textPadding: '1em' }, blue: { labelColor: ' ', labelBackgroundColor: '#5b8dd6', labelBorderColor: '#88abde #3379de #5b8dd6 #88abde', labelPadding: '.2em .3em .2em .3em', textBackgroundColor: '#f0f8ff', textBorderColor: '#5b8dd6 #3379de #3379de #5b8dd6', textPadding: '1em' }, yellow: { labelColor: ' ', labelBackgroundColor: '#ffe147', labelBorderColor: '#ffe977 #ffd813 #ffe147 #ffe977', labelPadding: '.2em .3em .2em .3em', textBackgroundColor: '#fffce8', textBorderColor: '#ffe147 #ffd813 #ffd813 #ffe147', textPadding: '1em' }, orange: { labelColor: ' ', labelBackgroundColor: '#ff9d42', labelBorderColor: '#ffac5d #ff820e #ff9d42 #ffac5d', labelPadding: '.2em .3em .2em .3em', textBackgroundColor: '#ffeedd', textBorderColor: '#ff9d42 #ff820e #ff820e #ff9d42', textPadding: '1em' }, black: { labelColor: ' ', labelBackgroundColor: '#7f7f7f', labelBorderColor: '#999999 #4c4c4c #7f7f7f #999999', labelPadding: '.2em .3em .2em .3em', textBackgroundColor: '#e5e5e5', textBorderColor: '#7f7f7f #4c4c4c #4c4c4c #7f7f7f', textPadding: '1em' } }; $('body').addClass('tab'); // A Class function StyleSheet() {} StyleSheet.prototype.getOwnPropertyNamesLength = function getOwnPropertyNamesLength() { return Object.getOwnPropertyNames(this).length; }; String.prototype.toLowerFirstCase = function toLowerFirstCase() { return this[0].toLowerCase() + this.substring(1); }; $('.Tabs').each(function(i) { if ($(this).children('.TabLabel')[0]) return true; var self = $(this), data = $.extend({ labelPadding: null, labelBorderColor: null, labelColor: null, labelBackgroundColor: $('#content').css('background-color'), textPadding: null, textBorderColor: null, textBackgroundColor: null, defaultTab: 1, }, self.attr('class').length > 4 ? defaultStyle[self.attr('class').slice(5)] || {} : {}, this.dataset || {}), tabLabel = self.append('<div class="TabLabel"></div>').children('.TabLabel'), tabContent = self.append('<div class="TabContent"></div>').children('.TabContent'), labelPadding = data.labelPadding, labelColor = data.labelColor, styleSheet = { label: new StyleSheet(), text: new StyleSheet() }, defaultTab = parseInt(data.defaultTab); self.children('.Tab').each(function() { $(this).children('.TabLabelText').appendTo(tabLabel); $(this).children('.TabContentText').appendTo(self.children('.TabContent')); $(this).remove(); }); if (isNaN(defaultTab) || defaultTab <= 0 || defaultTab > tabLabel.children('.TabLabelText').length) defaultTab = 1; tabLabel.children('.TabLabelText').on('click', function() { var label = $(this); label.addClass('selected').siblings().removeClass('selected').css({ 'border-color': '#aaa', 'background-color': 'inherit' }); tabContent.children('.TabContentText').eq(tabLabel.children('.TabLabelText').index(label)).addClass('selected').siblings().removeClass('selected').removeAttr('style'); if (styleSheet.label.getOwnPropertyNamesLength()) label.css(styleSheet.label); if (label.is(':visible')) tabLabel.height(label.height() + parseFloat(label.css('padding-top')) + parseFloat(label.css('padding-bottom')) + 2); else tabLabel.removeAttr('style'); }).eq(defaultTab - 1).click(); if (labelPadding) tabLabel.children('.TabLabelText').css('padding', labelPadding); ['labelBorderColor', 'labelBackgroundColor', 'textPadding', 'textBorderColor', 'textBackgroundColor'].forEach(function(n) { var target = /^label/.test(n) ? 'label' : 'text', key = n.replace(target, '').toLowerFirstCase(); styleSheet[target][key] = data[n]; }); if (labelColor) styleSheet.label.borderTopColor = labelColor; else if (styleSheet.label.borderColor) styleSheet.label.borderTopColor = 'green'; tabLabel.find('.selected').click(); if (styleSheet.text.getOwnPropertyNamesLength()) tabContent.css(styleSheet.text); if (data.autoWidth == 'yes') self.css('display', 'inline-block'); }); } if ($('.Tabs')[0]) tabs(); // Common.js port from Chinese version (function($, mw) { // Tabs function tabs() { var defaultStyle = { purple: { labelColor: ' ', //anti check labelBackgroundColor: '#9070c0', labelBorderColor: '#b090e0 #7050a0 #9070c0 #b090e0', labelPadding: '.2em .3em .2em .3em', textBorderColor: '#9070c0', textBackgroundColor: '#f0edf5', textPadding: '1em' }, green: { labelColor: ' ', labelBackgroundColor: '#75c045', labelBorderColor: '#90d060 #60b030 #75c045 #90d060', labelPadding: '.2em .3em .2em .3em', textBorderColor: '#75c045 #60b030 #60b030 #75c045', textBackgroundColor: '#f5fffa', textPadding: '1em' }, red: { labelColor: ' ', labelBackgroundColor: '#FF0000', labelBorderColor: '#FF8888 #CC0000 #FF0000 #FF8888', labelPadding: '.2em .3em .2em .3em', textBorderColor: '#FF0000 #CC0000 #CC0000 #FF0000', textBackgroundColor: '#fffafa', textPadding: '1em' }, blue: { labelColor: ' ', labelBackgroundColor: '#5b8dd6', labelBorderColor: '#88abde #3379de #5b8dd6 #88abde', labelPadding: '.2em .3em .2em .3em', textBackgroundColor: '#f0f8ff', textBorderColor: '#5b8dd6 #3379de #3379de #5b8dd6', textPadding: '1em' }, yellow: { labelColor: ' ', labelBackgroundColor: '#ffe147', labelBorderColor: '#ffe977 #ffd813 #ffe147 #ffe977', labelPadding: '.2em .3em .2em .3em', textBackgroundColor: '#fffce8', textBorderColor: '#ffe147 #ffd813 #ffd813 #ffe147', textPadding: '1em' }, orange: { labelColor: ' ', labelBackgroundColor: '#ff9d42', labelBorderColor: '#ffac5d #ff820e #ff9d42 #ffac5d', labelPadding: '.2em .3em .2em .3em', textBackgroundColor: '#ffeedd', textBorderColor: '#ff9d42 #ff820e #ff820e #ff9d42', textPadding: '1em' }, black: { labelColor: ' ', labelBackgroundColor: '#7f7f7f', labelBorderColor: '#999999 #4c4c4c #7f7f7f #999999', labelPadding: '.2em .3em .2em .3em', textBackgroundColor: '#e5e5e5', textBorderColor: '#7f7f7f #4c4c4c #4c4c4c #7f7f7f', textPadding: '1em' } }; $('body').addClass('tab'); // A Class function StyleSheet() {} StyleSheet.prototype.getOwnPropertyNamesLength = function getOwnPropertyNamesLength() { return Object.getOwnPropertyNames(this).length; }; String.prototype.toLowerFirstCase = function toLowerFirstCase() { return this[0].toLowerCase() + this.substring(1); }; $('.Tabs').each(function(i) { if ($(this).children('.TabLabel')[0]) return true; var self = $(this), data = $.extend({ labelPadding: null, labelBorderColor: null, labelColor: null, labelBackgroundColor: $('#content').css('background-color'), textPadding: null, textBorderColor: null, textBackgroundColor: null, defaultTab: 1, }, self.attr('class').length > 4 ? defaultStyle[self.attr('class').slice(5)] || {} : {}, this.dataset || {}), tabLabel = self.append('<div class="TabLabel"></div>').children('.TabLabel'), tabContent = self.append('<div class="TabContent"></div>').children('.TabContent'), labelPadding = data.labelPadding, labelColor = data.labelColor, styleSheet = { label: new StyleSheet(), text: new StyleSheet() }, defaultTab = parseInt(data.defaultTab); self.children('.Tab').each(function() { $(this).children('.TabLabelText').appendTo(tabLabel); $(this).children('.TabContentText').appendTo(self.children('.TabContent')); $(this).remove(); }); if (isNaN(defaultTab) || defaultTab <= 0 || defaultTab > tabLabel.children('.TabLabelText').length) defaultTab = 1; tabLabel.children('.TabLabelText').on('click', function() { var label = $(this); label.addClass('selected').siblings().removeClass('selected').css({ 'border-color': '#aaa', 'background-color': 'inherit' }); tabContent.children('.TabContentText').eq(tabLabel.children('.TabLabelText').index(label)).addClass('selected').siblings().removeClass('selected').removeAttr('style'); if (styleSheet.label.getOwnPropertyNamesLength()) label.css(styleSheet.label); if (label.is(':visible')) tabLabel.height(label.height() + parseFloat(label.css('padding-top')) + parseFloat(label.css('padding-bottom')) + 2); else tabLabel.removeAttr('style'); }).eq(defaultTab - 1).click(); if (labelPadding) tabLabel.children('.TabLabelText').css('padding', labelPadding); ['labelBorderColor', 'labelBackgroundColor', 'textPadding', 'textBorderColor', 'textBackgroundColor'].forEach(function(n) { var target = /^label/.test(n) ? 'label' : 'text', key = n.replace(target, '').toLowerFirstCase(); styleSheet[target][key] = data[n]; }); if (labelColor) styleSheet.label.borderTopColor = labelColor; else if (styleSheet.label.borderColor) styleSheet.label.borderTopColor = 'green'; tabLabel.find('.selected').click(); if (styleSheet.text.getOwnPropertyNamesLength()) tabContent.css(styleSheet.text); if (data.autoWidth == 'yes') self.css('display', 'inline-block'); }); } // Tab invocation if ($('.Tabs')[0]) tabs(); // Safari Fix if (!/chrome/i.test(navigator.userAgent) && /safari/i.test(navigator.userAgent)) { $('.heimu').on('click', function() { $(this).toggleClass('off'); }); } })(jQuery, mediaWiki);