"മീഡിയവിക്കി:Common.js" എന്ന താളിന്റെ പതിപ്പുകൾ തമ്മിലുള്ള വ്യത്യാസം

Schoolwiki സംരംഭത്തിൽ നിന്ന്
(ചെ.)No edit summary
(ചെ.)No edit summary
വരി 3: വരി 3:


document.addEventListener("DOMContentLoaded", function () {
document.addEventListener("DOMContentLoaded", function () {
     // Check if L (Leaflet) is loaded
     // Function to replace the marker URL
     if (typeof L !== "undefined" && L.Marker) {
     function replaceMarkerIcons() {
         // Define a custom icon
         // Select all img elements in the leaflet-marker-pane
         const customIcon = L.icon({
         const markerIcons = document.querySelectorAll('.leaflet-marker-pane img');
             iconUrl: "https://schoolwiki.in/extensions/Kartographer/lib/external/mapbox/images/marker-icon-2x.png",
        markerIcons.forEach(function (img) {
            iconSize: [30, 70], // Size of the icon
             if (img.src.includes("https://tile.openstreetmap.org/v4/marker/pin-m+7e7e7e@2x.png")) {
             iconAnchor: [15, 35] // Point of the icon which will correspond to the marker's location
                img.src = "https://schoolwiki.in/extensions/Kartographer/lib/external/mapbox/images/marker-icon-2x.png";
             }
         });
         });
    }


        // Override the default marker icon
    // Initial replacement on page load
        L.Marker.prototype.options.icon = customIcon;
     replaceMarkerIcons();
     } else {
        console.error("Leaflet is not loaded. Make sure the map is initialized properly.");
    }
});


  console.log ("map replace");
    // MutationObserver to catch dynamically added markers
    function replaceMarkerImage(newUrl) {
    const observer = new MutationObserver(function (mutations) {
        // Get all image elements with the target class
        mutations.forEach(function (mutation) {
        const imageElements = document.querySelectorAll('img.leaflet-marker-icon');
            mutation.addedNodes.forEach(function (node) {
                // If a new img is added, check if it matches the target URL
                if (node.nodeType === 1 && node.matches && node.matches('.leaflet-marker-pane img')) {
                    if (node.src.includes("https://tile.openstreetmap.org/v4/marker/pin-m+7e7e7e@2x.png")) {
                        node.src = "https://schoolwiki.in/extensions/Kartographer/lib/external/mapbox/images/marker-icon-2x.png";
                    }
                }
            });
        });
    });


        // Loop through each image element and update the src
    // Start observing the leaflet container for changes
         imageElements.forEach(image => {
    const mapContainer = document.querySelector('.leaflet-container');
             // Update the image source directly
    if (mapContainer) {
             image.src = newUrl;
         observer.observe(mapContainer, {
             childList: true,
             subtree: true
         });
         });
    } else {
        console.error("Leaflet map container not found.");
     }
     }
 
});
    // Example usage:
    const newImageUrl = 'https://schoolwiki.in/extensions/Kartographer/lib/external/mapbox/images/marker-icon-2x.png'; // Replace with the new URL
 
    // Call the function to replace the marker images
    replaceMarkerImage(newImageUrl);
 
 


//Quick Edit Box  
//Quick Edit Box  

11:57, 7 ജനുവരി 2025-നു നിലവിലുണ്ടായിരുന്ന രൂപം

mw.loader.load('//en.wikipedia.org/w/index.php?title=User:Joeytje50/JWB.js/load.js&action=raw&ctype=text/javascript');


