MediaWiki:Gadget-EditAddButton.js

来自康健生活
Kangkk​(留言 | 贡献)2020年9月12日 (六) 15:02的版本

注意:在发布之后,您可能需要清除浏览器缓存才能看到所作出的更改的影响。

  • Firefox或Safari:按住Shift的同时单击刷新,或按Ctrl-F5或Ctrl-R(Mac为⌘-R)
  • Google Chrome:按Ctrl-Shift-R(Mac为⌘-Shift-R)
  • Edge:按住Ctrl的同时单击刷新,或按Ctrl-F5。
var customizeToolbar = function () {
  /* Your code goes here */


  jQuery( document ).ready( function ( $ ) {
    $( '#wpTextbox1' ).wikiEditor( 'addToToolbar', {
      section: 'advanced',
      group: 'format',
      tools: {
        reqular_s_stroke: {
          label: 'Comment visible only for editors',
          type: 'button',
          icon: 'images/toolbar_img/Toolbaricon_regular_S_stroke.png',
          action: {
            type: 'encapsulate',
            options: {
              pre: '<!-- ',
              peri: 'Insert comment here',
              post: ' -->'
            }
          }
        },
        toolbar_css_tag: {
          label: 'CSS tag for editors',
          type: 'button',
          icon: 'images/toolbar_img/CSS.png',
          action: {
            type: 'encapsulate',
            options: {
              pre: '<syntaxhighlight lang="css">\n',
              peri: 'Insert comment here\n',
              post: '</syntaxhighlight>'
            }
          }
        },
        toolbar_html_tag: {
          label: 'HTML tag for editors',
          type: 'button',
          icon: 'images/toolbar_img/HTML-Button.png',
          action: {
            type: 'encapsulate',
            options: {
              pre: '<syntaxhighlight lang="html5">\n',
              peri: 'Insert comment here\n',
              post: '</syntaxhighlight>'
            }
          }
        },
        toolbar_bash_tag: {
          label: 'BASH tag for editors',
          type: 'button',
          icon: 'images/toolbar_img/BASH.png',
          action: {
            type: 'encapsulate',
            options: {
              pre: '{{shc|<syntaxhighlight lang="bash">\n',
              peri: 'Insert comment here\n',
              post: '</syntaxhighlight>}}'
            }
          }
        },
        toolbar_js_tag: {
          label: 'JAVASCRIPT tag for editors',
          type: 'button',
          icon: 'images/toolbar_img/JSbutton.png',
          action: {
            type: 'encapsulate',
            options: {
              pre: '<syntaxhighlight lang="javascript">\n',
              peri: 'Insert comment here\n',
              post: '</syntaxhighlight>'
            }
          }
        },
        toolbar_blockquote_tag: {
          label: 'Blockquote tag for editors',
          type: 'button',
          icon: 'images/toolbar_img/Button_blockquote.png',
          action: {
            type: 'encapsulate',
            options: {
              pre: '<blockquote>\n',
              peri: 'Insert comment here\n',
              post: '</blockquote>'
            }
          }
        },
        toolbar_pre_tag: {
          label: 'PRE tag for editors',
          type: 'button',
          icon: 'images/toolbar_img/Button_insert_table.png',
          action: {
            type: 'encapsulate',
            options: {
              pre: '<pre>\n',
              peri: 'Insert comment here\n',
              post: '</pre>'
            }
          }
        },
        toolbar_bq_pre_tag: {
          label: 'Blockquote > PRE tag for editors',
          type: 'button',
          icon: 'images/toolbar_img/BQ_PRE.png',
          action: {
            type: 'encapsulate',
            options: {
              pre: '<blockquote><pre>\n',
              peri: 'Insert comment here\n',
              post: '</pre></blockquote>'
            }
          }
        },
        toolbar_button_reflink: {
          label: 'Button reflink tag for editors',
          type: 'button',
          icon: 'images/toolbar_img/Button_reflink.png',
          action: {
            type: 'encapsulate',
            options: {
              pre: '<ref>',
              peri: 'Insert comment here',
              post: '</ref>'
            }
          }
        },
        toolbar_button_strong: {
          label: 'strong tag for editors',
          type: 'button',
          icon: 'images/toolbar_img/Button_bold.png',
          action: {
            type: 'encapsulate',
            options: {
              pre: "'''",
              peri: 'Insert comment here',
              post: "'''"
            }
          }
        },
        toolbar_button_strike: {
          label: 'Button_strike tag for editors',
          type: 'button',
          icon: 'images/toolbar_img/Button_strike.png',
          action: {
            type: 'encapsulate',
            options: {
              pre: '<s>',
              peri: 'Insert comment here',
              post: '</s>'
            }
          }
        },
        toolbar_button_email: {
          label: 'Button email tag for editors',
          type: 'button',
          icon: 'images/toolbar_img/Button_spam2.png',
          action: {
            type: 'encapsulate',
            options: {
              pre: '[mailto:',
              peri: 'Insert comment here',
              post: ']'
            }
          }
        },
        toolbar_button_outLink: {
          label: 'Button outLink tag for editors',
          type: 'button',
          icon: 'images/toolbar_img/Button_Link_DifferentName.png',
          action: {
            type: 'encapsulate',
            options: {
              pre: '[[|',
              peri: 'Insert comment here',
              post: ']]'
            }
          }
        },
        toolbar_button_redNote: {
          label: 'Button redNote tag for editors',
          type: 'button',
          icon: 'images/toolbar_img/Marco1.png',
          action: {
            type: 'encapsulate',
            options: {
              pre: '{{Warning|',
              peri: 'Insert comment here',
              post: '}}'
            }
          }
        },
        toolbar_button_greenNote: {
          label: 'Button greenNote tag for editors',
          type: 'button',
          icon: 'images/toolbar_img/Button_chapitre.png',
          action: {
            type: 'encapsulate',
            options: {
              pre: '<div class="pageBoxGreen">',
              peri: 'Insert comment here',
              post: '</div>'
            }
          }
        },
        toolbar_button_hrTag: {
          label: 'Button hr tag for editors',
          type: 'button',
          icon: 'images/toolbar_img/Button_hr.png',
          action: {
            type: 'encapsulate',
            options: {
              pre: '<hr>\n',
              peri: '',
              post: ''
            }
          }
        },
        toolbar_button_noToc: {
          label: 'Button noToc tag for editors',
          type: 'button',
          icon: 'images/toolbar_img/Button_stop.png',
          action: {
            type: 'encapsulate',
            options: {
              pre: '__NOTOC__\n',
              peri: '',
              post: ''
            }
          }
        },
        toolbar_code_tag: {
          label: 'code tag for editors',
          type: 'button',
          icon: 'images/toolbar_img/Btn_toolbar_commentaire.png',
          action: {
            type: 'encapsulate',
            options: {
              pre: '<code>',
              peri: 'Insert comment here',
              post: '</code>'
            }
          }
        },
        div_300px_tag: {
          label: 'Div 300px tag for editors',
          type: 'button',
          icon: 'images/toolbar_img/width300px.png',
          action: {
            type: 'encapsulate',
            options: {
              pre: '<div style="width:300px;">',
              peri: 'Insert comment here',
              post: '</div>'
            }
          }
        },
        div_600px_tag: {
          label: 'Div 600px tag for editors',
          type: 'button',
          icon: 'images/toolbar_img/width600px.png',
          action: {
            type: 'encapsulate',
            options: {
              pre: '<div style="width:600px;">',
              peri: 'Insert comment here',
              post: '</div>'
            }
          }
        },
        div_900px__tag: {
          label: 'Div 900px tag for editors',
          type: 'button',
          icon: 'images/toolbar_img/width900px.png',
          action: {
            type: 'encapsulate',
            options: {
              pre: '<div style="width:900px;">',
              peri: 'Insert comment here',
              post: '</div>'
            }
          }
        },
      }
    } );
} );

};



/* Check if view is in edit mode and that the required modules are available. Then, customize the toolbar … */
if ( $.inArray( mw.config.get( 'wgAction' ), [ 'edit', 'submit' ] ) !== -1 ) {
  mw.loader.using( 'user.options' ).then( function () {
    // This can be the string "0" if the user disabled the preference ([[phab:T54542#555387]])
    if ( mw.user.options.get( 'usebetatoolbar' ) == 1 ) {
      $.when(
        mw.loader.using( 'ext.wikiEditor' ), $.ready
        ).then( customizeToolbar );
    }
  } );
}