wp/wp-includes/js/tinymce/plugins/tabfocus/plugin.js
changeset 9 177826044cd9
parent 7 cf61fcea0001
equal deleted inserted replaced
8:c7c34916027a 9:177826044cd9
     1 (function () {
     1 (function () {
     2 var tabfocus = (function () {
     2 var tabfocus = (function (domGlobals) {
     3   'use strict';
     3     'use strict';
     4 
     4 
     5   var global = tinymce.util.Tools.resolve('tinymce.PluginManager');
     5     var global = tinymce.util.Tools.resolve('tinymce.PluginManager');
     6 
     6 
     7   var global$1 = tinymce.util.Tools.resolve('tinymce.dom.DOMUtils');
     7     var global$1 = tinymce.util.Tools.resolve('tinymce.dom.DOMUtils');
     8 
     8 
     9   var global$2 = tinymce.util.Tools.resolve('tinymce.EditorManager');
     9     var global$2 = tinymce.util.Tools.resolve('tinymce.EditorManager');
    10 
    10 
    11   var global$3 = tinymce.util.Tools.resolve('tinymce.Env');
    11     var global$3 = tinymce.util.Tools.resolve('tinymce.Env');
    12 
    12 
    13   var global$4 = tinymce.util.Tools.resolve('tinymce.util.Delay');
    13     var global$4 = tinymce.util.Tools.resolve('tinymce.util.Delay');
    14 
    14 
    15   var global$5 = tinymce.util.Tools.resolve('tinymce.util.Tools');
    15     var global$5 = tinymce.util.Tools.resolve('tinymce.util.Tools');
    16 
    16 
    17   var global$6 = tinymce.util.Tools.resolve('tinymce.util.VK');
    17     var global$6 = tinymce.util.Tools.resolve('tinymce.util.VK');
    18 
    18 
    19   var getTabFocusElements = function (editor) {
    19     var getTabFocusElements = function (editor) {
    20     return editor.getParam('tabfocus_elements', ':prev,:next');
    20       return editor.getParam('tabfocus_elements', ':prev,:next');
    21   };
    21     };
    22   var getTabFocus = function (editor) {
    22     var getTabFocus = function (editor) {
    23     return editor.getParam('tab_focus', getTabFocusElements(editor));
    23       return editor.getParam('tab_focus', getTabFocusElements(editor));
    24   };
    24     };
    25   var $_8rita4kwjjgwed4m = { getTabFocus: getTabFocus };
    25     var Settings = { getTabFocus: getTabFocus };
    26 
    26 
    27   var DOM = global$1.DOM;
    27     var DOM = global$1.DOM;
    28   var tabCancel = function (e) {
    28     var tabCancel = function (e) {
    29     if (e.keyCode === global$6.TAB && !e.ctrlKey && !e.altKey && !e.metaKey) {
    29       if (e.keyCode === global$6.TAB && !e.ctrlKey && !e.altKey && !e.metaKey) {
    30       e.preventDefault();
    30         e.preventDefault();
    31     }
       
    32   };
       
    33   var setup = function (editor) {
       
    34     function tabHandler(e) {
       
    35       var x, el, v, i;
       
    36       if (e.keyCode !== global$6.TAB || e.ctrlKey || e.altKey || e.metaKey || e.isDefaultPrevented()) {
       
    37         return;
       
    38       }
    31       }
    39       function find(direction) {
    32     };
    40         el = DOM.select(':input:enabled,*[tabindex]:not(iframe)');
    33     var setup = function (editor) {
    41         function canSelectRecursive(e) {
    34       function tabHandler(e) {
    42           return e.nodeName === 'BODY' || e.type !== 'hidden' && e.style.display !== 'none' && e.style.visibility !== 'hidden' && canSelectRecursive(e.parentNode);
    35         var x, el, v, i;
       
    36         if (e.keyCode !== global$6.TAB || e.ctrlKey || e.altKey || e.metaKey || e.isDefaultPrevented()) {
       
    37           return;
    43         }
    38         }
    44         function canSelect(el) {
    39         function find(direction) {
    45           return /INPUT|TEXTAREA|BUTTON/.test(el.tagName) && global$2.get(e.id) && el.tabIndex !== -1 && canSelectRecursive(el);
    40           el = DOM.select(':input:enabled,*[tabindex]:not(iframe)');
    46         }
    41           function canSelectRecursive(e) {
    47         global$5.each(el, function (e, i) {
    42             return e.nodeName === 'BODY' || e.type !== 'hidden' && e.style.display !== 'none' && e.style.visibility !== 'hidden' && canSelectRecursive(e.parentNode);
    48           if (e.id === editor.id) {
       
    49             x = i;
       
    50             return false;
       
    51           }
    43           }
    52         });
    44           function canSelect(el) {
    53         if (direction > 0) {
    45             return /INPUT|TEXTAREA|BUTTON/.test(el.tagName) && global$2.get(e.id) && el.tabIndex !== -1 && canSelectRecursive(el);
    54           for (i = x + 1; i < el.length; i++) {
    46           }
    55             if (canSelect(el[i])) {
    47           global$5.each(el, function (e, i) {
    56               return el[i];
    48             if (e.id === editor.id) {
       
    49               x = i;
       
    50               return false;
       
    51             }
       
    52           });
       
    53           if (direction > 0) {
       
    54             for (i = x + 1; i < el.length; i++) {
       
    55               if (canSelect(el[i])) {
       
    56                 return el[i];
       
    57               }
       
    58             }
       
    59           } else {
       
    60             for (i = x - 1; i >= 0; i--) {
       
    61               if (canSelect(el[i])) {
       
    62                 return el[i];
       
    63               }
    57             }
    64             }
    58           }
    65           }
       
    66           return null;
       
    67         }
       
    68         v = global$5.explode(Settings.getTabFocus(editor));
       
    69         if (v.length === 1) {
       
    70           v[1] = v[0];
       
    71           v[0] = ':prev';
       
    72         }
       
    73         if (e.shiftKey) {
       
    74           if (v[0] === ':prev') {
       
    75             el = find(-1);
       
    76           } else {
       
    77             el = DOM.get(v[0]);
       
    78           }
    59         } else {
    79         } else {
    60           for (i = x - 1; i >= 0; i--) {
    80           if (v[1] === ':next') {
    61             if (canSelect(el[i])) {
    81             el = find(1);
    62               return el[i];
    82           } else {
    63             }
    83             el = DOM.get(v[1]);
    64           }
    84           }
    65         }
    85         }
    66         return null;
    86         if (el) {
    67       }
    87           var focusEditor = global$2.get(el.id || el.name);
    68       v = global$5.explode($_8rita4kwjjgwed4m.getTabFocus(editor));
    88           if (el.id && focusEditor) {
    69       if (v.length === 1) {
    89             focusEditor.focus();
    70         v[1] = v[0];
    90           } else {
    71         v[0] = ':prev';
    91             global$4.setTimeout(function () {
    72       }
    92               if (!global$3.webkit) {
    73       if (e.shiftKey) {
    93                 domGlobals.window.focus();
    74         if (v[0] === ':prev') {
    94               }
    75           el = find(-1);
    95               el.focus();
    76         } else {
    96             }, 10);
    77           el = DOM.get(v[0]);
    97           }
    78         }
    98           e.preventDefault();
    79       } else {
       
    80         if (v[1] === ':next') {
       
    81           el = find(1);
       
    82         } else {
       
    83           el = DOM.get(v[1]);
       
    84         }
    99         }
    85       }
   100       }
    86       if (el) {
   101       editor.on('init', function () {
    87         var focusEditor = global$2.get(el.id || el.name);
   102         if (editor.inline) {
    88         if (el.id && focusEditor) {
   103           DOM.setAttrib(editor.getBody(), 'tabIndex', null);
    89           focusEditor.focus();
   104         }
       
   105         editor.on('keyup', tabCancel);
       
   106         if (global$3.gecko) {
       
   107           editor.on('keypress keydown', tabHandler);
    90         } else {
   108         } else {
    91           global$4.setTimeout(function () {
   109           editor.on('keydown', tabHandler);
    92             if (!global$3.webkit) {
       
    93               window.focus();
       
    94             }
       
    95             el.focus();
       
    96           }, 10);
       
    97         }
   110         }
    98         e.preventDefault();
   111       });
    99       }
   112     };
       
   113     var Keyboard = { setup: setup };
       
   114 
       
   115     global.add('tabfocus', function (editor) {
       
   116       Keyboard.setup(editor);
       
   117     });
       
   118     function Plugin () {
   100     }
   119     }
   101     editor.on('init', function () {
       
   102       if (editor.inline) {
       
   103         DOM.setAttrib(editor.getBody(), 'tabIndex', null);
       
   104       }
       
   105       editor.on('keyup', tabCancel);
       
   106       if (global$3.gecko) {
       
   107         editor.on('keypress keydown', tabHandler);
       
   108       } else {
       
   109         editor.on('keydown', tabHandler);
       
   110       }
       
   111     });
       
   112   };
       
   113   var $_6zogdykpjjgwed4h = { setup: setup };
       
   114 
   120 
   115   global.add('tabfocus', function (editor) {
   121     return Plugin;
   116     $_6zogdykpjjgwed4h.setup(editor);
       
   117   });
       
   118   function Plugin () {
       
   119   }
       
   120 
   122 
   121   return Plugin;
   123 }(window));
   122 
       
   123 }());
       
   124 })();
   124 })();