document.addEventListener("DOMContentLoaded", function () {
    // Function to replace the marker URL
    function replaceMarkerIcons() {
        // Select all img elements in the leaflet-marker-pane
        const markerIcons = document.querySelectorAll('.leaflet-marker-pane img');
        markerIcons.forEach(function (img) {
            if (img.src.includes("https://tile.openstreetmap.org/v4/marker/pin-m+7e7e7e@2x.png")) {
                img.src = "https://schoolwiki.in/extensions/Kartographer/lib/external/mapbox/images/marker-icon-2x.png";
            }
        });
    }

    // Initial replacement on page load
    replaceMarkerIcons();

    // MutationObserver to catch dynamically added markers
    const observer = new MutationObserver(function (mutations) {
        mutations.forEach(function (mutation) {
            mutation.addedNodes.forEach(function (node) {
                // If a new img is added, check if it matches the target URL
                if (node.nodeType === 1 && node.matches && node.matches('.leaflet-marker-pane img')) {
                    if (node.src.includes("https://tile.openstreetmap.org/v4/marker/pin-m+7e7e7e@2x.png")) {
                        node.src = "https://schoolwiki.in/extensions/Kartographer/lib/external/mapbox/images/marker-icon-2x.png";
                    }
                }
            });
        });
    });

    // Start observing the leaflet container for changes
    const mapContainer = document.querySelector('.leaflet-container');
    if (mapContainer) {
        observer.observe(mapContainer, {
            childList: true,
            subtree: true
        });
    } else {
        console.error("Leaflet map container not found.");
    }
});

//Quick Edit Box 
// [[User:BrandonXLF/QuickEdit.js]]
//mw.loader.load('https://en.wikipedia.org/w/index.php?title=User:BrandonXLF/QuickEdit.js&action=raw&ctype=text/javascript');
//mw.loader.load( '/index.php?title=മീഡിയവിക്കി:Common.js/QuickEdit.js&action=raw&ctype=text/javascript' );

/*ടൂൾബാറിൽ അവലംബം ചേർക്കാനുള്ള സൗകര്യം കൂട്ടിച്ചേർക്കുന്നതിനായി */
if ( mw.config.get( 'wgAction' ) === 'edit' || mw.config.get( 'wgAction' ) === 'submit' || mw.config.get( 'wgCanonicalSpecialPageName' ) === 'Upload' ) {
    /* scripts specific to editing pages */
/*    importScript( 'മീഡിയവിക്കി:Common.js/edit.js' ); */
    mw.loader.load( '/index.php?title=മീഡിയവിക്കി:Common.js/edit.js&action=raw&ctype=text/javascript' );
}


/*
==addCharSubsetMenu==
*/

/* add menu for selecting subsets of secial characters  */
/***** must match MediaWiki:Edittools *****/
function addCharSubsetMenu() {
	if($('#editpage-specialchars').length>0) {
		/* default subset from cookie */
		var s = parseInt( $.cookie('edittoolscharsubset') );
		if ( isNaN(s) ) s = 0;
		var $menu = $('<select />')
		.attr('id', 'charSubsetControl')
		.css('display', 'inline');
		$menu.change(chooseCharSubset)
		.data('previousSelectedIndex', s)
		.append($('<option />').text('ഫലകങ്ങൾ'))
		.append($('<option />').text('വിക്കിവിന്യാസങ്ങൾ'))
		.append($('<option />').text('അനുമതിപത്രങ്ങൾ'))
		.append($('<option />').text('മലയാളം'))
		.append($('<option />').text('കൊറിയൻ'))
		.append($('<option />').text('ലത്തീൻ'))
		.append($('<option />').text('ഐ.പി.എ.'))
		.append($('<option />').text('പലവക'))
		.append($('<option />').text('അറബി'))
		.append($('<option />').text('ദേവനാഗരി'))
		.append($('<option />').text('ഹിബ്രു'))
		.append($('<option />').text('പഴയ ഇംഗ്ലീഷ്'));
		$('#editpage-specialchars').prepend($menu);
		/* update dropdown control to value of cookie */
		$('#charSubsetControl')[0].selectedIndex = s;
		$('p', '#editpage-specialchars').each(function(index) {
			if(index==s) {
				$(this).css('display', 'inline');
				$(this).css('visibility', 'visible');
			} else {
				$(this).css('display', 'none');
				$(this).css('visibility', 'hidden');
			}
		});
	}
}

/* 
===chooseCharSubsetMenu===
 */
/* select subsection of special characters */
function chooseCharSubset() {
	var selectedIndex = $(this).find(':selected').index();
	$('p', '#editpage-specialchars').each(function(index) {
		if(index==selectedIndex) {
			$(this).css('display', 'inline');
			$(this).css('visibility', 'visible');
		}else {
			$(this).css('display', 'none');
			$(this).css('visibility', 'hidden');
		}
	});
	$.cookie('edittoolscharsubset', selectedIndex);
	$(this).data('previousSelectedIndex', selectedIndex);
}

