Skip to content

Commit

Permalink
2.4.0
Browse files Browse the repository at this point in the history
  • Loading branch information
j3tan committed Mar 23, 2016
1 parent 7783f37 commit d7d3a67
Show file tree
Hide file tree
Showing 23 changed files with 402 additions and 173 deletions.
9 changes: 9 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,12 @@
v2.4.0 - March 23, 2016

* 2.4.0 (Jeff Tan)
* Add reportWarning to test service provider (Jeff Tan)
* Add custom event types (Jeff Tan)
* Add reportWarning to Box.Application (Jeff Tan)
* Include the data-module element when finding event targets (Jeff Tan)
* Update Copyright year (Jeff Tan)

v2.3.0 - March 16, 2016

* 2.3.0 (Jeff Tan)
Expand Down
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,16 +44,16 @@ The last published release:

```
<!-- Recommended: Latest version of T3 -->
<script src="https://cdn.rawgit.com/box/t3js/v2.3.0/dist/t3.js"></script>
<script src="https://cdn.rawgit.com/box/t3js/v2.4.0/dist/t3.js"></script>
<!-- Recommended: Latest minified version of T3 -->
<script src="https://cdn.rawgit.com/box/t3js/v2.3.0/dist/t3.min.js"></script>
<script src="https://cdn.rawgit.com/box/t3js/v2.4.0/dist/t3.min.js"></script>
<!-- jQuery version (IE8 + 1.8.0+ jQuery) -->
<script src="https://cdn.rawgit.com/box/t3js/v2.3.0/dist/t3-jquery.js"></script>
<script src="https://cdn.rawgit.com/box/t3js/v2.4.0/dist/t3-jquery.js"></script>
<!-- jQuery minified version (IE8 + 1.8.0+ jQuery) -->
<script src="https://cdn.rawgit.com/box/t3js/v2.3.0/dist/t3-jquery.min.js"></script>
<script src="https://cdn.rawgit.com/box/t3js/v2.4.0/dist/t3-jquery.min.js"></script>
```
## Upgrade from 1.5.1 to 2.0.0

Expand Down
18 changes: 0 additions & 18 deletions dist/t3-jquery-2.3.0.min.js

This file was deleted.

