MediaWiki:Common.js

From Documentation

Note: After saving, you may have to bypass your browser's cache to see the changes.

  • Firefox / Safari: Hold Shift while clicking Reload, or press either Ctrl-F5 or Ctrl-R (⌘-R on a Mac)
  • Google Chrome: Press Ctrl-Shift-R (⌘-Shift-R on a Mac)
  • Internet Explorer / Edge: Hold Ctrl while clicking Refresh, or press Ctrl-F5
  • Opera: Go to Menu → Settings (Opera → Preferences on a Mac) and then to Privacy & security → Clear browsing data → Cached images and files.
/* Any JavaScript here will be loaded for all users on every page load. */

if (typeof mwCustomEditButtons != 'undefined' && mwCustomEditButtons) {
 
   mwCustomEditButtons[mwCustomEditButtons.length] = {
     "imageFile": "/_w/images/7/79/Button_reflink.png",
     "speedTip": "Reference",
     "taken": "<ref> ",
     "tagClose": " </ref>",
     "sampleText": ""}
  }

function getComponentName(){
    return $('.potix-breadcrumb:last').text().toLowerCase();
}

function getSectionHeader(demoBox){
    var sibling = demoBox.previousElementSibling;

}

/**
 * Creates and embeds a PollDaddy poll inside an iframe
 * 
 * details:
 * This function solves the document.write() error that occurs when loading PollDaddy polls
 * asynchronously. It creates an iframe to provide a fresh document context, allowing the
 * PollDaddy script to execute properly after the page has loaded.
 * 
 * Usage:
 * - Requires a div with class="polldaddy" and data-url attribute containing the poll script URL
 * - Example: <div class="polldaddy" data-url="https://secure.polldaddy.com/p/12345.js">
 */
function createPoll() {
    // Find the polldaddy div
    const pollDadyDiv = document.querySelector('.polldaddy');

    if (pollDadyDiv) {
        // Get the URL from data-url attribute
        const scriptUrl = pollDadyDiv.getAttribute('data-url');
        
        // Create a new iframe
        const iframe = document.createElement('iframe');
        iframe.style.border = 'none';
        iframe.style.width = '100%';
        iframe.style.height = '450px';
        
        // Add iframe to the div
        pollDadyDiv.appendChild(iframe);
        
        // Get the iframe's document and write the script into it
        const iframeDoc = iframe.contentDocument || iframe.contentWindow.document;
        iframeDoc.open();
        iframeDoc.write(
            '<html>' +
                '<body>' +
                    '<script type="text/javascript" charset="utf-8" src="' + scriptUrl + '"><\/script>' +
                '</body>' +
            '</html>'
        );
        iframeDoc.close();
    }
}
createPoll();


/*
setTimeout(function(){
    $(function () {
		if (ga) {
			function handleWikiClicks(event) {
				ga('send', 'event', {
					eventCategory: 'Outbound Link',
					eventAction: 'click',
					eventLabel: event.target.href
				});
			}
			$('.galink').each(function (index,each) {
				$(each).find('a').click(function (event) {
					handleWikiClicks(event)
				});
			});
		}
	}());
},2000);
*/

window.GA_MEASUREMENT_ID = 'G-57B6X16TY1';
window.GA_POLICY_URL = 'https://www.zkoss.org/privacy';
window.GA_DEBUGGING = false;
window.GA_DARK_THEME = false; // light for zkoss, dark for keikai
window.GA_TARGET_DEV_HOST = 'localhost:4000'; //website consuming the load-ga script
window.PT_DEV_HOST = 'http://localhost:8080'; //local url of zkoss website
window.PT_PROD_HOST = 'https://www.zkoss.org' //prod url of zkoss website

const loadGa4Script = document.createElement('script');
loadGa4Script.src = 'https://www.zkoss.org/resource/js/page/load-ga4.js';
loadGa4Script.async = true;
document.head.appendChild(loadGa4Script);