Source: jsxc.lib.tab.js

  1. /**
  2. * Provides communication between tabs.
  3. *
  4. * @namespace jsxc.tab
  5. */
  6. jsxc.tab = {
  7. CONST: {
  8. MASTER: 'master',
  9. SLAVE: 'slave'
  10. },
  11. exec: function(target, cmd, params) {
  12. params = Array.prototype.slice.call(arguments, 2);
  13. if (params.length === 1 && $.isArray(params[0])) {
  14. params = params[0];
  15. }
  16. if (target === jsxc.tab.CONST[jsxc.master ? 'MASTER' : 'SLAVE']) {
  17. jsxc.exec(cmd, params);
  18. if (jsxc.master) {
  19. return;
  20. }
  21. }
  22. jsxc.storage.setUserItem('_cmd', {
  23. target: target,
  24. cmd: cmd,
  25. params: params,
  26. rnd: Math.random() // force storage event
  27. });
  28. },
  29. /**
  30. * Execute command in master tab.
  31. *
  32. * @param {String} cmd Command
  33. * @param {String[]} params List of parameters
  34. */
  35. execMaster: function() {
  36. var args = Array.prototype.slice.call(arguments);
  37. args.unshift(jsxc.tab.CONST.MASTER);
  38. jsxc.tab.exec.apply(this, args);
  39. },
  40. /**
  41. * Execute command in all slave tabs.
  42. *
  43. * @param {String} cmd Command
  44. * @param {String[]} params List of parameters
  45. */
  46. execSlave: function() {
  47. var args = Array.prototype.slice.call(arguments);
  48. args.unshift(jsxc.tab.CONST.SLAVE);
  49. jsxc.tab.exec.apply(this, args);
  50. }
  51. };