/* 
== customizeWikipedia ==
 */

function customizeWikipedia() {
	addCharSubsetMenu();
}
 
$(customizeWikipedia);

/**
 * Dynamic Navigation Bars (experimental)
 *
 * Description: See [[Wikipedia:NavFrame]].
 * Maintainers: UNMAINTAINED
 */

/* set up the words in your language */
var NavigationBarHide = 'മറയ്ക്കുക';
var NavigationBarShow = 'പ്രദർശിപ്പിക്കുക';
var indexNavigationBar = 0;

/**
 * Shows and hides content and picture (if available) of navigation bars
 * Parameters:
 *     indexNavigationBar: the index of navigation bar to be toggled
 **/
window.toggleNavigationBar = function ( indexNavigationBar, event ) {
    var NavToggle = document.getElementById( 'NavToggle' + indexNavigationBar );
    var NavFrame = document.getElementById( 'NavFrame' + indexNavigationBar );
    var NavChild;

    if ( !NavFrame || !NavToggle ) {
        return false;
    }

    /* if shown now */
    if ( NavToggle.firstChild.data === NavigationBarHide ) {
        for ( NavChild = NavFrame.firstChild; NavChild != null; NavChild = NavChild.nextSibling ) {
            if ( $( NavChild ).hasClass( 'NavContent' ) || $( NavChild ).hasClass( 'NavPic' ) ) {
                NavChild.style.display = 'none';
            }
        }
    NavToggle.firstChild.data = NavigationBarShow;

    /* if hidden now */
    } else if ( NavToggle.firstChild.data === NavigationBarShow ) {
        for ( NavChild = NavFrame.firstChild; NavChild != null; NavChild = NavChild.nextSibling ) {
            if ( $( NavChild ).hasClass( 'NavContent' ) || $( NavChild ).hasClass( 'NavPic' ) ) {
                NavChild.style.display = 'block';
            }
        }
        NavToggle.firstChild.data = NavigationBarHide;
    }

    event.preventDefault();
};

/* adds show/hide-button to navigation bars */
function createNavigationBarToggleButton( $content ) {
    var NavChild;
    /* iterate over all < div >-elements */
    var $divs = $content.find( 'div' );
    $divs.each( function ( i, NavFrame ) {
        /* if found a navigation bar */
        if ( $( NavFrame ).hasClass( 'NavFrame' ) ) {

            indexNavigationBar++;
            var NavToggle = document.createElement( 'a' );
            NavToggle.className = 'NavToggle';
            NavToggle.setAttribute( 'id', 'NavToggle' + indexNavigationBar );
            NavToggle.setAttribute( 'href', '#' );
            $( NavToggle ).on( 'click', $.proxy( window.toggleNavigationBar, window, indexNavigationBar ) );

            var isCollapsed = $( NavFrame ).hasClass( 'collapsed' );
            /**
             * Check if any children are already hidden.  This loop is here for backwards compatibility:
             * the old way of making NavFrames start out collapsed was to manually add style="display:none"
             * to all the NavPic/NavContent elements.  Since this was bad for accessibility (no way to make
             * the content visible without JavaScript support), the new recommended way is to add the class
             * "collapsed" to the NavFrame itself, just like with collapsible tables.
             */
            for ( NavChild = NavFrame.firstChild; NavChild != null && !isCollapsed; NavChild = NavChild.nextSibling ) {
                if ( $( NavChild ).hasClass( 'NavPic' ) || $( NavChild ).hasClass( 'NavContent' ) ) {
                    if ( NavChild.style.display === 'none' ) {
                        isCollapsed = true;
                    }
                }
            }
            if ( isCollapsed ) {
                for ( NavChild = NavFrame.firstChild; NavChild != null; NavChild = NavChild.nextSibling ) {
                    if ( $( NavChild ).hasClass( 'NavPic' ) || $( NavChild ).hasClass( 'NavContent' ) ) {
                        NavChild.style.display = 'none';
                    }
                }
            }
            var NavToggleText = document.createTextNode( isCollapsed ? NavigationBarShow : NavigationBarHide );
            NavToggle.appendChild( NavToggleText );

            /* Find the NavHead and attach the toggle link (Must be this complicated because Moz's firstChild handling is borked) */
            for( var j = 0; j < NavFrame.childNodes.length; j++ ) {
                if ( $( NavFrame.childNodes[j] ).hasClass( 'NavHead' ) ) {
                    NavToggle.style.color = NavFrame.childNodes[j].style.color;
                    NavFrame.childNodes[j].appendChild( NavToggle );
                }
            }
            NavFrame.setAttribute( 'id', 'NavFrame' + indexNavigationBar );
        }
    } );
}

