Difference between revisions of "MediaWiki:Common.js"

From Bible Wiki, www.natnee.com
Jump to navigation Jump to search
 
(11 intermediate revisions by the same user not shown)
Line 1: Line 1:
/* Any JavaScript here will be loaded for all users on every page load. */
+
    var id, timeOut, timeOutShow, origin, mouseWhere='',
function dragElement(elmnt) {
+
        container = $("body"),
  var pos1 = 0, pos2 = 0, pos3 = 0, pos4 = 0;
+
        count=0;
  if ($('#'+elmnt[0].id + "header")) {
+
     // endvar
    /* if present, the header is where you move the DIV from:*/
 
    $('#'+elmnt[0].id + "header").on('mousedown', dragMouseDown);
 
  } else {
 
     /* otherwise, move the DIV from anywhere inside the DIV:*/
 
    elmnt.on('mousedown',dragMouseDown);
 
  }
 
  
  function dragMouseDown(e) {
+
    function dragElement(elmnt) {
    e = e || window.event;
+
      var pos1 = 0, pos2 = 0, pos3 = 0, pos4 = 0;
    e.preventDefault();
+
      if ($('#'+elmnt[0].id + "header")) {
    // get the mouse cursor position at startup:
+
        /* if present, the header is where you move the DIV from:*/
    pos3 = e.clientX;
+
        $('#'+elmnt[0].id + "header").on('mousedown', dragMouseDown);
    pos4 = e.clientY;
+
      } else {
    $(document).on('mouseup',closeDragElement);
+
        /* otherwise, move the DIV from anywhere inside the DIV:*/
    // call a function whenever the cursor moves:
+
        elmnt.on('mousedown',dragMouseDown);
    $(document).on('mousemove',elementDrag);
+
      }
  }
 
  
  function elementDrag(e) {
+
      function dragMouseDown(e) {
    e = e || window.event;
+
        e = e || window.event;
    e.preventDefault();
+
        e.preventDefault();
    // calculate the new cursor position:
+
        // get the mouse cursor position at startup:
    pos1 = pos3 - e.clientX;
+
        pos3 = e.clientX;
    pos2 = pos4 - e.clientY;
+
        pos4 = e.clientY;
    pos3 = e.clientX;
+
        $(document).on('mouseup',closeDragElement);
    pos4 = e.clientY;
+
        // call a function whenever the cursor moves:
    // set the element's new position:
+
        $(document).on('mousemove',elementDrag);
    elmnt.css('top', (elmnt[0].offsetTop - pos2) + "px");
+
      }
    elmnt.css('left', (elmnt[0].offsetLeft - pos1) + "px");
 
  }
 
  
  function closeDragElement() {
+
      function elementDrag(e) {
    /* stop moving when mouse button is released:*/
+
        e = e || window.event;
    $(document).off('mouseup',closeDragElement);
+
        e.preventDefault();
    $(document).off('mousemove',elementDrag);
+
        // calculate the new cursor position:
  }
+
        pos1 = pos3 - e.clientX;
}
+
        pos2 = pos4 - e.clientY;
var timer, timer_out, origin, what, mouseWhere='';
+
        pos3 = e.clientX;
var dte, whereami;
+
        pos4 = e.clientY;
var container = $("body");
+
        // set the element's new position:
var count=0;
+
        elmnt.css('top', (elmnt[0].offsetTop - pos2) + "px");
 
+
        elmnt.css('left', (elmnt[0].offsetLeft - pos1) + "px");
$('.verse').each(function(){  });
+
      }
  
$('.verse').on('click', function(){
+
       function closeDragElement() {
  elm = $(this);
+
         /* stop moving when mouse button is released:*/
  verse = elm.text();
+
         $(document).off('mouseup',closeDragElement);
  id = elm.text().replace(' ', '').replace(':','').replace('-','');
+
         $(document).off('mousemove',elementDrag);
 
 
  if ($('#' + id).length === 0) {
 
    $.ajax({
 
      url: '/chronology/index.php?route=common/home/sa',
 
      type: 'get',
 
      data: '&verse=' + verse,
 
       dataType: 'html',
 
      beforeSend: function() { },
 
      success: function(json) {
 
         var dv = '<div id="' + id +'" style="visibility:hidden; box-shadow: 0 0 10px rgba(0,0,0,0.5); background-color:#eee; width:250px;height:250px;position:fixed; top:50%; left:50%; transform:translate(-50%,-50%);"><div id="'+ id +'header" style="background-color:#aaa;cursor: move;padding:5px 10px">' + verse + '<div class="close" style="display:inline-block;cursor:pointer; float:right; font-weight:900;font-size:18px;line-height:15px" data-id="'+ id +'">&times;</div></div><div style="padding:20px;height:160px; overflow-y:scroll; ">' + json +  '</div></div>'
 
        elm.after(dv);
 
         $('#' + id).css('visibility', 'visible');
 
        //$('#one #header').mousedown(handle_mousedown);
 
        dragElement($("#" + id));
 
         $('.close').on('click', function() { close(this); } );
 
 
 
      },
 
      error: function(xhr, ajaxOptions, thrownError) {
 
          alert(thrownError + "\r\n" + xhr.statusText + "\r\n" + xhr.responseText);
 
 
       }
 
       }
 +
    }
 +
    function clickClose(i) {  $('#close-'+ i).trigger('click');  }
 +
    function getID(el) {  console.log(el.text().replace(/\u00a0/g,'').replace(/ /g, '').replace(':','').replace('-','')); return el.text().replace(/\u00a0/g,'').replace(/ /g, '').replace(':','').replace('-','');  }
 +
    function showHover(hover, lnk) {
 +
      console.log(container.innerWidth());
 +
      cW = container.innerWidth();
 +
      var posleft = lnk.offset().left + lnk.width();
 +
      if (posleft <= 50) posleft = 10;
 +
      else if (posleft >= (cW -250)) posleft = cW - 500;
 +
      else posleft = posleft - 160;
 +
      var postop = lnk.offset().top;
 +
      postop  = postop <= 200 ? 10 : postop - 200;
  
     });
+
      hover.css({"z-index":count,
  } else {
+
                    "left":posleft+"px",
    $('#' + id).css('visibility', 'visible');
+
                    "top":postop+"px",
  }
+
              "visibility":"visible"})
});
+
          .addClass("mwe-popups-fade-in-up");
 +
     }
 +
    function processHover (lnk, id) {
 +
      // delay showing the verse hover box
 +
      timeOutShow = setTimeout(function(){
 +
        if (mouseWhere == 'hover-'+id) {
 +
          timeOutShow = null;
 +
          if (lnk.data('verse')) verse = lnk.data('verse');
 +
          else verse = lnk.text().replace(/\u00a0/g,' ');
 +
          //id = getID(lnk);
 +
          var hover = $('#' + id);
 +
          count++;
 +
          if (hover.length === 0) {
 +
            $.ajax({
 +
              url: '/chronology/index.php?route=common/home/sa',
 +
              type: 'get',
 +
              data: '&verse=' + verse,
 +
              dataType: 'html',
 +
              beforeSend: function() {
 +
                // set the verse hover box:  content is loading
 +
                lnk.after('<div id="' + id +'" class="hover"><div id="'+ id +'header" class="hvr-header">' + verse + '<div id="close-' + id + '" class="close">&times;</div></div><div class="hvr-content"><img src="/natnee/images/6.gif" /></div></div>');
 +
              },
 +
              success: function(json) {
 +
                // verse hover box:  content is the verse
 +
                $('#' + id + ' .hvr-content').html(json);
 +
                // important to redefine the hover; it becomes null if it isn't defined
 +
                hover = $('#' + id);                   
 +
                origin = 'top';
 +
                showHover(hover, lnk);
 +
                // make it draggable
 +
                dragElement(hover);
 +
                // when [x] of verse hover is clicked
 +
                $('#close-'+id).on('click', function() {
 +
                    if (origin == 'top') hover.removeClass("mwe-popups-fade-in-up").addClass("mwe-popups-fade-out-down");
 +
                    else                hover.removeClass("mwe-popups-fade-in-down").hover.addClass("mwe-popups-fade-out-up");
  
$(document).on( 'mouseover keyup', '.verse', function ( event ) {
+
                    hover.on("animationend webkitAnimationEnd oAnimationEnd MSAnimationEnd", function(e){ hover.off(e);
  whereami = $(this).attr("data-ttl");
+
                      if (hover.attr('class').indexOf('mwe-popups-fade-out') >= 0 ) {
  mouseWhere = 'over';
+
                        hover.removeClass("mwe-popups-fade-out-down").css({'visibility':'hidden','top':'0','left':'0', 'z-index':'0'});
 +
                      }
 +
                    });//end hover animation
 +
                });//end close on click
  
  dte = Date.now();
 
  var lnk = $(this);
 
  
  verse = lnk.text();
+
                return false;
  id = lnk.text().replace(' ', '').replace(':','').replace('-','');
 
  var hover = $('#' + id);//$('#hover-'+title);
 
  
  if (mouseWhere == 'over') {
+
              }, error: function(xhr, ajaxOptions, thrownError) {
    count++;
+
                alert(thrownError + "\r\n" + xhr.statusText + "\r\n" + xhr.responseText);
    if (hover.length === 0) {
+
              }
      $.ajax({
+
            });
        url: '/chronology/index.php?route=common/home/sa',
+
           } else if (hover.css('visibility') == 'hidden') { showHover(hover, lnk); }
        type: 'get',
+
        }
        data: '&verse=' + verse,
 
        dataType: 'html',
 
        success: function(json) {
 
          lnk.after('<div id="' + id +'" class="hover"><div id="'+ id +'header" class="header">' + verse + '<div id="close-' + id + '" class="close">&times;</div></div><div class="content">' + json +  '</div></div>');
 
           hover = $('#' + id);
 
  
          hover.css('--hover-border-color',lnk.offsetParent().css("color"));
+
      }, 500);
          origin = 'top';
 
          hover.css({"z-index":count,"left":(lnk.offset().left-50)+"px","top":(lnk.offset().top-200)+"px","visibility":"visible"}).addClass("mwe-popups-fade-in-up");
 
          dragElement(hover);
 
          $('#close-'+id).on('click', function() {
 
            if (origin == 'top') hover.removeClass("mwe-popups-fade-in-up").addClass("mwe-popups-fade-out-down");
 
            else hover.removeClass("mwe-popups-fade-in-down").hover.addClass("mwe-popups-fade-out-up");
 
  
            hover.on("animationend webkitAnimationEnd oAnimationEnd MSAnimationEnd", function(e){ hover.off(e);
+
    }
            if (hover.attr('class').indexOf('mwe-popups-fade-out') >= 0 ) {
 
              hover.removeClass("mwe-popups-fade-out-down").css({'visibility':'hidden','top':'0','left':'0', 'z-index':'0'});
 
            } });
 
          } );
 
 
 
          dte = Date.now();
 
  
          return false;
 
  
        }, error: function(xhr, ajaxOptions, thrownError) {
+
    $(document).on( 'mouseover keyup', '.verse', function () {
          alert(thrownError + "\r\n" + xhr.statusText + "\r\n" + xhr.responseText);
+
                  id = getID($(this));
        }
+
                  mouseWhere = 'hover-' + id; 
      });
+
                  processHover($(this), id);
    } else if (hover.css('visibility') == 'hidden') {
+
                })
      hover.css({"z-index":count,"left":(lnk.offset().left-50)+"px","top":(lnk.offset().top-200)+"px","visibility":"visible"}).addClass("mwe-popups-fade-in-down");
+
              .on( 'mouseout blur', '.verse', function ()
    }
+
                  id = getID($(this)); 
  }
+
                  mouseWhere = 'out-' + id; 
 +
                  timeOut = setTimeout( clickClose, 800, id);
 +
                })
 +
              .on( 'mouseover', '.hover', function() { 
 +
                  clearTimeout( timeOut );
 +
                })
 +
              .on( 'mouseout', '.hover', function()
 +
                  timeOut = setTimeout( clickClose, 800, id );
 +
              });
 +
    // end document
  
});
+
    $('.verse').on('click', function(){
 +
                  if (timeOutShow === null) {
 +
                    id = getID($(this)); 
 +
                    mouseWhere = 'click-' + id; 
 +
                    processHover($(this), id);
 +
                  }
 +
                });
 +
    // end .verse

