भारत की संस्कृति के लिए... भाषा की उन्नति के लिए... साहित्य के प्रसार के लिए

"मीडियाविकि:Common.js" के अवतरणों में अंतर

Kavita Kosh से
यहाँ जाएँ: भ्रमण, खोज
 
(इसी सदस्य द्वारा किये गये बीच के 11 अवतरण नहीं दर्शाए गए)
पंक्ति 206: पंक्ति 206:
 
//////////////////////////////////////////////////////////////////////
 
//////////////////////////////////////////////////////////////////////
  
//Cite Popups
 
  
function findPosition(indx) {
 
/* This function is based on code obtained from:
 
http://www.softcomplex.com/docs/
 
get_window_size_and_scrollbar_position.html */
 
  
var dir = {
 
'clientWidth' : 'innerWidth',
 
'clientHeight' : 'innerHeight',
 
'scrollLeft' : 'pageXOffset',
 
'scrollTop' : 'pageYOffset'
 
};
 
  
var qarr = [
 
window[dir[indx]] ? window[dir[indx]] : 0,
 
document.documentElement ? document.documentElement[indx] : 0,
 
document.body ? document.body[indx] : 0
 
];
 
  
qarr.sort(function(a, b) {return a - b});
+
/* ***************************************************************************
while(qarr[0] == 0) { qarr.shift() }
+
Word Meanings
return qarr.length ? qarr[0] : 0;
+
*************************************************************************** */
 +
mArea = ".KKMmm";
 +
wArea = ".KKMwordmeaning";
 +
function KKMm(w) {
 +
if(w == ""){return;}
 +
$(wArea).html("<div class='KKMloader'></div>");
 +
$(".KKMloader").css("display", "block");
 +
var pData = {"w" : w};
 +
jQuery.ajax({
 +
url: "/kk/otherapps/dictionary/LalitKumarSystemF5RE3V-FindMeaning.php",
 +
data: pData,
 +
type: "POST",
 +
async: false,
 +
success:function(data){$(mArea).animate({bottom: "+=50px",}, "fast");$(wArea).html(data);}
 +
});
 +
 
 
}
 
}
  