mw.hook( 'wikipage.content' ).add( createNavigationBarToggleButton );

/*END OF NAVIGATION BARS*/

/** Collapsible tables *********************************************************
 *
 *  Description: Allows tables to be collapsed, showing only the header. See
 *               [[Wikipedia:NavFrame]].
 *  Maintainers: [[User:R. Koot]]
 */
 
var autoCollapse = 2;
var collapseCaption = "മറയ്ക്കുക";
var expandCaption = "പ്രദർശിപ്പിക്കുക";
 
function collapseTable( tableIndex )
{
	var Button = document.getElementById( "collapseButton" + tableIndex );
	var Table = document.getElementById( "collapsibleTable" + tableIndex );
 
	if ( !Table || !Button ) {
		return false;
	}
 
	var Rows = Table.rows;
 
	if ( Button.firstChild.data == collapseCaption ) {
		for ( var i = 1; i < Rows.length; i++ ) {
			Rows[i].style.display = "none";
		}
		Button.firstChild.data = expandCaption;
	} else {
		for ( var i = 1; i < Rows.length; i++ ) {
			Rows[i].style.display = Rows[0].style.display;
		}
		Button.firstChild.data = collapseCaption;
	}
}
 
function createCollapseButtons()
{
	var tableIndex = 0;
	var NavigationBoxes = new Object();
	var Tables = document.getElementsByTagName( "table" );
 
	for ( var i = 0; i < Tables.length; i++ ) {
		if ( $(Tables[i]).hasClass( "collapsible" ) ) {
 
			/* only add button and increment count if there is a header row to work with */
			var HeaderRow = Tables[i].getElementsByTagName( "tr" )[0];
			if (!HeaderRow) continue;
			var Header = HeaderRow.getElementsByTagName( "th" )[0];
			if (!Header) continue;
 
			NavigationBoxes[ tableIndex ] = Tables[i];
			Tables[i].setAttribute( "id", "collapsibleTable" + tableIndex );
 
			var Button     = document.createElement( "span" );
			var ButtonLink = document.createElement( "a" );
			var ButtonText = document.createTextNode( collapseCaption );
 
			Button.className = "collapseButton";  //Styles are declared in Common.css
 
			ButtonLink.style.color = Header.style.color;
			ButtonLink.setAttribute( "id", "collapseButton" + tableIndex );
			ButtonLink.setAttribute( "href", "javascript:collapseTable(" + tableIndex + ");" );
			ButtonLink.appendChild( ButtonText );
 
			Button.appendChild( document.createTextNode( "[" ) );
			Button.appendChild( ButtonLink );
			Button.appendChild( document.createTextNode( "]" ) );
 
			Header.insertBefore( Button, Header.childNodes[0] );
			tableIndex++;
		}
	}
 
	for ( var i = 0;  i < tableIndex; i++ ) {
		if ( $(NavigationBoxes[i]).hasClass( "collapsed" ) || ( tableIndex >= autoCollapse && $(NavigationBoxes[i]).hasClass( "autocollapse" ) ) ) {
			collapseTable( i );
		}
		else if ( $(NavigationBoxes[i]).hasClass( "innercollapse" ) ) {
			var element = NavigationBoxes[i];
			while (element = element.parentNode) {
				if ( $(element).hasClass( "outercollapse" ) ) {
					collapseTable ( i );
					break;
				}
			}
		}
	}
}
 
$( createCollapseButtons );
"https://schoolwiki.in/index.php?title=മീഡിയവിക്കി:Common.js&oldid=2624649" എന്ന താളിൽനിന്ന് ശേഖരിച്ചത്