home *** CD-ROM | disk | FTP | other *** search
/ HTML Examples / WP.iso / wordpress2 / wp-includes / js / tinymce / plugins / tabfocus / plugin.js next >
Encoding:
JavaScript  |  2017-05-07  |  8.1 KB  |  349 lines

  1. (function () {
  2.  
  3. var defs = {}; // id -> {dependencies, definition, instance (possibly undefined)}
  4.  
  5. // Used when there is no 'main' module.
  6. // The name is probably (hopefully) unique so minification removes for releases.
  7. var register_3795 = function (id) {
  8.   var module = dem(id);
  9.   var fragments = id.split('.');
  10.   var target = Function('return this;')();
  11.   for (var i = 0; i < fragments.length - 1; ++i) {
  12.     if (target[fragments[i]] === undefined)
  13.       target[fragments[i]] = {};
  14.     target = target[fragments[i]];
  15.   }
  16.   target[fragments[fragments.length - 1]] = module;
  17. };
  18.  
  19. var instantiate = function (id) {
  20.   var actual = defs[id];
  21.   var dependencies = actual.deps;
  22.   var definition = actual.defn;
  23.   var len = dependencies.length;
  24.   var instances = new Array(len);
  25.   for (var i = 0; i < len; ++i)
  26.     instances[i] = dem(dependencies[i]);
  27.   var defResult = definition.apply(null, instances);
  28.   if (defResult === undefined)
  29.      throw 'module [' + id + '] returned undefined';
  30.   actual.instance = defResult;
  31. };
  32.  
  33. var def = function (id, dependencies, definition) {
  34.   if (typeof id !== 'string')
  35.     throw 'module id must be a string';
  36.   else if (dependencies === undefined)
  37.     throw 'no dependencies for ' + id;
  38.   else if (definition === undefined)
  39.     throw 'no definition function for ' + id;
  40.   defs[id] = {
  41.     deps: dependencies,
  42.     defn: definition,
  43.     instance: undefined
  44.   };
  45. };
  46.  
  47. var dem = function (id) {
  48.   var actual = defs[id];
  49.   if (actual === undefined)
  50.     throw 'module [' + id + '] was undefined';
  51.   else if (actual.instance === undefined)
  52.     instantiate(id);
  53.   return actual.instance;
  54. };
  55.  
  56. var req = function (ids, callback) {
  57.   var len = ids.length;
  58.   var instances = new Array(len);
  59.   for (var i = 0; i < len; ++i)
  60.     instances.push(dem(ids[i]));
  61.   callback.apply(null, callback);
  62. };
  63.  
  64. var ephox = {};
  65.  
  66. ephox.bolt = {
  67.   module: {
  68.     api: {
  69.       define: def,
  70.       require: req,
  71.       demand: dem
  72.     }
  73.   }
  74. };
  75.  
  76. var define = def;
  77. var require = req;
  78. var demand = dem;
  79. // this helps with minificiation when using a lot of global references
  80. var defineGlobal = function (id, ref) {
  81.   define(id, [], function () { return ref; });
  82. };
  83. /*jsc
  84. ["tinymce.plugins.tabfocus.Plugin","tinymce.core.PluginManager","tinymce.core.dom.DOMUtils","tinymce.core.util.Tools","tinymce.core.EditorManager","tinymce.core.util.Delay","tinymce.core.Env","global!tinymce.util.Tools.resolve"]
  85. jsc*/
  86. defineGlobal("global!tinymce.util.Tools.resolve", tinymce.util.Tools.resolve);
  87. /**
  88.  * ResolveGlobal.js
  89.  *
  90.  * Released under LGPL License.
  91.  * Copyright (c) 1999-2017 Ephox Corp. All rights reserved
  92.  *
  93.  * License: http://www.tinymce.com/license
  94.  * Contributing: http://www.tinymce.com/contributing
  95.  */
  96.  
  97. define(
  98.   'tinymce.core.PluginManager',
  99.   [
  100.     'global!tinymce.util.Tools.resolve'
  101.   ],
  102.   function (resolve) {
  103.     return resolve('tinymce.PluginManager');
  104.   }
  105. );
  106.  
  107. /**
  108.  * ResolveGlobal.js
  109.  *
  110.  * Released under LGPL License.
  111.  * Copyright (c) 1999-2017 Ephox Corp. All rights reserved
  112.  *
  113.  * License: http://www.tinymce.com/license
  114.  * Contributing: http://www.tinymce.com/contributing
  115.  */
  116.  
  117. define(
  118.   'tinymce.core.dom.DOMUtils',
  119.   [
  120.     'global!tinymce.util.Tools.resolve'
  121.   ],
  122.   function (resolve) {
  123.     return resolve('tinymce.dom.DOMUtils');
  124.   }
  125. );
  126.  
  127. /**
  128.  * ResolveGlobal.js
  129.  *
  130.  * Released under LGPL License.
  131.  * Copyright (c) 1999-2017 Ephox Corp. All rights reserved
  132.  *
  133.  * License: http://www.tinymce.com/license
  134.  * Contributing: http://www.tinymce.com/contributing
  135.  */
  136.  
  137. define(
  138.   'tinymce.core.util.Tools',
  139.   [
  140.     'global!tinymce.util.Tools.resolve'
  141.   ],
  142.   function (resolve) {
  143.     return resolve('tinymce.util.Tools');
  144.   }
  145. );
  146.  
  147. /**
  148.  * ResolveGlobal.js
  149.  *
  150.  * Released under LGPL License.
  151.  * Copyright (c) 1999-2017 Ephox Corp. All rights reserved
  152.  *
  153.  * License: http://www.tinymce.com/license
  154.  * Contributing: http://www.tinymce.com/contributing
  155.  */
  156.  
  157. define(
  158.   'tinymce.core.EditorManager',
  159.   [
  160.     'global!tinymce.util.Tools.resolve'
  161.   ],
  162.   function (resolve) {
  163.     return resolve('tinymce.EditorManager');
  164.   }
  165. );
  166.  
  167. /**
  168.  * ResolveGlobal.js
  169.  *
  170.  * Released under LGPL License.
  171.  * Copyright (c) 1999-2017 Ephox Corp. All rights reserved
  172.  *
  173.  * License: http://www.tinymce.com/license
  174.  * Contributing: http://www.tinymce.com/contributing
  175.  */
  176.  
  177. define(
  178.   'tinymce.core.util.Delay',
  179.   [
  180.     'global!tinymce.util.Tools.resolve'
  181.   ],
  182.   function (resolve) {
  183.     return resolve('tinymce.util.Delay');
  184.   }
  185. );
  186.  
  187. /**
  188.  * ResolveGlobal.js
  189.  *
  190.  * Released under LGPL License.
  191.  * Copyright (c) 1999-2017 Ephox Corp. All rights reserved
  192.  *
  193.  * License: http://www.tinymce.com/license
  194.  * Contributing: http://www.tinymce.com/contributing
  195.  */
  196.  
  197. define(
  198.   'tinymce.core.Env',
  199.   [
  200.     'global!tinymce.util.Tools.resolve'
  201.   ],
  202.   function (resolve) {
  203.     return resolve('tinymce.Env');
  204.   }
  205. );
  206.  
  207. /**
  208.  * Plugin.js
  209.  *
  210.  * Released under LGPL License.
  211.  * Copyright (c) 1999-2017 Ephox Corp. All rights reserved
  212.  *
  213.  * License: http://www.tinymce.com/license
  214.  * Contributing: http://www.tinymce.com/contributing
  215.  */
  216.  
  217. /**
  218.  * This class contains all core logic for the code plugin.
  219.  *
  220.  * @class tinymce.tabfocus.Plugin
  221.  * @private
  222.  */
  223. define(
  224.   'tinymce.plugins.tabfocus.Plugin',
  225.   [
  226.     'tinymce.core.PluginManager',
  227.     'tinymce.core.dom.DOMUtils',
  228.     'tinymce.core.util.Tools',
  229.     'tinymce.core.EditorManager',
  230.     'tinymce.core.util.Delay',
  231.     'tinymce.core.Env'
  232.   ],
  233.   function (PluginManager, DOMUtils, Tools, EditorManager, Delay, Env) {
  234.     PluginManager.add('tabfocus', function (editor) {
  235.       var DOM = DOMUtils.DOM;
  236.  
  237.       function tabCancel(e) {
  238.         if (e.keyCode === 9 && !e.ctrlKey && !e.altKey && !e.metaKey) {
  239.           e.preventDefault();
  240.         }
  241.       }
  242.  
  243.       function tabHandler(e) {
  244.         var x, el, v, i;
  245.  
  246.         if (e.keyCode !== 9 || e.ctrlKey || e.altKey || e.metaKey || e.isDefaultPrevented()) {
  247.           return;
  248.         }
  249.  
  250.         function find(direction) {
  251.           el = DOM.select(':input:enabled,*[tabindex]:not(iframe)');
  252.  
  253.           function canSelectRecursive(e) {
  254.             return e.nodeName === "BODY" || (e.type != 'hidden' &&
  255.               e.style.display != "none" &&
  256.               e.style.visibility != "hidden" && canSelectRecursive(e.parentNode));
  257.           }
  258.  
  259.           function canSelect(el) {
  260.             return /INPUT|TEXTAREA|BUTTON/.test(el.tagName) && EditorManager.get(e.id) && el.tabIndex != -1 && canSelectRecursive(el);
  261.           }
  262.  
  263.           Tools.each(el, function (e, i) {
  264.             if (e.id == editor.id) {
  265.               x = i;
  266.               return false;
  267.             }
  268.           });
  269.           if (direction > 0) {
  270.             for (i = x + 1; i < el.length; i++) {
  271.               if (canSelect(el[i])) {
  272.                 return el[i];
  273.               }
  274.             }
  275.           } else {
  276.             for (i = x - 1; i >= 0; i--) {
  277.               if (canSelect(el[i])) {
  278.                 return el[i];
  279.               }
  280.             }
  281.           }
  282.  
  283.           return null;
  284.         }
  285.  
  286.         v = Tools.explode(editor.getParam('tab_focus', editor.getParam('tabfocus_elements', ':prev,:next')));
  287.  
  288.         if (v.length == 1) {
  289.           v[1] = v[0];
  290.           v[0] = ':prev';
  291.         }
  292.  
  293.         // Find element to focus
  294.         if (e.shiftKey) {
  295.           if (v[0] == ':prev') {
  296.             el = find(-1);
  297.           } else {
  298.             el = DOM.get(v[0]);
  299.           }
  300.         } else {
  301.           if (v[1] == ':next') {
  302.             el = find(1);
  303.           } else {
  304.             el = DOM.get(v[1]);
  305.           }
  306.         }
  307.  
  308.         if (el) {
  309.           var focusEditor = EditorManager.get(el.id || el.name);
  310.  
  311.           if (el.id && focusEditor) {
  312.             focusEditor.focus();
  313.           } else {
  314.             Delay.setTimeout(function () {
  315.               if (!Env.webkit) {
  316.                 window.focus();
  317.               }
  318.  
  319.               el.focus();
  320.             }, 10);
  321.           }
  322.  
  323.           e.preventDefault();
  324.         }
  325.       }
  326.  
  327.       editor.on('init', function () {
  328.         if (editor.inline) {
  329.           // Remove default tabIndex in inline mode
  330.           DOM.setAttrib(editor.getBody(), 'tabIndex', null);
  331.         }
  332.  
  333.         editor.on('keyup', tabCancel);
  334.  
  335.         if (Env.gecko) {
  336.           editor.on('keypress keydown', tabHandler);
  337.         } else {
  338.           editor.on('keydown', tabHandler);
  339.         }
  340.       });
  341.     });
  342.  
  343.  
  344.     return function () { };
  345.   }
  346. );
  347. dem('tinymce.plugins.tabfocus.Plugin')();
  348. })();
  349.