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 = 25;
22
this._historyLimit = 10;
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, currentGroup, name = "";
35
layerArray = layerStringToLayerArray(layerString).sort();
37
$.each(layerArray, function (i, layer) {
38
layer = extractLayerName(this);
40
// Add instrument or detector if its not already present, otherwise
41
// add a backslash and move onto the right-hand side
42
if (currentGroup === layer[1] || currentGroup === layer[2]) {
45
// For STEREO use detector for the Left-hand side
46
if (layer[1] === "SECCHI") {
47
currentGroup = layer[2];
48
// Add "A" or "B" to differentiate spacecraft
49
name += ", " + layer[2] + "-" +
50
layer[0].substr(-1) + " ";
52
// Otherwise use the instrument name
53
currentGroup = layer[1];
54
name += ", " + layer[1] + " ";
58
// For LASCO, use the detector for the right-hand side
59
if (layer[1] === "LASCO") {
61
} else if (layer[2].substr(0, 3) === "COR") {
62
// For COR1 & 2 images
70
return name.slice(2); // Get rid of the extra ", " at the front
76
add: function (item) {
77
if (this._history.unshift(item) > this._historyLimit) {
78
this._history = this._history.slice(0, this._historyLimit);
85
* Returns the item with the specified id if it exists
90
// Find the index in the history array
91
$.each(this._history, function (i, item) {
97
return this._history[index];
106
$.each(this._history, function (i, item) {
107
self._history[i] = null;
115
* Check to see if an entry exists
120
$.each(this._history, function (i, item) {
121
if (item.id === id) {
132
* @param {String} id Item to be removed
134
remove: function (id) {
137
$.each(this._history, function (i, item) {
138
if (item.id === id) {
139
self._history[i] = null;
140
self._history.splice(i, 1);
148
* Returns an array containing objects for the items currently being tracked
150
toArray: function () {
151
return $.extend([], this._history);