1- /*! t3-jquery v2.3 .0 */
1+ /*! t3-jquery v2.4 .0 */
22/*!
3- Copyright 2015 Box, Inc. All rights reserved.
3+ Copyright 2016 Box, Inc. All rights reserved.
44
55Licensed under the Apache License, Version 2.0 (the "License");
66you may not use this file except in compliance with the License.
@@ -226,7 +226,7 @@ Box.DOMEventDelegate = (function() {
226226 'use strict' ;
227227
228228 // Supported events for modules. Only events that bubble properly can be used in T3.
229- var EVENT_TYPES = [ 'click' , 'mouseover' , 'mouseout' , 'mousedown' , 'mouseup' ,
229+ var DEFAULT_EVENT_TYPES = [ 'click' , 'mouseover' , 'mouseout' , 'mousedown' , 'mouseup' ,
230230 'mouseenter' , 'mouseleave' , 'mousemove' , 'keydown' , 'keyup' , 'submit' , 'change' ,
231231 'contextmenu' , 'dblclick' , 'input' , 'focusin' , 'focusout' ] ;
232232
@@ -259,18 +259,21 @@ Box.DOMEventDelegate = (function() {
259259 */
260260 function getNearestTypeElement ( element ) {
261261 var found = false ;
262+ var moduleBoundaryReached = false ;
262263
263264 // We need to check for the existence of 'element' since occasionally we call this on a detached element node.
264265 // For example:
265266 // 1. event handlers like mouseout may sometimes detach nodes from the DOM
266267 // 2. event handlers like mouseleave will still fire on the detached node
267268 // Checking existence of element.parentNode ensures the element is a valid HTML Element
268- while ( ! found && element && element . parentNode && ! isModuleElement ( element ) ) {
269+ while ( ! found && element && element . parentNode && ! moduleBoundaryReached ) {
269270 found = isTypeElement ( element ) ;
271+ moduleBoundaryReached = isModuleElement ( element ) ;
270272
271273 if ( ! found ) {
272274 element = element . parentNode ;
273275 }
276+
274277 }
275278
276279 return found ? element : null ;
@@ -279,19 +282,20 @@ Box.DOMEventDelegate = (function() {
279282 /**
280283 * Iterates over each supported event type that is also in the handler, applying
281284 * a callback function. This is used to more easily attach/detach all events.
285+ * @param {string[] } eventTypes A list of event types to iterate over
282286 * @param {Object } handler An object with onclick, onmouseover, etc. methods.
283287 * @param {Function } callback The function to call on each event type.
284288 * @param {Object } [thisValue] The value of "this" inside the callback.
285289 * @returns {void }
286290 * @private
287291 */
288- function forEachEventType ( handler , callback , thisValue ) {
292+ function forEachEventType ( eventTypes , handler , callback , thisValue ) {
289293
290294 var i ,
291295 type ;
292296
293- for ( i = 0 ; i < EVENT_TYPES . length ; i ++ ) {
294- type = EVENT_TYPES [ i ] ;
297+ for ( i = 0 ; i < eventTypes . length ; i ++ ) {
298+ type = eventTypes [ i ] ;
295299
296300 // only call the callback if the event is on the handler
297301 if ( handler [ 'on' + type ] ) {
@@ -304,9 +308,10 @@ Box.DOMEventDelegate = (function() {
304308 * An object that manages events within a single DOM element.
305309 * @param {HTMLElement } element The DOM element to handle events for.
306310 * @param {Object } handler An object containing event handlers such as "onclick".
311+ * @param {string[] } [eventTypes] A list of event types to handle (events must bubble). Defaults to a common set of events.
307312 * @constructor
308313 */
309- function DOMEventDelegate ( element , handler ) {
314+ function DOMEventDelegate ( element , handler , eventTypes ) {
310315
311316 /**
312317 * The DOM element that this object is handling events for.
@@ -321,6 +326,13 @@ Box.DOMEventDelegate = (function() {
321326 */
322327 this . _handler = handler ;
323328
329+ /**
330+ * List of event types to handle (make sure these events bubble!)
331+ * @type {string[] }
332+ * @private
333+ */
334+ this . _eventTypes = eventTypes || DEFAULT_EVENT_TYPES ;
335+
324336 /**
325337 * Tracks event handlers whose this-value is bound to the correct
326338 * object.
@@ -357,7 +369,7 @@ Box.DOMEventDelegate = (function() {
357369 attachEvents : function ( ) {
358370 if ( ! this . _attached ) {
359371
360- forEachEventType ( this . _handler , function ( eventType ) {
372+ forEachEventType ( this . _eventTypes , this . _handler , function ( eventType ) {
361373 var that = this ;
362374
363375 function handleEvent ( ) {
@@ -378,7 +390,7 @@ Box.DOMEventDelegate = (function() {
378390 * @returns {void }
379391 */
380392 detachEvents : function ( ) {
381- forEachEventType ( this . _handler , function ( eventType ) {
393+ forEachEventType ( this . _eventTypes , this . _handler , function ( eventType ) {
382394 Box . DOM . off ( this . element , eventType , this . _boundHandler [ eventType ] ) ;
383395 } , this ) ;
384396 }
@@ -824,7 +836,7 @@ Box.Application = (function() {
824836 * @private
825837 */
826838 function createAndBindEventDelegate ( eventDelegates , element , handler ) {
827- var delegate = new Box . DOMEventDelegate ( element , handler ) ;
839+ var delegate = new Box . DOMEventDelegate ( element , handler , globalConfig . eventTypes ) ;
828840 eventDelegates . push ( delegate ) ;
829841 delegate . attachEvents ( ) ;
830842 }
@@ -879,7 +891,7 @@ Box.Application = (function() {
879891 * Gets message handlers from the provided module instance
880892 * @param {Box.Application~ModuleInstance|Box.Application~BehaviorInstance } instance Messages handlers will be retrieved from the Instance object
881893 * @param {String } name The name of the message to be handled
882- * @param {Any } data A playload to be passed to the message handler
894+ * @param {Any } data A playload to be passed to the message handler
883895 * @returns {void }
884896 * @private
885897 */
@@ -1320,7 +1332,27 @@ Box.Application = (function() {
13201332 * @param {Error } [exception] The exception object to use.
13211333 * @returns {void }
13221334 */
1323- reportError : error
1335+ reportError : error ,
1336+
1337+ /**
1338+ * Signals that an warning has occurred.
1339+ * If in development mode, console.warn is invoked.
1340+ * If in production mode, an event is fired.
1341+ * @param {* } data A message string or arbitrary data
1342+ * @returns {void }
1343+ */
1344+ reportWarning : function ( data ) {
1345+ if ( globalConfig . debug ) {
1346+ // We grab console via getGlobal() so we can stub it out in tests
1347+ var globalConsole = this . getGlobal ( 'console' ) ;
1348+ if ( globalConsole && globalConsole . warn ) {
1349+ globalConsole . warn ( data ) ;
1350+ }
1351+ } else {
1352+ application . fire ( 'warning' , data ) ;
1353+ }
1354+ }
1355+
13241356 } ) ;
13251357
13261358} ( ) ) ;
0 commit comments