Permalink
Browse files

Merge branch 't390'

Conflicts:
	src/core/trackevent.js
  • Loading branch information...
secretrobotron committed Mar 2, 2012
2 parents a41ed15 + 5c08bdd commit e1a29fafec46c7dccece53db952c6f246ac5bcd5
Showing with 100 additions and 28 deletions.
  1. +28 −8 editors/default-editor.html
  2. +9 −13 src/core/trackevent.js
  3. +36 −7 src/editor/editor.js
  4. +27 −0 src/util/time.js
@@ -4,6 +4,11 @@
<html>
<head>
+ <style>
+ p#message {
+ color: #FF0000;
+ }
+ </style>
<script type="text/javascript" src="../src/dialog/dialog-comm.js"></script>
<script type="text/javascript">
(function(){
@@ -16,22 +21,26 @@
okPressed,
cancelPressed;
- function sendData(){
+ function sendData( alsoClose ){
+ alsoClose = !!alsoClose;
var popcornOptions = {};
for( var item in _manifest ) {
popcornOptions[ item ] = document.getElementById( item ).value;
}
- _comm.send( "submit", popcornOptions);
+ document.getElementById( "message" ).innerHTML = "";
+ _comm.send( "submit", {
+ eventData: popcornOptions,
+ alsoClose: alsoClose
+ });
} //sendData
okPressed = function( e ) {
- sendData();
- _comm.send( "close" );
- };
+ sendData( true );
+ }; //okPressed
cancelPressed = function( e ) {
_comm.send( "cancel" );
- };
+ }; //cancelPressed
document.addEventListener( "keydown", function( e ) {
if( e.keyCode === 13 ) {
@@ -50,6 +59,12 @@
} //for
});
+ _comm.listen( "trackeventupdatefailed", function( e ) {
+ if( e.data.error === "trackeventupdate::invalidtime" ){
+ document.getElementById( "message" ).innerHTML = "You've entered an invalid start or end time. Please verify that they are both greater than 0, the end time is equal to or less than the media's duration, and that the start time is less than the end time.";
+ } //if
+ });
+
_comm.listen( "trackeventdata", function( e ){
var popcornOptions = e.data.popcornOptions,
targets = e.data.targets,
@@ -92,14 +107,18 @@
}
col2.appendChild( select );
- select.addEventListener( "change", sendData, false );
+ select.addEventListener( "change", function( e ){
+ sendData( false );
+ }, false );
} else {
var newItem = document.createElement( elem );
newItem.id = item;
newItem.style.width = "100%";
newItem.value = popcornOptions[ item ];
col2.appendChild( newItem );
- newItem.addEventListener( "change", sendData, false );
+ newItem.addEventListener( "change", function( e ){
+ sendData( false );
+ }, false );
}
row.appendChild( col1 );
@@ -117,5 +136,6 @@
</table>
<button id="ok">Ok</button>
<button id="cancel">Cancel</button>
+ <p id="message"></p>
</body>
</html>
View
@@ -2,10 +2,9 @@
* If a copy of the MIT license was not distributed with this file, you can
* obtain one at http://www.mozillapopcorn.org/butter-license.txt */
-define( [ "./logger", "./eventmanager", "util/lang" ], function( Logger, EventManager, util ) {
+define( [ "./logger", "./eventmanager", "util/lang", "util/time" ], function( Logger, EventManager, LangUtil, TimeUtil ) {
- var NUMBER_OF_DECIMAL_PLACES = 3,
- __guid = 0;
+ var __guid = 0;
var TrackEvent = function ( options ) {
@@ -23,19 +22,16 @@ define( [ "./logger", "./eventmanager", "util/lang" ], function( Logger, EventMa
start: 0,
end: 1
},
- _selected = false,
- _round = function( number, numberOfDecimalPlaces ) {
- return Math.round( number * ( Math.pow( 10, numberOfDecimalPlaces ) ) ) / Math.pow( 10, numberOfDecimalPlaces );
- };
+ _selected = false;
if( !_type ){
_logger.log( "Warning: " + _id + " has no type." );
} //if
_popcornOptions.start = _popcornOptions.start || 0;
- _popcornOptions.start = _round( _popcornOptions.start, NUMBER_OF_DECIMAL_PLACES );
+ _popcornOptions.start = TimeUtil.roundTime( _popcornOptions.start );
_popcornOptions.end = _popcornOptions.end || _popcornOptions.start + 1;
- _popcornOptions.end = _round( _popcornOptions.end, NUMBER_OF_DECIMAL_PLACES );
+ _popcornOptions.end = TimeUtil.roundTime( _popcornOptions.end );
this.update = function( updateOptions ) {
for ( var prop in updateOptions ) {
@@ -44,10 +40,10 @@ define( [ "./logger", "./eventmanager", "util/lang" ], function( Logger, EventMa
} //if
} //for
if ( _popcornOptions.start ) {
- _popcornOptions.start = _round( _popcornOptions.start, NUMBER_OF_DECIMAL_PLACES );
+ _popcornOptions.start = TimeUtil.roundTime( _popcornOptions.start );
}
if ( _popcornOptions.end ) {
- _popcornOptions.end = _round( _popcornOptions.end, NUMBER_OF_DECIMAL_PLACES );
+ _popcornOptions.end = TimeUtil.roundTime( _popcornOptions.end );
}
_em.dispatch( "trackeventupdated", _this );
}; //update
@@ -56,7 +52,7 @@ define( [ "./logger", "./eventmanager", "util/lang" ], function( Logger, EventMa
popcornOptions: {
enumerable: true,
get: function(){
- return util.clone( _popcornOptions );
+ return LangUtil.clone( _popcornOptions );
}
},
type: {
@@ -100,7 +96,7 @@ define( [ "./logger", "./eventmanager", "util/lang" ], function( Logger, EventMa
return {
id: _id,
type: _type,
- popcornOptions: util.clone( _popcornOptions ),
+ popcornOptions: LangUtil.clone( _popcornOptions ),
track: _track ? _track.name : undefined,
name: _name
};
View
@@ -2,7 +2,7 @@
* If a copy of the MIT license was not distributed with this file, you can
* obtain one at http://www.mozillapopcorn.org/butter-license.txt */
-define( [ "core/eventmanager", "dialog/iframe-dialog", "dialog/window-dialog" ], function( EventManager, IFrameDialog, WindowDialog ) {
+define( [ "core/eventmanager", "dialog/iframe-dialog", "dialog/window-dialog", "util/time" ], function( EventManager, IFrameDialog, WindowDialog, TimeUtil ) {
var DEFAULT_DIMS = [ 400, 400 ],
DEFAULT_FRAME_TYPE = "window";
@@ -58,8 +58,12 @@ define( [ "core/eventmanager", "dialog/iframe-dialog", "dialog/window-dialog" ],
} //if
} //blinkTarget
+ function onTrackEventUpdateFailed( e ){
+ _dialog.send( "trackeventupdatefailed", e.data );
+ } //onTrackEventUpdateFailed
+
_dialog.open({
- open: function( e ) {
+ open: function( e ){
var targets = [],
media = {
name: butter.currentMedia.name,
@@ -78,16 +82,41 @@ define( [ "core/eventmanager", "dialog/iframe-dialog", "dialog/window-dialog" ],
_currentTarget = corn.target;
blinkTarget();
trackEvent.listen( "trackeventupdated", onTrackEventUpdated );
+ trackEvent.listen( "trackeventupdatefailed", onTrackEventUpdateFailed );
},
- submit: function( e ) {
- if( e.data.target !== _currentTarget ){
- _currentTarget = e.data.target;
- blinkTarget();
+ submit: function( e ){
+ var duration = TimeUtil.roundTime( butter.currentMedia.duration ),
+ popcornData = e.data.eventData,
+ alsoClose = e.data.alsoClose;
+ if( popcornData ){
+ popcornData.start = Number( popcornData.start );
+ popcornData.end = Number( popcornData.end );
+ if( isNaN( popcornData.start ) ||
+ isNaN( popcornData.end ) ||
+ popcornData.start < 0 ||
+ popcornData.end > duration ||
+ popcornData.start >= popcornData.end ){
+ trackEvent.dispatch( "trackeventupdatefailed", {
+ error: "trackeventupdate::invalidtime",
+ message: "Invalid start/end times.",
+ attemptedData: popcornData
+ });
+ }
+ else{
+ if( popcornData.target !== _currentTarget ){
+ _currentTarget = popcornData.target;
+ blinkTarget();
+ } //if
+ trackEvent.update( popcornData );
+ if( alsoClose ){
+ _dialog.close();
+ } //if
+ } //if
} //if
- trackEvent.update( e.data );
},
close: function( e ){
trackEvent.unlisten( "trackeventupdated", onTrackEventUpdated );
+ trackEvent.unlisten( "trackeventupdatefailed", onTrackEventUpdateFailed );
}
});
}; //open
View
@@ -0,0 +1,27 @@
+define( [], function(){
+
+ var __timeAccuracy = 3;
+
+ function roundTime( time ){
+ return Math.round( time * ( Math.pow( 10, __timeAccuracy ) ) ) / Math.pow( 10, __timeAccuracy );
+ } //roundTime
+
+ var utils = {
+ roundTime: roundTime
+ }; //utils
+
+ Object.defineProperties( utils, {
+ timeAccuracy: {
+ enumerable: true,
+ get: function(){
+ return __timeAccuracy;
+ },
+ set: function( val ){
+ __timeAccuracy = val;
+ }
+ }
+ });
+
+ return utils;
+
+});

0 comments on commit e1a29fa

Please sign in to comment.