diff --git a/source/Ox.UI/js/Core/Keyboard.js b/source/Ox.UI/js/Core/Keyboard.js deleted file mode 100644 index 3035b590..00000000 --- a/source/Ox.UI/js/Core/Keyboard.js +++ /dev/null @@ -1,124 +0,0 @@ -'use strict'; - -/*@ -Ox.Keyboard Basic keyboard controller -@*/ - -Ox.Keyboard = (function() { - - var buffer = '', bound = [], resetTimeout, triggerTimeout; - - Ox.UI.ready(function() { - Ox.$document.keydown(keydown); - }); - - function keydown(event) { - - var focused = Ox.Focus.focused(), - $focused = focused === null ? null : Ox.UI.elements[focused], - key, - keyName = Ox.KEYS[event.keyCode] || '', - keyNames = keyName ? [keyName] : [], - keyBasename = keyName.split('.')[0], - ret = true; - - Ox.forEach(Ox.MODIFIER_KEYS, function(v, k) { - // avoid pushing modifier twice - // using event.originalEvent since jquery always sets - // event.metaKey to event.ctrlKey - if (event.originalEvent[k] && keyBasename != v) { - keyNames.splice(-1, 0, v); - } - }); - key = keyNames.join('_'); - // If no input element has focus, invoke global handlers - if ( - focused === null || ( - !$focused.hasClass('OxInput') - && !$focused.hasClass('OxEditableContent') - && !$focused.hasClass('OxAutocompleteMenu') - ) - ) { - bound.forEach(function(id) { - Ox.UI.elements[id].triggerEvent('key_' + key); - }); - // Don't open Chrome Inspect Element, used for copyadd - if (bound.length && key == 'control_shift_c') { - event.preventDefault(); - } - // Firefox opens quick find on slash and quick link find on quote otherwise - if (keyName == 'slash' || keyName == 'quote') { - event.preventDefault(); - } - } - // If the focused element is not bound globally, invoke element handlers - if (focused !== null && bound.indexOf(focused) == -1) { - $focused.triggerEvent('key_' + key); - // prevent Chrome from scrolling, or going back in history - if ( - [ - 'backspace', 'down', 'left', 'right', 'space', 'up' - ].indexOf(key) > -1 - && !$focused.hasClass('OxInput') - && !$focused.hasClass('OxEditableContent') - && !$focused.hasClass('OxAutocompleteMenu') - ) { - ret = false; - } - // prevent cursor in input field from moving to start or end - if ( - ['down', 'up'].indexOf(key) > -1 - && $focused.hasClass('OxAutocompleteMenu') - ) { - ret = false; - } - } - - if (/^[\w\d](\.numpad)?$|^space$/.test(key)) { - // don't register leading spaces or trailing double spaces - if (!(keyName == 'space' && (buffer == '' || / $/.test(buffer)))) { - buffer += keyName == 'space' ? ' ' : keyBasename; - // clear the trigger timeout only if the key went into the buffer - clearTimeout(triggerTimeout); - triggerTimeout = setTimeout(function() { - if (focused !== null) { - $focused.triggerEvent('keys', {keys: buffer}); - } - }, 250); - } - } - // clear the reset timeout even if the key didn't go into the buffer - clearTimeout(resetTimeout); - resetTimeout = setTimeout(function() { - buffer = ''; - }, 1000); - - // Firefox cancels active XMLHttpRequests when pressing escape - if (keyName == 'escape') { - event.preventDefault(); - } - - return ret; - - } - - return { - /*@ - bind bind - (id) -> bind id - @*/ - bind: function(id) { - var index = bound.indexOf(id); - index == -1 && bound.push(id); - }, - /*@ - unbind unbind - (id) -> unbind id - @*/ - unbind: function(id) { - var index = bound.indexOf(id); - index > -1 && bound.splice(index, 1); - } - }; - -}()); diff --git a/source/Ox.UI/js/Core/Message.js b/source/Ox.UI/js/Core/Message.js deleted file mode 100644 index 3e8cad2f..00000000 --- a/source/Ox.UI/js/Core/Message.js +++ /dev/null @@ -1,87 +0,0 @@ -/*@ -Ox.Message Message controller -@*/ - -Ox.Message = (function() { - - var that = {}, - callbacks = []; - - window.addEventListener('message', function(e) { - var data = {}; - try { - data = JSON.parse(e.data); - } catch(e) {} - Ox.Log('MESSAGE', data) - if (data.event == 'init') { - window.oxid = data.data.id; - } else if (data.event) { - callbacks.forEach(function(callback) { - callback(data.event, data.data, data.oxid); - }); - } else { - Ox.Log('Core', 'unknown message', e.data); - } - }); - - // Defined here so one can just load Message.js in addtion to Ox.js - Ox.$parent = { - onMessage: function() { - var callback; - if (Ox.isObject(arguments[0])) { - Ox.forEach(arguments[0], function(callback, event) { - Ox.Message.bind(function(event_, data, oxid) { - if (event_ == event && Ox.isUndefined(oxid)) { - callback(data || {}); - } - }); - }); - } else { - callback = arguments[0]; - Ox.Message.bind(function(event, data, oxid) { - if (Ox.isUndefined(oxid)) { - callback(event, data || {}); - } - }); - } - return this; - }, - postMessage: function(event, message) { - Ox.Message.post(Ox.$parent, event, message); - return this; - } - }; - - /*@ - .bind Adds message handler - (callback) -> Ox.Message - callback Callback function - - @*/ - that.bind = function(callback) { - callbacks.push(callback); - return that; - }; - - /*@ - .post Sends a message - (target, event, data) -> Ox.Message - target Ox.$parent or iframe Ox.Element or element id - event Event name - data Event data - @*/ - that.post = function(target, event, data) { - target = target == Ox.$parent ? window.parent - : Ox.isElement(target[0]) ? target[0].contentWindow - : Ox.$('#' + target)[0].contentWindow; - target.postMessage(JSON.stringify({ - data: data, - event: event, - oxid: window.oxid - }), '*'); - return that; - }; - - return that; - -})();