function showFootnote(evnt) {
+
function KKMc(){
var e = window.event ? window.event : evnt;
+
mAreaC = ".KKMwordmeaningC";
var obj = window.event ? window.event.srcElement : evnt.target;
+
$(mAreaC).css("display", "block");
 +
}
 +
function KKMo(){ $(".KKMmm").css("display", "block"); $(mAreaC).css("display", "none");}
  
// Is this link a ref tag
+
function KKMShowMeaning(){
if(obj.tagName != "A") return;
+
var t = true;
if(!obj.hash) return;
+
if ($(".poem p").length != 0){t = true;}
if(obj.hash.substr(0,11) != "#cite_note-") return;
+
if ($("#mw-normal-catlinks ul li a:contains(' रचना')").length != 0){t = false;}
if(obj.parentNode.className != "reference") return;
+
if ($("#mw-normal-catlinks ul li a:contains('प्रसिद्ध रचना')").length != 0){t = true;}
 
+
if ($("#mw-normal-catlinks ul li a:contains('लम्बी रचना')").length != 0){t = true;}
// Is there a footnote to display?
+
if ($("#mw-normal-catlinks ul li a:contains('दलित रचना')").length != 0){t = true;}
// Someone may have forgotten the <references/> tag
+
if ($("#mw-normal-catlinks ul li a:contains('नज़्म')").length != 0){t = false;}
var footnote_id = obj.hash.substr(1);
+
if ($("#mw-normal-catlinks ul li a:contains('ग़ज़ल')").length != 0){t = false;}
if(!document.getElementById(footnote_id)) return;
+
return t;
 
+
// Good, hide the popup, if it isn't already hidden
+
if(footnote.style.visibility != "hidden") { resetFootnote() }
+
 
+
// Fetch the footnote text and remove the unnecessary back link(s)
+
// This is a little messy as there's no containing tags
+
var fn_text = document.getElementById(footnote_id).innerHTML;
+
fn_text = fn_text.replace(/^.*<a[^>]*href="#cite_ref-.*?<\/a> */i, ""); // "
+
 
+
// Insert the footnote text
+
footnote.innerHTML = fn_text;
+
 
+
// Decide where to put the popup
+
var window_width = findPosition('clientWidth');
+
var window_height = findPosition('clientHeight');
+
 
+
var horizontal_position = e.clientX;
+
var vertical_position = e.clientY;
+
 
+
var horizontal = findPosition('scrollLeft') + horizontal_position;
+
var vertical = findPosition('scrollTop') + vertical_position;
+
 
+
var footnote_width = footnote.offsetWidth;
+
var footnote_height = footnote.offsetHeight;
+
 
+
if(window_height - vertical_position < footnote_height) {
+
footnote.style.top = "";
+
footnote.style.bottom = (window_height - vertical - 13) + "px";
+
} else {
+
footnote.style.top = (vertical - 13) + "px";
+
footnote.style.bottom = "";
+
}
+
 
+
if(window_width - horizontal_position > footnote_width) {
+
footnote.style.left = (horizontal - 13) + "px";
+
footnote.style.right = "";
+
} else {
+
footnote.style.left = "";
+
footnote.style.right = (window_width - horizontal - 13) + "px";
+
}  
+
 
+
//Make the popup visible
+
footnote.style.visibility = "visible";
+
 
}
 
}
  
function hideFootnote(evnt) {
+
$(document).ready(function() {
var obj = window.event ? window.event.srcElement : evnt.target;
+
  
// No point in going on if popup is already hidden
+
if(KKMShowMeaning()){
if(footnote.style.visibility == "hidden") return;
+
KKMc();
 +
    var p = $('.poem p');
 +
var wmAv = $('.poem').prepend("<div class='wmAv'>हिन्दी शब्दों के अर्थ उपलब्ध हैं। शब्द पर डबल क्लिक करें। अन्य शब्दों पर कार्य जारी है।</div>");
 +
    p.css({ cursor: 'pointer' });
 +
    p.dblclick(function(e) {
 +
$(mArea).animate({bottom: "-=50px"}, "fast")
 +
KKMc();
 +
        var range = window.getSelection() || document.getSelection() || document.selection.createRange();
 +
        var w = $.trim(range.toString());
 +
        if(w != '') {
 +
            KKMm(w);
 +
KKMo();
 +
        }
 +
        range.collapse();
 +
        e.stopPropagation();
 +
    });
  
// Search the tree to see where the curser is
+
$(mAreaC).css("display", "none");
var depth = 0; // no need to search too much
+
while(obj && obj.parentNode && depth < 5) {
+
if(obj.id == "footnote" || obj.id.substr(0, 9) == "cite_ref-") { return; }
+
obj = obj.parentNode;
+
depth++;
+
}
+
+
resetFootnote();
+
}
+
  
function resetFootnote() {
+
$(".KKMcloseMeaning").click(function(e) {
footnote.style.visibility = "hidden";
+
$(".KKMmm").css("display", "none");
footnote.style.left = 0;
+
});
footnote.style.top = 0;
+
footnote.style.right = "auto";
+
footnote.style.bottom = "auto";
+
 
}
 
}
 +
});
 +
//////////////////////////////////////////////////////////////////////
  
// Set up the float element
 
var footnote = document.createElement("DIV");
 
footnote.id = "footnote";
 
footnote.style.position = "absolute";
 
footnote.style.zIndex = 500;
 
footnote.style.border = "1px solid black";
 
footnote.style.backgroundColor = "lightyellow";
 
footnote.style.maxWidth = "450px";
 
footnote.style.textAlign = "justify";
 
footnote.style.padding = "5px";
 
footnote.style.fontSize = "10pt";
 
resetFootnote();
 
  
document.body.appendChild(footnote);
 
  
// Add events
 
addHandler(document, "mouseover", showFootnote);
 
addHandler(document, "mousemove", hideFootnote);
 
  
  
 +
/* ***************************************************************************
 +
Function for showing star volunteers' random photo
 +
*************************************************************************** */
 +
var randomImagesArray = ["1.jpg",
 +
"2.jpg",
 +
"3.jpg",
 +
"4.jpg",
 +
"5.jpg",
 +
"6.jpg",
 +
"7.jpg"];
 +
var rImageBase = "http://kavitakosh.org/kk/otherapps/ramdom-photo/star-volunteers/";
  
////////////////////////////////////////////////////////////
+
function displayRPic(){
 +
    var num = Math.floor(Math.random() * 7); // 0...6
 +
    document.getElementById("rPicStarVolunteers").src = rImageBase+randomImagesArray[num];
 +
}
 +
displayRPic();

18:30, 18 अगस्त 2018 के समय का अवतरण

if ( mw.toolbar ) {
    mw.toolbar.addButton( {
        "imageFile": "http://www.kavitakosh.org/kk/images/c/cd/Button_poem.png",
        "speedTip": "Poem tag",
        "tagOpen": "<poem>",
        "tagClose": "</poem>",
        "sampleText": "रचना यहाँ टाइप करें"
    } );

    mw.toolbar.addButton( {
        "imageFile": "http://upload.wikimedia.org/wikipedia/en/c/c8/Button_redirect.png",
        "speedTip": "Redirect",
        "tagOpen": "#REDIRECT [[",
        "tagClose": "]]",
        "sampleText": "Insert text"
    } );
}

/* ***************************************************************************
Function to insert text in a textarea (may be on click of a link or button
*************************************************************************** */
function insertAtCaret(areaId,text) {
    var txtarea = document.getElementById(areaId);
    var scrollPos = txtarea.scrollTop;
    var strPos = 0;
    var br = ((txtarea.selectionStart || txtarea.selectionStart == '0') ? 
        "ff" : (document.selection ? "ie" : false ) );
    if (br == "ie") { 
        txtarea.focus();
        var range = document.selection.createRange();
        range.moveStart ('character', -txtarea.value.length);
        strPos = range.text.length;
    }
    else if (br == "ff") strPos = txtarea.selectionStart;

    var front = (txtarea.value).substring(0,strPos);  
    var back = (txtarea.value).substring(strPos,txtarea.value.length); 
    txtarea.value=front+text+back;
    strPos = strPos + text.length;
    if (br == "ie") { 
        txtarea.focus();
        var range = document.selection.createRange();
        range.moveStart ('character', -txtarea.value.length);
        range.moveStart ('character', strPos);
        range.moveEnd ('character', 0);
        range.select();
    }
    else if (br == "ff") {
        txtarea.selectionStart = strPos;
        txtarea.selectionEnd = strPos;
        txtarea.focus();
    }
    txtarea.scrollTop = scrollPos;
}
/*  *************************************************************************** */



/* ***************************************************************************
Functions for transliteration
*************************************************************************** */
function decideLipi(rootEl){
var curkklipi=getCookie("kklipi");
var defaultkklipi="hi";
if (curkklipi=="en"){walkTheDomAndTranslit(rootEl);}
else{setCookie("kklipi",defaultkklipi,365);}
}
function walkTheDomAndTranslit(rootEl){
var rootnode=document.getElementById(rootEl);
var walker=document.createTreeWalker(rootnode, NodeFilter.SHOW_TEXT, null, false);
while (walker.nextNode()){
var tstr=unicode2itrans(walker.currentNode.textContent);
walker.currentNode.textContent=tstr;
}
var tButton=document.getElementById('translitButton');
tButton.innerHTML="देवनागरी में बदलें";
tButton.onclick = function() {setCookie('kklipi', 'hi'); window.location.reload();};
setCookie('kklipi', 'en');
}
function unicode2itrans(strText){
var array_one = new Array( "आ", "ऑ", "अ", "ई", "इ", "ऊ", "उ", "ऋ", "ए", "ऐ", "ओ", "औ","ा", "ि", "ी", "ु", "ू", "ृ", "े", "ै", "ो", "ौ", "ं", "ँ", ":", "्", "ऽ", "ॉ","क़", "ख़", "ग़", "ज़", "ड़", "ढ़", "फ़","क", "ख", "ग", "घ", "ङ", "च", "छ", "ज", "झ", "ञ", "ट", "ठ", "ड", "ढ", "ण","त", "थ", "द", "ध", "न", "प", "फ", "ब", "भ", "म","य", "र", "ल", "व", "श", "ष", "स", "ह","Z.hY", "ZY", "ZV", "aV", "V", "W", "Y", "Z","०", "१", "२", "३", "४", "५", "६", "७", "८", "९", "।", "ॐ" );
var array_two= new Array( "VaaW", "Vaa.uW", "VaW", "VeeW", "ViW", "VooW", "VuW", "VRRiW", "VeW", "VaiW", "VoW", "VauW","aa", "i", "ee", "u", "oo", "Ri", "e", "ai", "o", "au", ".n", ".N", "aH", ".h", ".a", " aa.u","YqZ", "YKhZ", "YGZ", "YzZ", " Y.DZ", "Y.DhZ", "YfZ", "YkZ", "YkhZ", "YgZ", "YghZ", "Y~NZ", "YchZ", "YchhZ", "YjZ", "YjhZ", "Y~nZ", "YTZ", "YThZ", "YDZ", "YDhZ", "YNZ","YtZ", "YthZ", "YdZ", "YdhZ", "YnZ", "YpZ", "YphZ", "YbZ", "YbhZ", "YmZ","YyZ", "YrZ",  "YlZ", "YvZ", "YshZ", "YShZ", "YsZ", "YhZ","", "a", "a_", "a_", "", "", "", "","0", "1", "2", "3", "4", "5", "6", "7", "8", "9", ".", "OM" );
text2BProcessed = strText;
for (ctr=0; ctr < 95; ctr++){
var idx = 0;
while ( idx != -1 ){
text2BProcessed = text2BProcessed.replace(array_one[ctr] , array_two[ctr]);
idx = text2BProcessed.indexOf(array_one[ctr]);}
}
return text2BProcessed;
}
function setCookie(cname,cvalue,exdays){
var d = new Date();
d.setTime(d.getTime()+(exdays*24*60*60*1000));
var expires = "expires="+d.toGMTString();
document.cookie = cname+"="+cvalue+"; "+expires;
}
function getCookie(cname){
var name = cname + "=";
var ca = document.cookie.split(';');
for(var i=0; i<ca.length; i++){
var c = ca[i].trim();
if (c.indexOf(name)==0) return c.substring(name.length,c.length);
}
return "";
}
/*  *************************************************************************** */




//Call function to decide which lipi is to be used for displaying the page.
$(function() {
decideLipi('globalWrapper');
});




// This function opens a page based on the value of option selected by user from a SELECT html dropdown box
function gotoPageOnSelect(wrapperElement, selectElement){
var wrapperElement=document.getElementById(wrapperElement);
var selectedOption=document.getElementById(selectElement).value;
if (selectedOption!="") {
var baseloc = "http://kavitakosh.org/kk/";
wrapperElement.innerHTML=""
wrapperElement.innerHTML="लोडिंग... ";
self.location.href=baseloc+selectedOption;
}
}


////////////////////////////


// To float anchor list in Rachnakaaro Ki Soochi
var $poetAnchorsExistRef = $('#poet-list-anchors-container');
$(document).ready( function() {

        if($poetAnchorsExistRef.length){
                $('#poet-list-anchors').addClass('visible');
        }
} );

// To togle the anchor list visibility
$(document).ready(function(){

  $("#poet-list-letter-set-toggle").click(function(){
    $("#poet-list-letter-set").toggle(400);
  });


  $('#poet-list-letter-set a').click(function(){
    $('html, body').animate({
        scrollTop: $( $(this).attr('href') ).offset().top
    }, 500);
    return false;
  });


});


////////////////////////////


//for multi-lingual transliteration

var srcText = ""; //keep it global
var targetEl = '.poem p';
var trgScript = "";

if ( $(targetEl).length) { $( "#mtransbtnDiv" ).css("display", "inline-block");}
else{$( "#mtransbtnDiv").css("display", "none");}

function convert(t) {
trgScript = t;

if(t ==="x"){if(srcText != ""){$(targetEl).css("font-size", "16px"); $(targetEl).html(srcText);} return;}
if(srcText === ""){srcText = $(targetEl).html();}
$(targetEl).html("<i class='fa fa-refresh fa-spin fa-3x fa-fw'></i><span class='sr-only'>लोडिंग...</span>");
	var pData = {"TextToConvert" : srcText, "srcScript": 1, "trgScript": trgScript};
	jQuery.ajax({
	url: "http://kavitakosh.org/kk/otherapps/transliteration/convertAjax.php",
	data: pData,
	type: "POST",
	success:function(data){$(targetEl).html(data);}
	});

}

jQuery(document).ajaxStop(function() {
	trgFontSize = "16px;"
	switch(trgScript) {
		case 0: trgFontSize = "16px"; break; //roman
		case 2: trgFontSize = "16px"; break; //diacritic
		case 3: trgFontSize = "16px"; break; //ipa
		case 4: trgFontSize = "16px"; break; //gujarati
		case 5: trgFontSize = "16px"; break; //gurumukhi
		case 6: trgFontSize = "16px"; break; //bangla
	}
	$(targetEl).css("font-size", trgFontSize);
});


//////////////////////////////////////////////////////////////////////





/* ***************************************************************************
Word Meanings
*************************************************************************** */
mArea = ".KKMmm";
wArea = ".KKMwordmeaning";
function KKMm(w) {
if(w == ""){return;}
$(wArea).html("<div class='KKMloader'></div>");
$(".KKMloader").css("display", "block");
	var pData = {"w" : w};
	jQuery.ajax({
	url: "/kk/otherapps/dictionary/LalitKumarSystemF5RE3V-FindMeaning.php",
	data: pData,
	type: "POST",
	async: false,
	success:function(data){$(mArea).animate({bottom: "+=50px",}, "fast");$(wArea).html(data);}
	});

}

function KKMc(){
mAreaC = ".KKMwordmeaningC";
$(mAreaC).css("display", "block");
}
function KKMo(){ $(".KKMmm").css("display", "block"); $(mAreaC).css("display", "none");}

function KKMShowMeaning(){
var t = true;
if ($(".poem p").length != 0){t = true;}
if ($("#mw-normal-catlinks ul li a:contains(' रचना')").length != 0){t = false;}
if ($("#mw-normal-catlinks ul li a:contains('प्रसिद्ध रचना')").length != 0){t = true;}
if ($("#mw-normal-catlinks ul li a:contains('लम्बी रचना')").length != 0){t = true;}
if ($("#mw-normal-catlinks ul li a:contains('दलित रचना')").length != 0){t = true;}
if ($("#mw-normal-catlinks ul li a:contains('नज़्म')").length != 0){t = false;}
if ($("#mw-normal-catlinks ul li a:contains('ग़ज़ल')").length != 0){t = false;}
return t;
}

$(document).ready(function() {

if(KKMShowMeaning()){
	KKMc();
    var p = $('.poem p');
var wmAv = $('.poem').prepend("<div class='wmAv'>हिन्दी शब्दों के अर्थ उपलब्ध हैं। शब्द पर डबल क्लिक करें। अन्य शब्दों पर कार्य जारी है।</div>");
    p.css({ cursor: 'pointer' });
    p.dblclick(function(e) {
		$(mArea).animate({bottom: "-=50px"}, "fast")	
		KKMc();
        var range = window.getSelection() || document.getSelection() || document.selection.createRange();
        var w = $.trim(range.toString());
        if(w != '') {
            KKMm(w);
			KKMo();
        }
        range.collapse();
        e.stopPropagation();
    });

	$(mAreaC).css("display", "none");

	$(".KKMcloseMeaning").click(function(e) {
	$(".KKMmm").css("display", "none");
	});
}
});
//////////////////////////////////////////////////////////////////////





/* ***************************************************************************
Function for showing star volunteers' random photo
*************************************************************************** */
var randomImagesArray = ["1.jpg", 
"2.jpg", 
"3.jpg", 
"4.jpg", 
"5.jpg", 
"6.jpg",
"7.jpg"];
var rImageBase = "http://kavitakosh.org/kk/otherapps/ramdom-photo/star-volunteers/";

function displayRPic(){
    var num = Math.floor(Math.random() * 7); // 0...6
    document.getElementById("rPicStarVolunteers").src = rImageBase+randomImagesArray[num];
}
displayRPic();