מדיה ויקי:Templateslist.js

הערה: לאחר הפרסום, ייתכן שיהיה צורך לנקות את זיכרון המטמון (cache) של הדפדפן כדי להבחין בשינויים.

  • פיירפוקס / ספארי: להחזיק את המקש Shift בעת לחיצה על טעינה מחדש (Reload) או ללחוץ על צירוף המקשים Ctrl-F5 או Ctrl-R (במחשב מק: ⌘-R).
  • גוגל כרום: ללחוץ על צירוף המקשים Ctrl-Shift-R (במחשב מק: ⌘-Shift-R).
  • אינטרנט אקספלורר / אדג': להחזיק את המקש Ctrl בעת לחיצה על רענן (Refresh) או ללחוץ על צירוף המקשים Ctrl-F5.
  • אופרה: ללחוץ על Ctrl-F5.
/* הוספת רשימת תבניות בסרגל הכלים, נכתב על ידי [[משתמש:ערן]] */
$( function () {
	var templates = [ 'תבניות להוספה' ];

	var templatesText = [];

	// add template to list of templates
	function AddTemplateToList( title, before, middle, after ) {
		templates.push( title );
		templatesText[ templates.length - 1 ] = [];
		templatesText[ templates.length - 1 ][ 0 ] = before;
		templatesText[ templates.length - 1 ][ 1 ] = middle;
		templatesText[ templates.length - 1 ][ 2 ] = after;
	}

	// add template to list if it isn't already contained in the article text
	function addSingleTemplateToList( title, before, middle, after ) {
		if ( document.getElementById( 'wpTextbox1' ) ) {
			if ( document.getElementById( 'wpTextbox1' ).value.indexOf( before ) === -1 ) {
				AddTemplateToList( title, before, middle, after );
			}
		}
	}

	// Defines the templates
	function beforeListInit() {
		switch ( mw.config.get( 'wgNamespaceNumber' ) ) {
			case 6:// templates for images
				AddTemplateToList( 'הוחלף בתמונה ווקטורית', '{' + '{הוחלף בווקטור|', '', '}}' );
				AddTemplateToList( 'ייחוס', '{' + '{ייחוס}}', '', '' );
				AddTemplateToList( 'כפילות עם תמונה מוויקישיתוף', '{' + '{גם בוויקישיתוף}}', '', '' );
				AddTemplateToList( 'להחליף בתמונה ווקטורית', '{' + '{SVG}}', '', '' );
				AddTemplateToList( 'מידע', '{{' + 'מידע\n|תיאור=', '', '\n|מקור=\n|תאריך יצירה=\n|יוצר=\n|אישורים והיתרים=\n}}' );
				AddTemplateToList( 'רישיון CC', '{' + '{Cc-by-sa-3.0}}', '', '' );
				AddTemplateToList( 'רישיון GFDL', '{' + '{GFDL}}', '', '' );
				AddTemplateToList( 'שימוש הוגן', '{' + '{שימוש הוגן|מקור=', 'ציינו מקור', '|ערך=}}' );
				AddTemplateToList( 'תמונה חשודה', '{{ס:' + 'תמונה חשודה|', 'ציינו סיבה', '}}' );
				break;
			case 10:// templates for templates
				AddTemplateToList( 'פרמטר', '{{{', '*שם הפרמטר*|*ערך ברירת מחדל*', '}}}' );
				AddTemplateToList( 'קטגוריה', '\n[' + '[קטגוריה:', 'שם הקטגוריה', ']]' );
				AddTemplateToList( 'קטע שיופיע רק בדף התבנית', '<no' + 'include>', 'טקסט שיופיע בתבנית ולא בדפים המשתמשים בה', '</no' + 'include>' );
				AddTemplateToList( 'קטע שיופיע רק בדפים המכילים את התבנית', '<include' + 'only>', 'טקסט שיופיע בדפים המשתמשים בתבנית בלבד', '</include' + 'only>' );
				AddTemplateToList( 'תבנית ניווט', '{{ניווט' + '\n|תמונה=תמונה, כולל קישור וגודל. ברירת מחדל - ללא תמונה\n|תוכן=', '', '\n}}' );

				break;
			case 14:// templates for categories
				addSingleTemplateToList( 'הבהרת חשיבות', '{' + '{ס:הבהרת חשיבות}}', '', '' );
				AddTemplateToList( 'פתיח סטנדרטי לקטגוריה', '{{קטגוריה|קשור|', 'נושא שאליו הערכים בקטגוריה קשורים|ערך ראשי', '}}' );
				AddTemplateToList( 'קטגוריה', '\n[' + '[קטגוריה:', 'שם הקטגוריה', ']]' );
				AddTemplateToList( 'תבנית מיזמים', '{{מיזמים|ויקישיתוף=', 'שם הדף בוויקישיתוף', '}}' );
				AddTemplateToList( 'תוכן עניינים', '{{Category' + 'TOC}}', '', '' );
				break;
			default:// templates for other namespaces
				AddTemplateToList( 'אין תמונה', '', '{{אין' + ' תמונה}}', '' );
				addSingleTemplateToList( 'בעבודה', '', '\n{' + '{בעבודה}}', '\n' );
				addSingleTemplateToList( 'הבהרת חשיבות', '', '{' + '{ס:הבהרת חשיבות}}', '' );
				addSingleTemplateToList( 'הודעת קצרמר', '', '\n{' + '{קצרמר}}', '' );
				AddTemplateToList( 'הפניה לערך מורחב', '{' + '{הפניה לערך מורחב', '|', '}}' );
				AddTemplateToList( 'הערת שוליים - הפניה', '', '{{הערה|שם=שם-הערה}}', '' );
				addSingleTemplateToList( 'הערת שוליים - כותרת', '\n==הערות שוליים==', '\n{' + '{הערות שוליים|יישור=ימין}}', '' );
				AddTemplateToList( 'הפרת זכויות יוצרים', '\n{' + '{הפרת זכויות יוצרים|מקור=', ' המקור שממנו הועתק התוכן ', '|זמן={' + '{ס:יום נוכחי}}/{' + '{ס:חודש נוכחי}}/{' + '{ס:שנה נוכחית}}(~~' + '~~' + '~)}}\n' );
				addSingleTemplateToList( 'לקריאה נוספת', '\n==לקריאה נוספת==\n', '* שם סופר, \'\'\'שם ספר\'\'\', שם הוצאה, תאריך הוצאה\n', '' );
				AddTemplateToList( 'מפנה', '{' + '{מפנה|', 'הדף המפנה|הסבר על הדף האחר|שם הדף האחר', '}}' );
				addSingleTemplateToList( 'פירוש נוסף', '{' + '{פירוש נוסף|', 'נוכחי=|אחר=|ראו=', '}}' );
				addSingleTemplateToList( 'פירושונים', '\n{' + '{פירושונים|' + '\n', '* [[' + 'ערך 1]] - הסבר קצר על מהותו של ערך 1\n* [[' + 'ערך 2]] - הסבר קצר על מהותו של ערך 2', '\n}}' );
				AddTemplateToList( 'ציטוט', '{' + '{ציטוט|תוכן=', 'הזינו ציטוט כאן', '}}' );
				AddTemplateToList( 'קטגוריה', '\n[' + '[קטגוריה:', 'שם הקטגוריה', ']]' );
				addSingleTemplateToList( 'קישורים חיצוניים', '\n==קישורים חיצוניים==\n', '* שם כותב, [' + 'Address תיאור המאמר], שם האתר\n', '' );
				addSingleTemplateToList( 'ראו גם', '\n==ראו גם==\n', '* [' + '[שם ערך]]\n', '' );
				AddTemplateToList( 'תבנית מיזמים', '{{מיזמים|ויקישיתוף=', 'שם הדף בוויקישיתוף', '}}' );
		}
	}

	function initTemplatesList() {
		var action = mw.config.get( 'wgAction' );
		if ( action !== 'edit' && action !== 'submit' ) { return; } // not edit page
		var $toolbar = $( '#toolbar' );
		if ( !$toolbar.length ) { return; } // no toolbar
		beforeListInit();
		var $select = $( '<select>', { id: 'templatesList' } ).change( function () {
			insertTemplate( this.selectedIndex );
			this.selectedIndex = 0;
			return false;
		} );

		$( templates ).each( function () { $select.append( $( '<option>', { text: this, title: this } ) ); } );

		// add to toolbar
		toolbar.append( $select );
	}

	function insertTemplate( index ) {
		if ( index > 0 ) {
			insertTags( templatesText[ index ][ 0 ], templatesText[ index ][ 2 ], templatesText[ index ][ 1 ] );
		}
	}

	if ( mw.user.options.get( 'usebetatoolbar' ) ) {
		mw.loader.using( [ 'ext.wikiEditor' ], function () {
			if ( typeof $.wikiEditor !== 'undefined' ) { beforeListInit(); }
			var templateListAdv = {
				label: 'תבניות להוספה',
				type: 'select',
				list: { }
			};

			for ( var i = 1; i < templates.length; i++ ) {
				var addiontalMessages = {};
				for ( var j = 0; j < 3; j++ ) {
					if ( templatesText[ i ][ j ] !== '' ) {
						addiontalMessages[ templatesText[ i ][ j ] ] = templatesText[ i ][ j ];
					}
				}
				mw.messages.set( addiontalMessages );

				templateListAdv.list[ 'template' + i ] = {
					label: templates[ i ],
					action: {
						type: 'encapsulate',
						options: {
							pre: templatesText[ i ][ 0 ],
							peri: templatesText[ i ][ 1 ],
							post: templatesText[ i ][ 2 ]
						}
					}
				};
			}
			$( '#wpTextbox1' ).wikiEditor( 'addToToolbar', {
				section: 'advanced',
				group: 'heading',
				tools: { templateListAdv: templateListAdv }
			} );
		} );
	} else { initTemplatesList(); }
} );