مدیاویکی:Common.js: تفاوت میان نسخه‌ها

از ویکی حج
بدون خلاصۀ ویرایش
بدون خلاصۀ ویرایش
خط ۳۳: خط ۳۳:


/* دکمه های جمع شدن منوی سمت راست، بازگشت به بالای صفحه و تغییر اندازه فونت */
/* دکمه های جمع شدن منوی سمت راست، بازگشت به بالای صفحه و تغییر اندازه فونت */
/*!
 
* Hide Vector sidebar
* http://en.wikipedia.org/wiki/User:PleaseStand/Hide_Vector_sidebar
*
* Originally imported from revision 365211954 as of 2010-06-01 from
* [[User:Nihiltres/nothingthree.js]]. It has had some modification from that
* version to isolate it within the script collection and further improve it.
*
* Copyright 2010 Wikipedia user Nihiltres
* Copyright 2010-2012 Wikipedia user PleaseStand
*
* Licensed under the Creative Commons Attribution-Share-Alike 3.0 Unported License and
* the GNU Free Documentation License (unversioned); pick the license(s) of your choice.
*
* http://creativecommons.org/licenses/by-sa/3.0/
* http://www.gnu.org/copyleft/fdl.html
*/
(function( $, undefined ) {
(function( $, undefined ) {
   
   

نسخهٔ ‏۲ آوریل ۲۰۱۹، ساعت ۱۵:۱۱

/* google analytics */
  (function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
  (i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
  m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
  })(window,document,'script','https://www.google-analytics.com/analytics.js','ga');

  ga('create', 'UA-105346324-1', 'auto');
  ga('send', 'pageview');

/* end of google analytics */

/* اضافه کردن تیتر برای یادداشت ها */
$( function() {
    if($('#reflist-notes .reflist').text().length>10) {
        $('#reflist-notes').before('<h2>یادداشت‌ها</h2>');
    }
});

/* تنظیمات پاپ آپ ها */
mw.loader.using( [ 'ext.popups' ], function() { // wait for popups to be loaded

// Time to wait in ms before showing a popup on hover. Default is 500.
mw.popups.render.POPUP_DELAY = 500;

// Time to wait in ms before closing a popup on de-hover. Default is 300.
mw.popups.render.POPUP_CLOSE_DELAY = 300;

// Time to wait in ms before starting the API queries on hover, must be <= POPUP_DELAY. Default is 50.
// Don't change this unless you know what you're doing.
mw.popups.render.API_DELAY = 50;

});

/* دکمه های جمع شدن منوی سمت راست، بازگشت به بالای صفحه و تغییر اندازه فونت */

(function( $, undefined ) {
 
"use strict";
 
/**
 * Messages displayed by this script (in English).
 * Any translations (see below) replace these at runtime.
 */
var msg = {
	toggleTabText: "Toggle sidebar",
	toggleTabTitle: "Hide or show the sidebar"
};
 
/**
 * Translations for messages displayed by this script.
 * To have your translations added, please contact this script's maintainer.
 */
var translations = {
	fa: {
		toggleTabText: "تغییر وضعیت نوار سمت راست",
		toggleTabTitle: "مخفی یا نمایش نوار سمت راست",
	}
};
 
/**
 * Whether the web browser is Internet Explorer before version 9.
 */
var isOldIE = false;
 
/**
 * The text direction of the page.
 */
var dir = "ltr";
 
/**
 * The current (or default) state of the sidebar.
 */
var state = "collapsed";
 
/**
 * A cache of jQuery objects.
 */
var nodes = {};
 
/**
 * Equivalent CSS property names for RTL pages.
 */
var cssRTLProps = {
	"left": "right",
	"margin-left": "margin-right"
};
 
/**
 * Changes the CSS property name as appropriate for the page's text direction.
 * @param prop {string} The CSS property name to be changed.
 */
function flipCSSProp(prop) {
	if ( dir === "rtl" && cssRTLProps[prop] ) {
		return cssRTLProps[prop];
	}
	return prop;
}
 
/**
 * Loads the current state from sessionStorage (preferred) or localStorage.
 * If there is no item in storage, this function does nothing.
 */
function loadState() {
	state = ( window.sessionStorage && sessionStorage.getItem("sidebarToggle") ) ||
	        ( window.localStorage && localStorage.getItem("sidebarToggle") ) ||
	        state;
}
 
/**
 * Saves the current state in both sessionStorage and localStorage.
 */
function saveState() {
 
	if ( window.sessionStorage ) {
		sessionStorage.setItem( "sidebarToggle", state );
	}
 
	if ( window.localStorage ) {
		localStorage.setItem( "sidebarToggle", state );
	}
 
}
 
/**
 * Reacts to a click on the "Toggle sidebar" button.
 */
function toggle() {
 
	if ( state === "collapsed" ) {
		expand( 400 );
	} else {
		collapse( 400 );
	}
 
	saveState();
 
}
 
/**
 * Collapses the sidebar.
 * @param duration {mixed} Animation duration passed to jQuery.
 */
function collapse( duration ) {
 
	var animations = {
		mwPanelIE: {},
		mwPanelNonIE: {opacity: 0},
		notSidebar: {},
		leftNavigation: {}
	};
 
	animations.mwPanelIE[ flipCSSProp("left") ] = "-10em";
	animations.mwPanelNonIE[ flipCSSProp("left") ] = "-10em";
	animations.notSidebar[ flipCSSProp("margin-left") ] = 0;
	animations.leftNavigation[ flipCSSProp("left") ] = "1em";
 
	if ( isOldIE ) {
		nodes.$mwPanel.animate( animations.mwPanelIE, duration, function() {
			nodes.$mwPanel.css( "visibility", "hidden");
		});
	} else {
		nodes.$mwPanel.animate( animations.mwPanelNonIE, duration, function() {
			nodes.$mwPanel.css( "visibility", "hidden");
		});
	}
 
	nodes.$notSidebar.animate( animations.notSidebar, duration, function() {
		nodes.$content.css( "background-image", "none" );
	});
 
	nodes.$leftNavigation.animate( animations.leftNavigation, duration);
	
	$("#collsidebar").css("transform", "rotate(180deg)");
	
	state = "collapsed";
 
}
 
/**
 * Expands the sidebar.
 * @param duration {mixed} Animation duration passed to jQuery.
 */
function expand( duration ) {
 
	nodes.$mwPanel.css( "visibility", "" );
 
	var animations = {
		mwPanelIE: {},
		mwPanelNonIE: {opacity: 1},
		notSidebar: {},
		leftNavigation: {}
	};
 
	animations.mwPanelIE[ flipCSSProp("left") ] = "-0.01em";
	animations.mwPanelNonIE[ flipCSSProp("left") ] = 0;
	animations.notSidebar[ flipCSSProp("margin-left") ] = "11em";
	animations.leftNavigation[ flipCSSProp("left") ] = "10em";
 
	if ( isOldIE ) {
		nodes.$mwPanel.animate( animations.mwPanelIE, duration, function () {
			nodes.$mwPanel.css( flipCSSProp("left"), "0em" );
		});
	} else {
		nodes.$mwPanel.animate( animations.mwPanelNonIE, duration );
	}
 
	nodes.$content.css( "background-image", "" );
	nodes.$notSidebar.animate( animations.notSidebar, duration );
	nodes.$leftNavigation.animate( animations.leftNavigation, duration );
	
	$("#collsidebar").css("transform", "rotate(0deg)");

	state = "expanded";
 
}

function totop() {
$('html, body').animate({ scrollTop: 0 }, 500);
} 

function fontsizeup() {
	var fontSize = parseInt($('p').css("font-size"));
    fontSize = fontSize + 1 + "px";
    $('p').css({'font-size':fontSize});
}

function fontsizedown() {
	var fontSize = parseInt($('p').css("font-size"));
	fontSize = fontSize - 1 + "px";
	$('p').css({'font-size':fontSize});
}

/**
 * Called when the DOM is ready for manipulation.
 */
function ready() {
 
	// Populate jQuery object cache.
	nodes.$mwPanel = $("#mw-panel");
	nodes.$content = $("#content");
	nodes.$notSidebar = $("#content, #mw-head-base, #footer");
	nodes.$leftNavigation = $("#left-navigation");
 
	// Show the toggle tab.
	$("<button id='collsidebar'></button>")
		.prop( "title", msg.toggleTabTitle )
		.click( toggle )
		.insertAfter("#mw-panel");
		
	$("<button id='totop'></button>")
		.prop( "title", "بازگشت به بالا" )
		.click( totop )
		.insertAfter("#mw-panel");
		
		$("<button id='fontsizeup'></button>")
		.prop( "title", "افزایش اندازه قلم" )
		.click( fontsizeup )
		.insertAfter("#mw-panel");

		$("<button id='fontsizedown'></button>")
		.prop( "title", "کاهش اندازه قلم" )
		.click( fontsizedown )
		.insertAfter("#mw-panel");
		
/* 
	// Respect the saved state.
	if ( state === "collapsed" ) {
		collapse( 0 );
	}
	*/
 
}
 
/**
 * Initialization code
 */
function main() {
 
	if ( mw.config.get("skin") !== "vector" ) {
		return;
	}
 
	// Load translations and saved state.
	dir = document.documentElement.dir;
	$.extend( msg, translations[document.documentElement.lang] );
	loadState();
 
	// Detect Internet Explorer <= 8
	var profile = $.client.profile();
	isOldIE = ( profile.name === "msie" && profile.versionNumber < 9 );
 
	$(ready);
 
}
 
mw.loader.using( "jquery.client", main );

})( jQuery );