(function ($) { AblePlayer.prototype.setCookie = function(cookieValue) { Cookies.set('Able-Player', cookieValue, { expires:90 }); // set the cookie lifetime for 90 days }; AblePlayer.prototype.getCookie = function() { var defaultCookie = { preferences: {}, sign: {}, transcript: {} }; var cookie; try { cookie = Cookies.getJSON('Able-Player'); } catch (err) { // Original cookie can't be parsed; update to default Cookies.getJSON(defaultCookie); cookie = defaultCookie; } if (cookie) { return cookie; } else { return defaultCookie; } }; AblePlayer.prototype.updateCookie = function( setting ) { // called when a particular setting had been updated // useful for settings updated indpedently of Preferences dialog // e.g., prefAutoScrollTranscript, which is updated in control.js > handleTranscriptLockToggle() // setting is any supported preference name (e.g., "prefCaptions") // OR 'transcript' or 'sign' (not user-defined preferences, used to save position of draggable windows) var cookie, $window, windowPos, available, i, prefName; cookie = this.getCookie(); if (setting === 'transcript' || setting === 'sign') { if (setting === 'transcript') { $window = this.$transcriptArea; windowPos = $window.position(); if (typeof cookie.transcript === 'undefined') { cookie.transcript = {}; } cookie.transcript['position'] = $window.css('position'); // either 'relative' or 'absolute' cookie.transcript['zindex'] = $window.css('z-index'); cookie.transcript['top'] = windowPos.top; cookie.transcript['left'] = windowPos.left; cookie.transcript['width'] = $window.width(); cookie.transcript['height'] = $window.height(); } else if (setting === 'sign') { $window = this.$signWindow; windowPos = $window.position(); if (typeof cookie.sign === 'undefined') { cookie.sign = {}; } cookie.sign['position'] = $window.css('position'); // either 'relative' or 'absolute' cookie.sign['zindex'] = $window.css('z-index'); cookie.sign['top'] = windowPos.top; cookie.sign['left'] = windowPos.left; cookie.sign['width'] = $window.width(); cookie.sign['height'] = $window.height(); } } else { available = this.getAvailablePreferences(); // Rebuild cookie with current cookie values, // replacing the one value that's been changed for (i = 0; i < available.length; i++) { prefName = available[i]['name']; if (prefName == setting) { // this is the one that requires an update cookie.preferences[prefName] = this[prefName]; } } } // Save updated cookie this.setCookie(cookie); }; AblePlayer.prototype.getPreferencesGroups = function() { // return array of groups in the order in which they will appear // in the Preferences popup menu // Human-readable label for each group is defined in translation table if (this.mediaType === 'video') { return ['captions','descriptions','keyboard','transcript']; } else if (this.mediaType === 'audio') { var groups = []; groups.push('keyboard'); if (this.lyricsMode) { groups.push('transcript'); } return groups; } } AblePlayer.prototype.getAvailablePreferences = function() { // Return the list of currently available preferences. // Preferences with no 'label' are set within player, not shown in Prefs dialog var prefs = []; // Modifier keys preferences prefs.push({ 'name': 'prefAltKey', // use alt key with shortcuts 'label': this.tt.prefAltKey, 'group': 'keyboard', 'default': 1 }); prefs.push({ 'name': 'prefCtrlKey', // use ctrl key with shortcuts 'label': this.tt.prefCtrlKey, 'group': 'keyboard', 'default': 1 }); prefs.push({ 'name': 'prefShiftKey', 'label': this.tt.prefShiftKey, 'group': 'keyboard', 'default': 0 }); // Transcript preferences prefs.push({ 'name': 'prefTranscript', // transcript default state 'label': null, 'group': 'transcript', 'default': 0 // off because turning it on has a certain WOW factor }); prefs.push({ 'name': 'prefHighlight', // highlight transcript as media plays 'label': this.tt.prefHighlight, 'group': 'transcript', 'default': 1 // on because many users can benefit }); prefs.push({ 'name': 'prefAutoScrollTranscript', 'label': null, 'group': 'transcript', 'default': 1 }); prefs.push({ 'name': 'prefTabbable', // tab-enable transcript 'label': this.tt.prefTabbable, 'group': 'transcript', 'default': 0 // off because if users don't need it, it impedes tabbing elsewhere on the page }); if (this.mediaType === 'video') { // Caption preferences prefs.push({ 'name': 'prefCaptions', // closed captions default state 'label': null, 'group': 'captions', 'default': 1 }); /* // not supported yet prefs.push({ 'name': 'prefCaptionsStyle', 'label': this.tt.prefCaptionsStyle, 'group': 'captions', 'default': this.tt.captionsStylePopOn }); */ prefs.push({ 'name': 'prefCaptionsPosition', 'label': this.tt.prefCaptionsPosition, 'group': 'captions', 'default': this.defaultCaptionsPosition }); prefs.push({ 'name': 'prefCaptionsFont', 'label': this.tt.prefCaptionsFont, 'group': 'captions', 'default': this.tt.sans }); prefs.push({ 'name': 'prefCaptionsSize', 'label': this.tt.prefCaptionsSize, 'group': 'captions', 'default': '100%' }); prefs.push({ 'name': 'prefCaptionsColor', 'label': this.tt.prefCaptionsColor, 'group': 'captions', 'default': 'white' }); prefs.push({ 'name': 'prefCaptionsBGColor', 'label': this.tt.prefCaptionsBGColor, 'group': 'captions', 'default': 'black' }); prefs.push({ 'name': 'prefCaptionsOpacity', 'label': this.tt.prefCaptionsOpacity, 'group': 'captions', 'default': '100%' }); // Description preferences prefs.push({ 'name': 'prefDesc', // audio description default state 'label': null, 'group': 'descriptions', 'default': 0 // off because users who don't need it might find it distracting }); prefs.push({ 'name': 'prefDescFormat', // audio description default state 'label': this.tt.prefDescFormat, 'group': 'descriptions', 'default': 'video' }); prefs.push({ 'name': 'prefDescPause', // automatically pause when closed description starts 'label': this.tt.prefDescPause, 'group': 'descriptions', 'default': 0 // off because it burdens user with restarting after every pause }); prefs.push({ 'name': 'prefVisibleDesc', // visibly show closed description (if avilable and used) 'label': this.tt.prefVisibleDesc, 'group': 'descriptions', 'default': 1 // on because sighted users probably want to see this cool feature in action }); // Video preferences without a category (not shown in Preferences dialogs) prefs.push({ 'name': 'prefSign', // open sign language window by default if avilable 'label': null, 'group': null, 'default': 0 // off because clicking an icon to see the sign window has a powerful impact }); } return prefs; }; // Loads current/default preferences from cookie into the AblePlayer object. AblePlayer.prototype.loadCurrentPreferences = function () { var available = this.getAvailablePreferences(); var cookie = this.getCookie(); // Copy current cookie values into this object, and fill in any default values. for (var ii = 0; ii < available.length; ii++) { var prefName = available[ii]['name']; var defaultValue = available[ii]['default']; if (cookie.preferences[prefName] !== undefined) { this[prefName] = cookie.preferences[prefName]; } else { cookie.preferences[prefName] = defaultValue; this[prefName] = defaultValue; } } // Save since we may have added default values. this.setCookie(cookie); }; AblePlayer.prototype.injectPrefsForm = function (form) { // Creates a preferences form and injects it. // form is one of the supported forms (groups) defined in getPreferencesGroups() var available, thisObj, $prefsDiv, formTitle, introText, $prefsIntro,$prefsIntroP2,p3Text,$prefsIntroP3,i, j, $fieldset, fieldsetClass, fieldsetId, $descFieldset1, $descLegend1, $descFieldset2, $descLegend2, $legend, thisPref, $thisDiv, thisClass, thisId, $thisLabel, $thisField, $div1,id1,$radio1,$label1, $div2,id2,$radio2,$label2, options,$thisOption,optionValue,optionText,sampleCapsDiv, changedPref,changedSpan,changedText, currentDescState, $kbHeading,$kbList,kbLabels,keys,kbListText,$kbListItem, dialog,saveButton,cancelButton; thisObj = this; available = this.getAvailablePreferences(); // outer container, will be assigned role="dialog" $prefsDiv = $('
',{ 'class': 'able-prefs-form ' }); var customClass = 'able-prefs-form-' + form; $prefsDiv.addClass(customClass); // add intro if (form == 'captions') { formTitle = this.tt.prefTitleCaptions; introText = this.tt.prefIntroCaptions; // Uncomment the following line to include a cookie warning // Not included for now in order to cut down on unnecessary verbiage // introText += ' ' + this.tt.prefCookieWarning; $prefsIntro = $('

',{ text: introText }); $prefsDiv.append($prefsIntro); } else if (form == 'descriptions') { formTitle = this.tt.prefTitleDescriptions; var $prefsIntro = $('

',{ text: this.tt.prefIntroDescription1 }); var $prefsIntroUL = $('