-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathservices_MP.Controls.service.js.html
More file actions
545 lines (483 loc) · 19.1 KB
/
services_MP.Controls.service.js.html
File metadata and controls
545 lines (483 loc) · 19.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width">
<title>DocStrap Source: services/MP.Controls.service.js</title>
<!--[if lt IE 9]>
<script src="//html5shiv.googlecode.com/svn/trunk/html5.js"></script>
<![endif]-->
<link type="text/css" rel="stylesheet" href="styles/sunlight.default.css">
<link type="text/css" rel="stylesheet" href="styles/site.cosmo.css">
</head>
<body>
<div class="navbar navbar-default navbar-fixed-top navbar-inverse">
<div class="container">
<div class="navbar-header">
<a class="navbar-brand" href="index.html">DocStrap</a>
<button class="navbar-toggle" type="button" data-toggle="collapse" data-target="#topNavigation">
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
</div>
<div class="navbar-collapse collapse" id="topNavigation">
<ul class="nav navbar-nav">
<li class="dropdown">
<a href="classes.list.html" class="dropdown-toggle" data-toggle="dropdown">Classes<b class="caret"></b></a>
<ul class="dropdown-menu ">
<li><a href="MemoryPlayerAPI.html">MemoryPlayerAPI</a></li><li><a href="MemoryPlayerComponent.html">MemoryPlayerComponent</a></li><li><a href="MemoryPlayerConfig.html">MemoryPlayerConfig</a></li><li><a href="MemoryPlayerController.html">MemoryPlayerController</a></li><li><a href="MemoryPlayerControls.html">MemoryPlayerControls</a></li><li><a href="MemoryPlayerProvider.html">MemoryPlayerProvider</a></li><li><a href="MemoryPlayerRun.html">MemoryPlayerRun</a></li><li><a href="MemoryPlayerSharing.html">MemoryPlayerSharing</a></li><li><a href="MemoryPlayerState.html">MemoryPlayerState</a></li><li><a href="MPPlayerController.html">MPPlayerController</a></li><li><a href="MPSharingComponent.html">MPSharingComponent</a></li><li><a href="MPSharingController.html">MPSharingController</a></li>
</ul>
</li>
</ul>
<div class="col-sm-3 col-md-3">
<form class="navbar-form" role="search">
<div class="input-group">
<input type="text" class="form-control" placeholder="Search" name="q" id="search-input">
<div class="input-group-btn">
<button class="btn btn-default" id="search-submit"><i class="glyphicon glyphicon-search"></i></button>
</div>
</div>
</form>
</div>
</div>
</div>
</div>
<div class="container" id="toc-content">
<div class="row">
<div class="col-md-12">
<div id="main">
<h1 class="page-title">Source: services/MP.Controls.service.js</h1>
<section>
<article>
<pre
class="sunlight-highlight-javascript linenums">var MemoryPlayerControls = /** @class */ (function () {
/**
* Implements IMemoryPlayerControls
* @constructs MemoryPlayerControls
* @param {IRootScopeService} $rootScope - The core angular root scope service.
* @param {IJPlayerProvider} JPlayer - The provider service that manages jplayer.
* @param {IMemoryPlayerState} MemoryPlayerState - The service that manages memory player state.
*/
function MemoryPlayerControls($rootScope, JPlayer, MemoryPlayerState) {
var _this = this;
this.$rootScope = $rootScope;
this.JPlayer = JPlayer;
this.MemoryPlayerState = MemoryPlayerState;
// Stores player id for optimization
this.jPlayerId = this.JPlayer.ids.jPlayer;
// Observes player ready
this.$rootScope.$on('MP:Ready', function ($event) {
/**
* Observes player volume change.
*/
angular.element(_this.jPlayerId).bind($.jPlayer.event.volumechange, function (event) {
// Updates volume
_this.MemoryPlayerState.setVolume(event.jPlayer.options.volume);
// Updates is muted
_this.MemoryPlayerState.setIsMuted(event.jPlayer.options.muted);
});
/**
* Observes current track ended.
*/
angular.element(_this.jPlayerId).bind($.jPlayer.event.ended, function () {
// If playlist is not over then update state, else start from beginning
if (!_this.isEnd()) {
// Gets next track id
var trackId_1 = (_this.MemoryPlayerState.getTrackId() + 1);
_this.$rootScope.$evalAsync(function () {
// Updates current track
_this.MemoryPlayerState.setTrack(trackId_1);
});
}
else {
_this.$rootScope.$evalAsync(function () {
// Starts playlist from beginning
_this.selectTrack(0);
});
}
});
});
/**
* Observes open playlist dropdown click inside to prevent close.
*/
angular.element('#memory-player').on('click.mp.dropdown', '.mp-dropdown-menu', function (event) {
event.stopPropagation();
});
/**
* Observes click to close open playlist dropdown.
*/
angular.element(document).on('click.mp.dropdown', function (event) {
var $dropdown = angular.element('.mp-dropdown');
// If dropdown is open then close it
if (!angular.element(event.target).closest('.mp-dropdown-toggle').length && $dropdown.hasClass('open')) {
// Closes dropdown
$dropdown.removeClass('open');
// Updates aria for accessibility
$dropdown.find('a').attr('aria-expanded', 'false');
}
});
/**
* Observes click to close open playlist dropdown on mobile devices.
*/
angular.element(document).on('click.mp.dropdown', '.mp-dropdown-backdrop', function (event) {
// Removes dropdown backdrop
angular.element(event.target).remove();
var $dropdown = angular.element('.mp-dropdown');
// Closes dropdown
$dropdown.removeClass('open');
// Updates aria for accessibility
$dropdown.find('a').attr('aria-expanded', 'false');
});
/**
* Observes custom event that YouTube video has played and prevents simultaneous playback.
*/
angular.element(document).on('YT.VideoPlayed', function () {
// If player is playing then toggle playback to pause
if (!_this.MemoryPlayerState.getIsPaused()) {
_this.$rootScope.$evalAsync(function () {
// Pauses player
_this.play();
});
}
});
}
/**
* Checks if current track is last in playlist.
* @memberof MemoryPlayerControls
* @instance
* @returns {boolean} - True if current track is last, else false.
* @private
*/
MemoryPlayerControls.prototype.isEnd = function () {
// Compares track index to track count
var trackId = (this.MemoryPlayerState.getTrackId() + 1), currentPlaylist = this.MemoryPlayerState.getPlaylist();
return !(trackId < currentPlaylist.trackCount);
};
/**
* Sets player to max volume.
* @memberof MemoryPlayerControls
* @instance
*/
MemoryPlayerControls.prototype.maxVolume = function () {
// If muted then unmute
if (this.MemoryPlayerState.getIsMuted()) {
// Unmutes player
angular.element(this.jPlayerId).jPlayer('unmute');
// Updates is muted
this.MemoryPlayerState.setIsMuted(false);
}
// Sets max volume
angular.element(this.jPlayerId).jPlayer('volume', 1);
};
/**
* Toggles mute and unmute.
* @memberof MemoryPlayerControls
* @instance
*/
MemoryPlayerControls.prototype.mute = function () {
// Gets is muted
var isMuted = this.MemoryPlayerState.getIsMuted();
// Toggles mute
(isMuted) ? angular.element(this.jPlayerId).jPlayer('unmute') : angular.element(this.jPlayerId).jPlayer('mute');
// Updates is muted
this.MemoryPlayerState.setIsMuted(!isMuted);
};
/**
* Plays next track.
* @memberof MemoryPlayerControls
* @instance
*/
MemoryPlayerControls.prototype.next = function () {
// If current track is not last in playlist then play next
if (!this.isEnd()) {
// Gets next track id
var trackId = (this.MemoryPlayerState.getTrackId() + 1);
// Updates current track
this.MemoryPlayerState.setTrack(trackId);
// Plays next track
this.JPlayer.instance().next();
// Updates play state
this.MemoryPlayerState.setIsPaused(false);
// Notifies other media of play event
angular.element(this.jPlayerId).trigger('MP.TrackPlayed');
}
};
/**
* Toggles play and pause.
* @memberof MemoryPlayerControls
* @instance
*/
MemoryPlayerControls.prototype.play = function () {
// Gets play state
var isPaused = this.MemoryPlayerState.getIsPaused();
// Toggles play
(isPaused) ? this.JPlayer.instance().play() : this.JPlayer.instance().pause();
// Updates play state
this.MemoryPlayerState.setIsPaused(!isPaused);
// If playing then notify other media
if (isPaused) {
angular.element(this.jPlayerId).trigger('MP.TrackPlayed');
}
};
/**
* Plays previous track.
* @memberof MemoryPlayerControls
* @instance
*/
MemoryPlayerControls.prototype.previous = function () {
// Gets previous track id
var trackId = (this.MemoryPlayerState.getTrackId() - 1);
// If current track is not first in playlist then play previous
if (trackId >= 0) {
// Updates current track
this.MemoryPlayerState.setTrack(trackId);
// Plays previous track
this.JPlayer.instance().previous();
// Updates play state
this.MemoryPlayerState.setIsPaused(false);
// Notifies other media of play event
angular.element(this.jPlayerId).trigger('MP.TrackPlayed');
}
};
/**
* Restarts player with previous settings.
* @memberof MemoryPlayerControls
* @instance
* @param {IRestartSettings} settings - Settings required to restart player.
* @private
*/
MemoryPlayerControls.prototype.restart = function (settings) {
// Updates current track
this.MemoryPlayerState.setTrack(settings.track);
// Sets player to current track
this.JPlayer.instance().select(settings.track);
// Sets player to current volume
angular.element(this.jPlayerId).jPlayer('volume', settings.volume);
// If is muted then set player and update state
if (settings.isMuted === true) {
// Mutes player
angular.element(this.jPlayerId).jPlayer('mute');
// Updates is muted
this.MemoryPlayerState.setIsMuted(true);
}
// Assigns variable to set play state
var playState = 'pause';
// If playing then update
if (settings.isPaused !== true) {
playState = 'play';
// Updates play state
this.MemoryPlayerState.setIsPaused(false);
}
// Sets player to current time and play state
angular.element(this.jPlayerId).jPlayer(playState, settings.time);
};
/**
* Plays selected playlist.
* @memberof MemoryPlayerControls
* @instance
* @param {string} playlistName - The name of selected playlist.
*/
MemoryPlayerControls.prototype.selectPlaylist = function (playlistName) {
// Updates current playlist
this.MemoryPlayerState.setPlaylist(playlistName);
// Gets current playlist
var tracks = this.MemoryPlayerState.getPlaylist().tracks;
// Sets current playlist in player
this.JPlayer.instance().setPlaylist(tracks);
// Plays first track
this.JPlayer.instance().play();
// Updates play state
this.MemoryPlayerState.setIsPaused(false);
// Notifies other media of play event
angular.element(this.jPlayerId).trigger('MP.TrackPlayed');
};
/**
* Plays selected track.
* @memberof MemoryPlayerControls
* @instance
* @param {number} trackIndex - The index of selected track in playlist.
*/
MemoryPlayerControls.prototype.selectTrack = function (trackIndex) {
// If selected track is different from current then set track and play, else toggle play
if (trackIndex !== this.MemoryPlayerState.getTrackId()) {
// Updates current track
this.MemoryPlayerState.setTrack(trackIndex);
// Plays selected track
this.JPlayer.instance().play(trackIndex);
// Updates play state
this.MemoryPlayerState.setIsPaused(false);
// Notifies other media of play event
angular.element(this.jPlayerId).trigger('MP.TrackPlayed');
}
else {
// Toggles play
this.play();
}
};
/**
* Creates player and executes restart with previous settings if available.
* @memberof MemoryPlayerControls
* @instance
* @param {string} playlist - The name of current playlist.
* @param {IRestartSettings} settings - Settings required to restart player.
*/
MemoryPlayerControls.prototype.showtime = function (playlist, settings) {
var _this = this;
// Updates current playlist
this.MemoryPlayerState.setPlaylist(playlist);
// Creates jplayer instance with current playlist
this.JPlayer.create(this.MemoryPlayerState.getPlaylist().tracks);
// Observes player ready
angular.element(this.jPlayerId).bind($.jPlayer.event.ready, function () {
// If settings exist then restart
if (angular.isDefined(settings)) {
// Restarts player
_this.restart(settings);
}
// Notifies that player setup is complete
_this.$rootScope.$broadcast('MP:Ready');
// Removes loading class
angular.element('#memory-player').removeClass('mp-loading');
});
};
/**
* Toggles playlist dropdown.
* @memberof MemoryPlayerControls
* @instance
* @param {JQueryEventObject} $event - The event from trigger element.
*/
MemoryPlayerControls.prototype.toggleDropdown = function ($event) {
// Sets values to update dropdown state
var $trigger = angular.element($event.target), $parent = $trigger.closest('.mp-dropdown'), isActive = $parent.hasClass('open'), $backdrop = angular.element(document.createElement('div')).addClass('mp-dropdown-backdrop');
// Removes dropdown backdrop
angular.element('.mp-dropdown-backdrop').remove();
// Resets each dropdown
angular.element('.mp-dropdown-toggle').each(function () {
// Ignores closed dropdowns
if (!angular.element(this).closest('.mp-dropdown').hasClass('open'))
return;
// Closes open dropdowns
angular.element(this).closest('.mp-dropdown').removeClass('open');
// Updates aria for accessibility
angular.element(this).attr('aria-expanded', 'false');
});
// If dropdown was closed then open it
if (!isActive) {
// If user is on mobile device append backdrop
if ('ontouchstart' in document.documentElement) {
$backdrop.appendTo('body');
}
// Opens dropdown
$parent.addClass('open');
// Updates aria for accessibility
$trigger.closest('.mp-dropdown-toggle').attr('aria-expanded', 'true');
}
};
MemoryPlayerControls.instance = [
'$rootScope',
'JPlayer',
'MemoryPlayerState',
MemoryPlayerControls
];
return MemoryPlayerControls;
}());
(function () {
'use strict';
angular.module('MemoryPlayer')
.service('MemoryPlayerControls', MemoryPlayerControls.instance);
})();
</pre>
</article>
</section>
</div>
</div>
<div class="clearfix"></div>
</div>
</div>
<div class="modal fade" id="searchResults">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">×</span></button>
<h4 class="modal-title">Search results</h4>
</div>
<div class="modal-body"></div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
</div>
</div><!-- /.modal-content -->
</div><!-- /.modal-dialog -->
</div>
<footer>
<span class="copyright">
DocStrap Copyright © 2012-2017 The contributors to the JSDoc3 and DocStrap projects.
</span>
<span class="jsdoc-message">
Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.5.5</a>
on Mon Sep 10th 2018
using the <a href="https://github.com/docstrap/docstrap">DocStrap template</a>.
</span>
</footer>
<script src="scripts/docstrap.lib.js"></script>
<script src="scripts/toc.js"></script>
<script type="text/javascript" src="scripts/fulltext-search-ui.js"></script>
<script>
$( function () {
$( "[id*='$']" ).each( function () {
var $this = $( this );
$this.attr( "id", $this.attr( "id" ).replace( "$", "__" ) );
} );
$( ".tutorial-section pre, .readme-section pre, pre.prettyprint.source" ).each( function () {
var $this = $( this );
var example = $this.find( "code" );
exampleText = example.html();
var lang = /{@lang (.*?)}/.exec( exampleText );
if ( lang && lang[1] ) {
exampleText = exampleText.replace( lang[0], "" );
example.html( exampleText );
lang = lang[1];
} else {
var langClassMatch = example.parent()[0].className.match(/lang\-(\S+)/);
lang = langClassMatch ? langClassMatch[1] : "javascript";
}
if ( lang ) {
$this
.addClass( "sunlight-highlight-" + lang )
.addClass( "linenums" )
.html( example.html() );
}
} );
Sunlight.highlightAll( {
lineNumbers : true,
showMenu : true,
enableDoclinks : true
} );
$.catchAnchorLinks( {
navbarOffset: 10
} );
$( "#toc" ).toc( {
anchorName : function ( i, heading, prefix ) {
return $( heading ).attr( "id" ) || ( prefix + i );
},
selectors : "#toc-content h1,#toc-content h2,#toc-content h3,#toc-content h4",
showAndHide : false,
smoothScrolling: true
} );
$( "#main span[id^='toc']" ).addClass( "toc-shim" );
$( '.dropdown-toggle' ).dropdown();
$( "table" ).each( function () {
var $this = $( this );
$this.addClass('table');
} );
} );
</script>
<!--Navigation and Symbol Display-->
<!--Google Analytics-->
<script type="text/javascript">
$(document).ready(function() {
SearcherDisplay.init();
});
</script>
</body>
</html>