Latest revision as of 09:52, 5 May 2021

    var id, timeOut, timeOutShow, origin, mouseWhere='',
        container = $("body"),
        count=0;
    // endvar

    function dragElement(elmnt) {
      var pos1 = 0, pos2 = 0, pos3 = 0, pos4 = 0;
      if ($('#'+elmnt[0].id + "header")) {
        /* if present, the header is where you move the DIV from:*/
        $('#'+elmnt[0].id + "header").on('mousedown', dragMouseDown);
      } else {
        /* otherwise, move the DIV from anywhere inside the DIV:*/
        elmnt.on('mousedown',dragMouseDown);
      }

      function dragMouseDown(e) {
        e = e || window.event;
        e.preventDefault();
        // get the mouse cursor position at startup:
        pos3 = e.clientX;
        pos4 = e.clientY;
        $(document).on('mouseup',closeDragElement);
        // call a function whenever the cursor moves:
        $(document).on('mousemove',elementDrag);
      }

      function elementDrag(e) {
        e = e || window.event;
        e.preventDefault();
        // calculate the new cursor position:
        pos1 = pos3 - e.clientX;
        pos2 = pos4 - e.clientY;
        pos3 = e.clientX;
        pos4 = e.clientY;
        // set the element's new position:
        elmnt.css('top', (elmnt[0].offsetTop - pos2) + "px");
        elmnt.css('left', (elmnt[0].offsetLeft - pos1) + "px");
      }

      function closeDragElement() {
        /* stop moving when mouse button is released:*/
        $(document).off('mouseup',closeDragElement);
        $(document).off('mousemove',elementDrag);
      }
    }
    function clickClose(i) {  $('#close-'+ i).trigger('click');  }
    function getID(el) {  console.log(el.text().replace(/\u00a0/g,'').replace(/ /g, '').replace(':','').replace('-','')); return el.text().replace(/\u00a0/g,'').replace(/ /g, '').replace(':','').replace('-','');  }
    function showHover(hover, lnk) {
      console.log(container.innerWidth());
      cW = container.innerWidth();
      var posleft = lnk.offset().left + lnk.width();
      if (posleft <= 50) posleft = 10;
      else if (posleft >= (cW -250)) posleft = cW - 500;
      else posleft = posleft - 160;
      var postop = lnk.offset().top;
      postop  = postop <= 200 ? 10 : postop - 200;

      hover.css({"z-index":count,
                    "left":posleft+"px",
                     "top":postop+"px",
              "visibility":"visible"})
           .addClass("mwe-popups-fade-in-up");
    }
    function processHover (lnk, id) {
      // delay showing the verse hover box
      timeOutShow = setTimeout(function(){
        if (mouseWhere == 'hover-'+id) {
          timeOutShow = null;
          if (lnk.data('verse')) verse = lnk.data('verse');
          else verse = lnk.text().replace(/\u00a0/g,' ');
          //id = getID(lnk);
          var hover = $('#' + id);
          count++;
          if (hover.length === 0) {
            $.ajax({ 
              url: '/chronology/index.php?route=common/home/sa',
              type: 'get',
              data: '&verse=' + verse,
              dataType: 'html',
              beforeSend: function() {
                // set the verse hover box:  content is loading
                lnk.after('<div id="' + id +'" class="hover"><div id="'+ id +'header" class="hvr-header">' + verse + '<div id="close-' + id + '" class="close">&times;</div></div><div class="hvr-content"><img src="/natnee/images/6.gif" /></div></div>');
              },
              success: function(json) {
                // verse hover box:  content is the verse
                $('#' + id + ' .hvr-content').html(json);
                // important to redefine the hover; it becomes null if it isn't defined
                hover = $('#' + id);                    
                origin = 'top';
                showHover(hover, lnk);
                // make it draggable
                dragElement(hover);
                // when [x] of verse hover is clicked
                $('#close-'+id).on('click', function() {
                    if (origin == 'top') hover.removeClass("mwe-popups-fade-in-up").addClass("mwe-popups-fade-out-down");
                    else                 hover.removeClass("mwe-popups-fade-in-down").hover.addClass("mwe-popups-fade-out-up");

                    hover.on("animationend webkitAnimationEnd oAnimationEnd MSAnimationEnd", function(e){ hover.off(e); 
                      if (hover.attr('class').indexOf('mwe-popups-fade-out') >= 0 ) {
                        hover.removeClass("mwe-popups-fade-out-down").css({'visibility':'hidden','top':'0','left':'0', 'z-index':'0'});
                      }
                    });//end hover animation
                });//end close on click


                return false;

              }, error: function(xhr, ajaxOptions, thrownError) {
                alert(thrownError + "\r\n" + xhr.statusText + "\r\n" + xhr.responseText);
              }
            });
          } else if (hover.css('visibility') == 'hidden') { showHover(hover, lnk); }
        }

      }, 500);

    }


    $(document).on( 'mouseover keyup', '.verse', function () {  
                  id = getID($(this));  
                  mouseWhere = 'hover-' + id;  
                  processHover($(this), id);  
                })
               .on( 'mouseout blur', '.verse', function () {  
                  id = getID($(this));  
                  mouseWhere = 'out-' + id;  
                  timeOut = setTimeout( clickClose, 800, id); 
                })
               .on( 'mouseover', '.hover', function() {  
                  clearTimeout( timeOut );
                })
               .on( 'mouseout', '.hover', function() {  
                  timeOut = setTimeout( clickClose, 800, id );  
               });
    // end document

    $('.verse').on('click', function(){
                  if (timeOutShow === null) { 
                    id = getID($(this));  
                    mouseWhere = 'click-' + id;  
                    processHover($(this), id); 
                  }
                });
    // end .verse