58 changes: 45 additions & 13 deletions dist/t3-jquery-2.3.0.js → dist/t3-jquery-2.4.0.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*! t3-jquery v2.3.0 */
/*! t3-jquery v2.4.0 */
/*!
Copyright 2015 Box, Inc. All rights reserved.
Copyright 2016 Box, Inc. All rights reserved.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -226,7 +226,7 @@ Box.DOMEventDelegate = (function() {
'use strict';

// Supported events for modules. Only events that bubble properly can be used in T3.
var EVENT_TYPES = ['click', 'mouseover', 'mouseout', 'mousedown', 'mouseup',
var DEFAULT_EVENT_TYPES = ['click', 'mouseover', 'mouseout', 'mousedown', 'mouseup',
'mouseenter', 'mouseleave', 'mousemove', 'keydown', 'keyup', 'submit', 'change',
'contextmenu', 'dblclick', 'input', 'focusin', 'focusout'];

Expand Down Expand Up @@ -259,18 +259,21 @@ Box.DOMEventDelegate = (function() {
*/
function getNearestTypeElement(element) {
var found = false;
var moduleBoundaryReached = false;

// We need to check for the existence of 'element' since occasionally we call this on a detached element node.
// For example:
// 1. event handlers like mouseout may sometimes detach nodes from the DOM
// 2. event handlers like mouseleave will still fire on the detached node
// Checking existence of element.parentNode ensures the element is a valid HTML Element
while (!found && element && element.parentNode && !isModuleElement(element)) {
while (!found && element && element.parentNode && !moduleBoundaryReached) {
found = isTypeElement(element);
moduleBoundaryReached = isModuleElement(element);

if (!found) {
element = element.parentNode;
}

}

return found ? element : null;
Expand All @@ -279,19 +282,20 @@ Box.DOMEventDelegate = (function() {
/**
* Iterates over each supported event type that is also in the handler, applying
* a callback function. This is used to more easily attach/detach all events.
* @param {string[]} eventTypes A list of event types to iterate over
* @param {Object} handler An object with onclick, onmouseover, etc. methods.
* @param {Function} callback The function to call on each event type.
* @param {Object} [thisValue] The value of "this" inside the callback.
* @returns {void}
* @private
*/
function forEachEventType(handler, callback, thisValue) {
function forEachEventType(eventTypes, handler, callback, thisValue) {

var i,
type;

for (i = 0; i < EVENT_TYPES.length; i++) {
type = EVENT_TYPES[i];
for (i = 0; i < eventTypes.length; i++) {
type = eventTypes[i];

// only call the callback if the event is on the handler
if (handler['on' + type]) {
Expand All @@ -304,9 +308,10 @@ Box.DOMEventDelegate = (function() {
* An object that manages events within a single DOM element.
* @param {HTMLElement} element The DOM element to handle events for.
* @param {Object} handler An object containing event handlers such as "onclick".
* @param {string[]} [eventTypes] A list of event types to handle (events must bubble). Defaults to a common set of events.
* @constructor
*/
function DOMEventDelegate(element, handler) {
function DOMEventDelegate(element, handler, eventTypes) {

/**
* The DOM element that this object is handling events for.
Expand All @@ -321,6 +326,13 @@ Box.DOMEventDelegate = (function() {
*/
this._handler = handler;

/**
* List of event types to handle (make sure these events bubble!)
* @type {string[]}
* @private
*/
this._eventTypes = eventTypes || DEFAULT_EVENT_TYPES;

/**
* Tracks event handlers whose this-value is bound to the correct
* object.
Expand Down Expand Up @@ -357,7 +369,7 @@ Box.DOMEventDelegate = (function() {
attachEvents: function() {
if (!this._attached) {

forEachEventType(this._handler, function(eventType) {
forEachEventType(this._eventTypes, this._handler, function(eventType) {
var that = this;

function handleEvent() {
Expand All @@ -378,7 +390,7 @@ Box.DOMEventDelegate = (function() {
* @returns {void}
*/
detachEvents: function() {
forEachEventType(this._handler, function(eventType) {
forEachEventType(this._eventTypes, this._handler, function(eventType) {
Box.DOM.off(this.element, eventType, this._boundHandler[eventType]);
}, this);
}
Expand Down Expand Up @@ -824,7 +836,7 @@ Box.Application = (function() {
* @private
*/
function createAndBindEventDelegate(eventDelegates, element, handler) {
var delegate = new Box.DOMEventDelegate(element, handler);
var delegate = new Box.DOMEventDelegate(element, handler, globalConfig.eventTypes);
eventDelegates.push(delegate);
delegate.attachEvents();
}
Expand Down Expand Up @@ -879,7 +891,7 @@ Box.Application = (function() {
* Gets message handlers from the provided module instance
* @param {Box.Application~ModuleInstance|Box.Application~BehaviorInstance} instance Messages handlers will be retrieved from the Instance object
* @param {String} name The name of the message to be handled
* @param {Any} data A playload to be passed to the message handler
* @param {Any} data A playload to be passed to the message handler
* @returns {void}
* @private
*/
Expand Down Expand Up @@ -1320,7 +1332,27 @@ Box.Application = (function() {
* @param {Error} [exception] The exception object to use.
* @returns {void}
*/
reportError: error
reportError: error,

/**
* Signals that an warning has occurred.
* If in development mode, console.warn is invoked.
* If in production mode, an event is fired.
* @param {*} data A message string or arbitrary data
* @returns {void}
*/
reportWarning: function(data) {
if (globalConfig.debug) {
// We grab console via getGlobal() so we can stub it out in tests
var globalConsole = this.getGlobal('console');
if (globalConsole && globalConsole.warn) {
globalConsole.warn(data);
}
} else {
application.fire('warning', data);
}
}

});

}());
Expand Down
Loading

0 comments on commit d7d3a67

Please sign in to comment.