Difference between revisions of "MediaWiki:Common.js"

From Game Detectives Wiki
Jump to: navigation, search
(Fix for animation plays when link clicked)
Line 18: Line 18:
 
   jQueryCSS.setAttribute('rel','stylesheet' );
 
   jQueryCSS.setAttribute('rel','stylesheet' );
 
   jQueryCSS.setAttribute('href','//code.jquery.com/ui/1.12.1/themes/smoothness/jquery-ui.css');
 
   jQueryCSS.setAttribute('href','//code.jquery.com/ui/1.12.1/themes/smoothness/jquery-ui.css');
 
  
 
   // Wait for jQuery scripts to load
 
   // Wait for jQuery scripts to load
Line 26: Line 25:
 
       // Define jQuery prefix
 
       // Define jQuery prefix
 
       var $ = window.jQuery;
 
       var $ = window.jQuery;
 +
 +
      // Create variable clicked to capture data about which element is clicked
 +
      $(document).click(function(event) {
 +
        var clicked = $(event.target).text();
 +
      });
  
 
       // Iterate n to loop through each table row
 
       // Iterate n to loop through each table row
Line 38: Line 42:
  
 
           // Add the click event listener and popup function to the given row
 
           // Add the click event listener and popup function to the given row
           row.addEventListener('click', function (rowID) {
+
           row.addEventListener('click', function (rowID, clicked) {
             $(rowID).dialog({ // Define popup settings below
+
 
              modal: true,
+
            // Check if what has been clicked is a table element of some kind
              minHeight: 300,
+
            if(clicked.srcElement.toString().match('\\[object HTMLT') === null);
              minWidth: 600,
+
 
              width: 900,
+
            //Only proceed if not a link
              dialogClass: 'mattyPopup',
+
             else {
              position: { my: 'top center', at: 'top center', of: window },
+
              $(rowID).dialog({ // Define popup settings below
              show: { effect: 'clip', direction: 'vertical', duration: 600, easing: 'swing', delay: 500 },
+
                modal: true,
              hide: { effect: 'transfer', to: '#tableRow1' },
+
                minHeight: 300,
              buttons: [
+
                minWidth: 600,
                {
+
                width: 900,
                  text: 'Close',
+
                dialogClass: 'mattyPopup',
                  icon: 'ui-icon-closethick',
+
                position: {my: 'top center', at: 'top center', of: window},
                  click: function() {
+
                show: {effect: 'clip', direction: 'vertical', duration: 600, easing: 'swing', delay: 500},
                    $( this ).dialog( 'close' );
+
                hide: {effect: 'transfer', to: '#' + clicked.path[1].id},
 +
                buttons: [
 +
                  {
 +
                    text: 'Close',
 +
                    icon: 'ui-icon-closethick',
 +
                    click: function () {
 +
                      $(this).dialog('close');
 +
                    }
 
                   }
 
                   }
                 }
+
                 ]
               ]
+
               });
             });
+
             }
  
             // Bind rowID to function as it is passed in
+
             // Bind rowID to function
 
           }.bind(null, rowID));
 
           }.bind(null, rowID));
  

Revision as of 14:33, 16 August 2018

/* Scripts in this area will be loaded for all users on all pages */

/* Script for popup onclick for SMW matty tables */

(function () {

  // Count to break loop
  var cnt = 0;

  // Define jQuery scripts and settings
  var jQuery = document.createElement('script');
  jQuery.setAttribute('src','//code.jquery.com/jquery-1.12.4.js');

  var jQueryUI = document.createElement('script');
  jQueryUI.setAttribute('src','//code.jquery.com/ui/1.12.1/jquery-ui.js');

  var jQueryCSS = document.createElement('link');
  jQueryCSS.setAttribute('rel','stylesheet' );
  jQueryCSS.setAttribute('href','//code.jquery.com/ui/1.12.1/themes/smoothness/jquery-ui.css');

  // Wait for jQuery scripts to load
  jQuery.onload = function () {
    jQueryUI.onload = function () {

      // Define jQuery prefix
      var $ = window.jQuery;

      // Create variable clicked to capture data about which element is clicked
      $(document).click(function(event) {
        var clicked = $(event.target).text();
      });

      // Iterate n to loop through each table row
      for (var n = 1; n < 100; n++) {

        // Check that the table row exists
        if (document.getElementById('tableRow' + n)) {

          // Select the table row and set it's ID selector
          var row = document.getElementById('tableRow' + n);
          var rowID = '#dialog' + n;

          // Add the click event listener and popup function to the given row
          row.addEventListener('click', function (rowID, clicked) {

            // Check if what has been clicked is a table element of some kind
            if(clicked.srcElement.toString().match('\\[object HTMLT') === null);

            //Only proceed if not a link
            else {
              $(rowID).dialog({ // Define popup settings below
                modal: true,
                minHeight: 300,
                minWidth: 600,
                width: 900,
                dialogClass: 'mattyPopup',
                position: {my: 'top center', at: 'top center', of: window},
                show: {effect: 'clip', direction: 'vertical', duration: 600, easing: 'swing', delay: 500},
                hide: {effect: 'transfer', to: '#' + clicked.path[1].id},
                buttons: [
                  {
                    text: 'Close',
                    icon: 'ui-icon-closethick',
                    click: function () {
                      $(this).dialog('close');
                    }
                  }
                ]
              });
            }

            // Bind rowID to function
          }.bind(null, rowID));

          // Define a variable to be used for the title of the popup
          var nameCol = document.getElementById('tableCol1-' + n).innerText;

          // Define the popup's title and content and insert the popup's HTML into the given row's HTML
          row.innerHTML += '<div style="display:none" id="dialog' + n + '"' + ' title="' + nameCol + '"' + n + '">' + '\n' +
              '<p>Coming Soon ' + n + '</p>\n' +
              '</div>';
        }

        // Detect when a given row does not exist
        else {
          cnt++;
        }

        // If two rows are detected to not exist, assume the tables have ended and break the loop
        if (cnt > 0) {
          break;
        }
      }
    };
  };

  // Insert jQuery scripts into page's HTML
  document.getElementsByTagName('head')[0].appendChild(jQuery);
  document.getElementsByTagName('head')[0].appendChild(jQueryUI);
  document.getElementsByTagName('head')[0].appendChild(jQueryCSS);
})();