旧站的内容可能已过时。您可以前往“真魂”分站查看本页面,那里的内容将会定期同步。
“MediaWiki:Common.js”的版本间的差异
来自个人维基
小 |
|||
第1行: | 第1行: | ||
− | |||
$( function () { | $( function () { | ||
− | + | ||
− | + | /* 缺省将内容 lang 设置成简体中文 */ | |
− | + | if ( !document.getElementById( "lnnblog-setlang" ) ) { | |
− | + | $( "mw-content-text" ).attr( "lang", "zh-cmn-Hans" ); | |
− | + | $( "firstHeading" ).attr( "lang", "zh-cmn-Hans" ); | |
+ | } | ||
/* 评论框内联 CSS 修正 */ | /* 评论框内联 CSS 修正 */ | ||
第12行: | 第12行: | ||
$( "#addComment form .greyTiny" ).css( "padding-left", "" ); | $( "#addComment form .greyTiny" ).css( "padding-left", "" ); | ||
$( "#addComment textarea+div" ).css( "text-align", "right" ); | $( "#addComment textarea+div" ).css( "text-align", "right" ); | ||
+ | |||
+ | |||
+ | /* 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 ) | ||
+ | $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" ) | ||
+ | $(".lnnblog-hidebox-body").text("").text(($(".lnnblog-hidebox")[0].outerHTML)) | ||
+ | } | ||
+ | } ) | ||
+ | } 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 ) | ||
+ | $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 ) | ||
+ | } | ||
+ | } ) | ||
+ | } | ||
+ | } ) | ||
+ | |||
+ | } ); |
2022年11月22日 (二) 00:39的版本
$( 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" ); /* 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 ) $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" ) $(".lnnblog-hidebox-body").text("").text(($(".lnnblog-hidebox")[0].outerHTML)) } } ) } 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 ) $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 ) } } ) } } ) } );