468
עריכות
אין תקציר עריכה |
אין תקציר עריכה |
||
שורה 1: | שורה 1: | ||
mw.loader. | /* תוספות לסרגל כלים רגיל | ||
* | |||
*/ | |||
function ExEditToolbar(){ | |||
/* הרחבת סרגל הכלים */ | |||
var customButtons; | |||
mw.loader.using(['mediawiki.toolbar'],function(){ | |||
function addBtn( location, imageFile, tagOpen, sampleText, tagClose, speedTip ) { | |||
mw.toolbar.addButton( ((location == 1) ? "//wiki.jewishbooks.org.il/" : "//upload.wikimedia.org/" ) + imageFile,speedTip,tagOpen, tagClose,sampleText); | |||
} | |||
$(function() { | |||
var toolbar = document.getElementById('toolbar'); | |||
if (!toolbar) return; | |||
// Group 1 | |||
mw.toolbar.addButton("//upload.wikimedia.org/wikipedia/commons/1/1d/Button_italic.png", "טקסט נטוי (לא מומלץ בעברית)", "\'\'" ,"\'\'","טקסט נטוי"); | |||
addBtn(0, "wikipedia/commons/8/89/Button_bigger.png", '<big>', "טקסט מוגדל", "</big>", "טקסט מוגדל"); | |||
addBtn(0, "wikipedia/commons/0/0d/Button_smaller.png", '<small>', "טקסט מוקטן", "</small>", "טקסט מוקטן"); | |||
addBtn(0, "wikipedia/he/c/c9/Button_strike.png", "<s>", "טקסט המסומן כמחוק", "</s>", "טקסט מחוק"); | |||
addBtn(0, "wikipedia/he/1/1e/Button_font_color.png", '<span style="color: ColorName;">', "טקסט צבוע", "</span>", "טקסט עם צבע"); | |||
addBtn(0, "wikipedia/commons/6/6a/Button_sup_letter.png", "<sup>", "כתב עילי", "</sup>", "כתב עילי"); | |||
addBtn(0, "wikipedia/commons/a/aa/Button_sub_letter.png", "<sub>", "כתב תחתי", "</sub>", "כתב תחתי"); | |||
addBtn(0, "wikipedia/he/2/23/Button_code.png", '<syntaxhighlight lang="text">\n', "טקסט", "\n<\/syntaxhighlight>\n", "עיצוב קוד"); | |||
// ground 4 | |||
addBtn(0, "wikipedia/he/1/12/Button_gallery.png", "<gallery>\n", "קובץ:PictureFileName.jpg|כיתוב תמונה\nקובץ:PictureFileName.jpg|כיתוב תמונה", "\n</gallery>", "יצירת גלריית תמונות"); | |||
addBtn(0, "wikipedia/he/1/13/Button_enter.png", "{{ש}}", "", "", "ירידת שורה"); | |||
// group 5: | |||
addBtn(0, "wikipedia/he/d/d3/Button_definition_list.png", "\n; ", "פריט", " : ", "רשימת הגדרות"); | |||
addBtn(0, "wikipedia/he/5/5f/Button_center.png", '<div style="text-align: center;">\n', "טקסט ממורכז", "\n</div>", "מירכוז טקסט"); | |||
addBtn(0, "wikipedia/he/e/ea/Button_align_left.png", '<div class="mw-content-ltr">\n', "טקסט מיושר לשמאל", "\n</div>", "יישור טקסט לשמאל"); | |||
addBtn(0, "wikipedia/commons/a/ac/Button_ref.PNG", "{{הערה|", "הקלידו הערת שוליים כאן", "}}", "הערת שוליים"); | |||
addBtn(0, "wikipedia/he/3/34/Button_hide_comment.png", "<!-- ", "הערה מוסתרת", " -->", "הערה מוסתרת"); | |||
addBtn(0, "wikipedia/commons/c/c8/Button_redirect.png", "#הפניה [[", "יעד", "]]", "הפניה"); | |||
}); | |||
}); | |||
function addToWikiEditor(){ | |||
/* Math editor */ | |||
/* Math editor */ | |||
function mathDialog(tag, boxtitle, help){ | |||
// override user preference, otherwise mathjax enabler will just skip init | |||
mw.loader.using(['jquery.ui.dialog'],function(){ | |||
var mathEditor=$('<div>'); | |||
var mathInput=$('<textarea>', { dir:'ltr', rows: 8, cols: 40 }).css('width', '100%').appendTo(mathEditor); | |||
var displayOptions=$('<div>הצגה ממורכזת</div>').appendTo(mathEditor); | |||
var mathPreviewDiv=$('<div>').appendTo(mathEditor); | |||
var mathPreviewSpan=$('<span>', { dir: "ltr", 'class' : "tex" }).appendTo(mathPreviewDiv); | |||
var blockDisplay=$('<input type="checkbox" />').prependTo(displayOptions); | |||
mathEditor.dialog( { | |||
title: boxtitle, | |||
height: 0.5 * $('body').height(), | |||
width: 0.5 * $('body').width(), | |||
buttons: { | |||
'הוספה': function(){ | |||
$("#wpTextbox1").textSelection('encapsulateSelection', {replace: true, peri: '<' + tag + | |||
(blockDisplay.prop('checked')? ' display="block"' : '')+'>'+mathInput.val()+'</' + tag + '>'}); | |||
$(this).dialog('close'); | |||
}, | |||
'עזרה':function(){window.open(mw.util.getUrl(help)); | |||
}, | |||
'ביטול': function(){ $(this).dialog('close');} | |||
} // buttons | |||
}); | |||
function updatePreview() { | |||
api.get( { | |||
action: 'parse', | |||
prop: 'text', | |||
text: '<' + tag + '>' + mathInput.val() + '</' + tag + '>', | |||
contentmodel: 'wikitext' | |||
} ) | |||
.done( function(d) { | |||
mathPreviewSpan.html(d.parse.text['*']); | |||
$( 'p', mathPreviewSpan ).css( { overflow: 'auto' } ); | |||
} ); | |||
} | |||
mathInput | |||
.on( 'keyup', updatePreview ) | |||
.on( 'paste', function() { setTimeout( updatePreview, 0 ) } ); // we need to do it after the event has been processed: we get the trigger b4 the content is actually updated. | |||
var api=new mw.Api(); | |||
var selection = $("#wpTextbox1").textSelection( 'getSelection' ); | |||
//insert the selected text into the equation editor | |||
var mathRgx=new RegExp('<' + tag + '>(.*)<\/' + tag + '>'); | |||
if(selection && mathRgx.test(selection)){ | |||
mathInput.val(mathRgx.exec(selection)[1]); | |||
mathInput.keyup(); | |||
} | |||
}); | |||
} | |||
$('#wpTextbox1').on('wikiEditor-dialogs-loaded-insert-file',function(){ | |||
$( '#wikieditor-toolbar-file-dialog' ) | |||
.dialog( { | |||
open: function() { | |||
$( '#wikieditor-toolbar-file-format' ).val( 'ממוזער' ); | |||
} | |||
} ); | |||
}); | |||
// קבוצה חדשה בתפריט מתקדם: | |||
$( '#wpTextbox1' ).wikiEditor( 'addToToolbar', { | |||
'section': 'advanced', | |||
'groups': { | |||
'more': { | |||
'label': "" | |||
} | |||
} | |||
} ); | |||
// קו חוצה | |||
$( '#wpTextbox1' ).wikiEditor( 'addToToolbar', { | |||
'section': 'main', | |||
'group': 'format', | |||
'tools': { | |||
'strikethrough': { | |||
label: 'קו חוצה', | |||
type: 'button', | |||
filters: [ 'body.ns-4, body.ns-talk' ], | |||
icon: '//upload.wikimedia.org/wikipedia/he/8/8d/NewInlineBtn.png', | |||
action: { | |||
type: 'encapsulate', | |||
options: { | |||
pre: '{'+'{כתב מחוק|', | |||
peri: "טקסט מחוק", | |||
post: '}'+'}' | |||
} | |||
} | |||
} | |||
} | |||
} ); | |||
// נוסחאות מתמטיות | |||
// נוסחאות כימיות | |||
// הערה מוסתרת | |||
// טקסט ממורכז | |||
// טקסט מיושר לשמאל | |||
// תגי syntaxhighlight | |||
// תו כיווניות | |||
$( '#wpTextbox1' ).wikiEditor( 'addToToolbar', { | |||
'section': 'advanced', | |||
'group': 'more', | |||
'tools': { | |||
'formula': { | |||
label: 'נוסחה מתמטית (LaTeX)', | |||
type: 'button', | |||
icon: '//upload.wikimedia.org/wikipedia/commons/thumb/3/3e/Nuvola_apps_edu_mathematics_blue-p.svg/22px-Nuvola_apps_edu_mathematics_blue-p.svg.png', | |||
action: {type: 'callback', execute: (function () {return mathDialog('math', 'הוספת משוואה', 'עזרה:נוסחאות'); }) } | |||
}, | |||
'hiddennote': { | |||
label: 'הערה מוסתרת', | |||
type: 'button', | |||
icon: '//upload.wikimedia.org/wikipedia/commons/thumb/b/b5/Gnome-document-new.svg/22px-Gnome-document-new.svg.png', | |||
action: { | |||
type: 'encapsulate', | |||
options: { | |||
pre: '<!-- ', | |||
peri: "הערה מוסתרת", | |||
post: " -->" | |||
} | |||
} | |||
}, | |||
'leftalign': { | |||
label: 'טקסט מיושר לשמאל', | |||
type: 'button', | |||
icon: '//upload.wikimedia.org/wikipedia/commons/thumb/c/ce/Gnome-format-justify-left.svg/22px-Gnome-format-justify-left.svg.png', | |||
action: { | |||
type: 'encapsulate', | |||
options: { | |||
pre: '<div class="mw-content-ltr">', | |||
peri: "טקסט מיושר לשמאל", | |||
post: "</div>" | |||
} | |||
} | |||
}, | |||
'sourcetags': { | |||
label: 'עיצוב קוד מקור', | |||
type: 'button', | |||
icon: '//upload.wikimedia.org/wikipedia/commons/thumb/6/66/Utilities-terminal.svg/22px-Utilities-terminal.svg.png', | |||
action: { | |||
type: 'encapsulate', | |||
options: { | |||
pre: '<syntaxhighlight lang="text">\n', | |||
peri: "טקסט", | |||
post: "\n</syntaxhighlight>\n" | |||
} | |||
} | |||
}, | |||
'rlm': { | |||
label: 'תו כיווניות', | |||
type: 'button', | |||
icon: '//upload.wikimedia.org/wikipedia/commons/thumb/a/a6/Gnome-format-text-direction-rtl.svg/22px-Gnome-format-text-direction-rtl.svg.png', | |||
action: { | |||
type: 'encapsulate', | |||
options: { | |||
pre: '{'+'{כ}'+'}' | |||
} | |||
} | |||
} | |||
} | |||
} ); | |||
} | |||
/* תוספות לסרגל כלים משופר | |||
* | |||
*/ | |||
if ( mw.user.options.get('usebetatoolbar')) { | |||
mw.loader.using(['ext.wikiEditor'],function(){ | |||
if ($('#wikiEditor-ui-toolbar').length === 1) addToWikiEditor();//in case it loaded after toolbar initaliztion | |||
else $( '#wpTextbox1' ).on( 'wikiEditor-toolbar-doneInitialSections', addToWikiEditor); | |||
} ); | |||
} | |||
} | |||
if ( ( $.inArray( mw.config.get( 'wgAction' ), [ 'edit', 'submit' ] ) + 1 ) && | |||
!$( '#wpTextbox1' ).prop( 'readonly' ) | |||
) { | |||
$(document).ready(ExEditToolbar); | |||
} |
עריכות