MediaWiki:Common.js

来自个人维基
2022年11月22日 (二) 11:26的版本

跳转至: 导航搜索

注意:保存之后,你必须清除浏览器缓存才能看到做出的更改。

  • 火狐(Firefox)/Safari:按住“Shift”,同时单击“刷新”,或按“Ctrl-F5”或“Ctrl-R”(Mac为“⌘-R”)
  • Google Chrome:按“Ctrl-Shift-R”(Mac为“⌘-Shift-R”)
  • Internet Explorer:按住“Ctrl”,同时单击“刷新”,或按“Ctrl-F5”
  • Opera:在“工具→首选项”中清除缓存
$( function () {
 
/* 缺省将内容 lang 设置成简体中文 */
if ( !document.getElementById( "lnnblog-setlang" ) ) {
	$( "mw-content-text" ).attr( "lang", "zh-cmn-Hans" );
	$( "firstHeading" ).attr( "lang", "zh-cmn-Hans" );
}
 
/* 评论框内联 CSS 修正 */
$( "#addComment" ).css( "width", "" ).css( "max-width", "500px" );
$( "#addComment textarea" ).css( "width", "100%" ).css( "box-sizing", "border-box" );
$( "#addComment form .greyTiny" ).css( "padding-left", "" );
$( "#addComment textarea+div" ).css( "text-align", "right" );
 
/* viewport meta? */
$( "head" ).append( '<meta name="viewport" content="width=720">' )
 
/* Template: Hidebox */
 
var animationDuration = 250
 
$( "#bodyContent" ).on( "click", ".lnnblog-hidebox-heading", function ( event ) {
  var $this = $( this )
  var $parent = $this.parent()
  var $body = $this.nextAll( ".lnnblog-hidebox-body" )
 
  var open = $parent.prop( "open" )
  var state = $parent.attr( "data-lnnblog-hidebox-state" )
 
  if ( !open || state === "shrink" ) {
    event.preventDefault()
    var currentWidth = $parent.width()
    var currentHeight = $parent.height()
    $parent.stop( true, true ).prop( "open", true )
    var targetWidth = $parent.width()
    var targetHeight = $parent.height()
 
    $body.outerWidth( targetWidth + 1 )
    $parent
      .attr( "data-lnnblog-hidebox-state", "expand" )
      .width( currentWidth )
      .height( currentHeight )
 
    $parent.animate( {
        width: targetWidth,
        height: targetHeight
      }, {
        duration: animationDuration,
        done: function () {
          $body.css( "width", "" )
          $parent
            .css( {
              width: "",
              height: ""
            } )
            .removeAttr( "data-lnnblog-hidebox-state" )
        }
      } )
  } else if ( open || state === "expand" ) {
    event.preventDefault()
    var currentWidth = $parent.width()
    var currentHeight = $parent.height()
    $parent.stop( true, true ).prop( "open", false )
    var targetWidth = $parent.width()
    var targetHeight = $parent.height()
 
    state === "expand" || $body.outerWidth( currentWidth + 1 )
    $parent
      .attr( "data-lnnblog-hidebox-state", "shrink" )
      .width( currentWidth )
      .height( currentHeight )
      .prop( "open", true )
      .animate( {
        width: targetWidth,
        height: targetHeight
      }, {
        duration: animationDuration,
        done: function () {
          $body.css( "width", "" )
          $parent
            .css( {
              width: "",
              height: ""
            } )
            .removeAttr( "data-lnnblog-hidebox-state" )
            .prop( "open", false )
        }
      } )
  }
} )
 
} );