[ Index ]

PHP Cross Reference of vtigercrm-6.1.0

title

Body

[close]

/libraries/jquery/ -> jquery_windowmsg.js (source)

   1  /*
   2   * WindowMsg jquery plugin
   3   *
   4   * Copyright (c) 2008 Peter Hulst (sfpeter.com / hollice.com)
   5   * Dual licensed under the MIT (MIT-LICENSE.txt)
   6   * and GPL (GPL-LICENSE.txt) licenses.
   7   *
   8   * Version 1.0
   9   */
  10  (function($) {
  11  
  12  // this array keeps the list of event handlers and names
  13  $.windowMsgHandlers = [];
  14  
  15  // this init method must be called in the parent window upon page load
  16  $.initWindowMsg = function() {
  17    $('body').append($('<form name="windowComm"></form>')
  18        .append($('<input type="hidden" name="windowCommEvent">'))
  19        .append($('<input type="hidden" name="windowCommData">'))
  20        .append($('<input id="myinput" type="button" name="windowCommButton" value="" style="display:none">')));    
  21   
  22    // register event listener
  23    $('#myinput').click(function() { 
  24      eventType = $('[name=windowCommEvent]').val();
  25      data = $('[name=windowCommData]').val();
  26      //console.log('received event/data: ' + eventType + " / " + data);
  27    
  28      for (var i=0; i<$.windowMsgHandlers.length; i++) {
  29        h = $.windowMsgHandlers[i];
  30        if (h.event == eventType) {
  31          h.callback.call(null, data); // call the callback method
  32          break;
  33        }
  34      }
  35    });
  36  };
  37  
  38  // triggers an event in the parent window. Returns true if the 
  39  // message was succesfully sent, otherwise false. 
  40  $.triggerParentEvent = function(event, msg) {
  41    $.triggerWindowEvent(window.opener, event, msg);
  42  };
  43  
  44  // triggers an event in a window that was opened by the current window
  45  $.triggerWindowEvent = function(otherWindow, event, msg) {
  46    if (typeof otherWindow == "object") {
  47      form = otherWindow.document.forms["windowComm"];
  48      if (form) {
  49        form.windowCommEvent.value = event;
  50        form.windowCommData.value = msg;
  51        form.windowCommButton.click();
  52        return true;
  53      }
  54    } 
  55    return false;
  56  }
  57  
  58  // adds a handler for a message from child window    
  59  $.windowMsg = function(event, callback) {
  60    $.windowMsgHandlers.push({event: event, callback: callback});
  61  } 
  62      
  63  })(jQuery);


Generated: Fri Nov 28 20:08:37 2014 Cross-referenced by PHPXref 0.7.1