2
* MediaManager class definition
3
* @author <a href="mailto:keith.hughitt@nasa.gov">Keith Hughitt</a>
5
/*jslint browser: true, white: true, onevar: true, undef: true, nomen: false, eqeqeq: true, plusplus: true,
6
bitwise: true, regexp: false, strict: true, newcap: true, immed: true, maxlen: 120, sub: true */
7
/*global Class, $, setTimeout, window, Media, extractLayerName, layerStringToLayerArray */
9
var MediaManager = Class.extend(
10
/** @lends MediaManager.prototype */
14
* @param {Array} history Items saved in the user's history
16
init: function (savedItems) {
17
this._history = savedItems;
19
if ($.support.localStorage) {
20
this._historyLimit = 20;
22
this._historyLimit = 5;
28
* Creates the name that will be displayed in the history.
29
* Groups layers together by detector, e.g. "EIT 171/304, LASCO C2/C3"
30
* Will crop names that are too long and append ellipses.
32
_getName: function (layerString) {
33
var layer, layerArray, observatory, instrument, detector, measurement,
34
currentGroup, name = "";
36
layerArray = layerStringToLayerArray(layerString).sort();
38
$.each(layerArray, function (i, layer) {
39
layer = extractLayerName(this);
41
observatory = layer[0];
42
instrument = layer[1];
44
measurement = layer[3];
46
// Add instrument or detector if its not already present, otherwise
47
// add a backslash and move onto the right-hand side
48
if (currentGroup === instrument || currentGroup === detector) {
51
// For STEREO use detector for the Left-hand side
52
if (instrument === "SECCHI") {
53
currentGroup = detector;
54
// Add "A" or "B" to differentiate spacecraft
55
name += ", " + detector + "-" +
56
observatory.substr(-1) + " ";
58
// Otherwise use the instrument name
59
currentGroup = instrument;
60
name += ", " + instrument + " ";
64
// For LASCO, use the detector for the right-hand side
65
if (instrument === "LASCO") {
67
} else if (detector.substr(0, 3) === "COR") {
68
// For COR1 & 2 images
75
return name.slice(2); // Get rid of the extra ", " at the front
81
add: function (item) {
82
if (this._history.unshift(item) > this._historyLimit) {
83
this._history = this._history.slice(0, this._historyLimit);
90
* Returns the item with the specified id if it exists
95
// Find the index in the history array
96
$.each(this._history, function (i, item) {
102
return this._history[index];
111
$.each(this._history, function (i, item) {
112
self._history[i] = null;
120
* Check to see if an entry exists
125
$.each(this._history, function (i, item) {
126
if (item.id === id) {
137
* @param {String} id Item to be removed
139
remove: function (id) {
142
$.each(this._history, function (i, item) {
143
if (item.id === id) {
144
self._history[i] = null;
145
self._history.splice(i, 1);
153
* Returns an array containing objects for the items currently being tracked
155
toArray: function () {
156
return $.extend([], this._history);