MediaWiki:Common.js:修订间差异
无编辑摘要 |
无编辑摘要 |
||
| 第63行: | 第63行: | ||
] } | ] } | ||
} | } | ||
} | |||
} | |||
} ); | |||
// ===== 🎨 取色按钮(追加,不影响上面的 Noblecraft 格式 booklet)===== | |||
var NC_PALETTE = [ | |||
'#c0392b','#d35400','#e67e22','#f1c40f','#27ae60','#16a085','#1a6b7d','#0f4c5c', | |||
'#2c6fb3','#2980b9','#8e44ad','#9b59b6','#34495e','#7f8c8d','#000000','#ffffff' | |||
]; | |||
var $ncPanel = null; | |||
function ncApplyColor( hex ) { | |||
$textarea.textSelection( 'encapsulateSelection', | |||
{ pre: '{{色|' + hex + '|', peri: '文字', post: '}}', selectPeri: true } ); | |||
ncClosePanel(); | |||
} | |||
function ncClosePanel() { | |||
if ( $ncPanel ) { $ncPanel.remove(); $ncPanel = null; } | |||
$( document ).off( 'click.nccolor' ); | |||
} | |||
function ncTogglePanel() { | |||
if ( $ncPanel ) { ncClosePanel(); return; } | |||
$ncPanel = $( '<div class="nc-colorpop">' ); | |||
var $grid = $( '<div class="nc-colorpop-grid">' ).appendTo( $ncPanel ); | |||
NC_PALETTE.forEach( function ( c ) { | |||
$( '<button type="button" class="nc-swatch">' ).css( 'background', c ) | |||
.attr( 'title', c ).on( 'click', function () { ncApplyColor( c ); } ).appendTo( $grid ); | |||
} ); | |||
var $row = $( '<div class="nc-colorpop-row">' ).appendTo( $ncPanel ); | |||
$( '<label>自定义</label>' ).appendTo( $row ); | |||
var $native = $( '<input type="color" value="#1a6b7d">' ).appendTo( $row ); | |||
$( '<button type="button" class="nc-colorpop-ok">应用</button>' ) | |||
.on( 'click', function () { ncApplyColor( $native.val() ); } ).appendTo( $row ); | |||
$ncPanel.appendTo( document.body ); | |||
var $btn = $( '.tool[rel="nccolorpicker"]' ); | |||
var off = $btn.length ? $btn.offset() : { top: 120, left: 120 }; | |||
$ncPanel.css( { top: ( off.top + 30 ) + 'px', left: off.left + 'px' } ); | |||
setTimeout( function () { | |||
$( document ).on( 'click.nccolor', function ( e ) { | |||
if ( !$( e.target ).closest( '.nc-colorpop, .tool[rel="nccolorpicker"]' ).length ) ncClosePanel(); | |||
} ); | |||
}, 0 ); | |||
} | |||
$textarea.wikiEditor( 'addToToolbar', { | |||
section: 'main', | |||
group: 'format', | |||
tools: { | |||
nccolorpicker: { | |||
label: '🎨 颜色', | |||
type: 'button', | |||
action: { type: 'callback', execute: function () { ncTogglePanel(); } } | |||
} | } | ||
} | } | ||