MediaWiki:CollapseMessage.js

(function ($, settings) {   // msg enshrinker. codename: ens    var p = {};    p.settings = settings.ens || (settings.ens = {});    if (p.settings.p) return;    p.settings.p = p;    p.languages = {        qqx: {            more: ' ',            less: ' ',        },        en: {            more: 'more',            less: 'less',        },        ru: {            more: 'больше',            less: 'меньше',        },    };    p.defaults = {        height: 70,        selector: '.msg-body, .article-comm-text',    };    p.settings.height = p.settings.height || p.defaults.height;    p.settings.selector = p.settings.selector || p.defaults.selector;    p.settings.languages = $.extend(true, {}, p.languages, p.settings.languages);    p.lang = $.extend(true, {}, p.settings.languages.qqx, p.settings.languages.en, p.settings.languages[wgUserLanguage] || p.settings.languages[wgContentLanguage] );   p.button = $(' ', { class: 'ens-button wds-button', style: 'position:absolute;display:block;bottom:0;min-height:1px;height:3px;padding:0px 2px 11px 2px;width:100%;text-align:center;opacity:0.5;', text: p.lang.more });   p.shrink = function (el) {        var $el = $(el);        if (!el.dataset.ensHeight || el.dataset.ensHeight == $el.height) {            // enshrink            el.dataset.ensHeight = $el.height;            el.dataset.ensOverflow = $el.css('overflow');            $el.height(p.settings.height);            $el.css({overflow: 'hidden'});            $el.find('.ens-button').text(p.lang.more);        } else {            // enlarge            $el.height(el.dataset.ensHeight);            $el.css({overflow: el.dataset.ensOverflow});            $el.find('.ens-button').text(p.lang.less);        }// if    };// shrink    p.process = function process ($content) {        var $target = $content.find(p.settings.selector);        $target.each(function  { var $this = $(this); if ($this.height > p.settings.height) { $this.append(p.button.clone); p.shrink(this); }       });// each msg    };// process    $('body').on('click', '.ens-button', function (e) { var $target = $(e.target).closest(p.settings.selector); if (!$target.length) return; p.shrink($target.get(0)); });   mw.hook('wikipage.content').add(p.process); })(jQuery, window.fng || (window.fng = {}));