|
1841 | 1841 | {
|
1842 | 1842 | function removeListeners(button)
|
1843 | 1843 | {
|
| 1844 | + if (button === null) |
| 1845 | + { |
| 1846 | + return; |
| 1847 | + } |
| 1848 | + |
1844 | 1849 | button.classList.remove('unmuted');
|
1845 | 1850 | button.classList.remove('muted');
|
1846 | 1851 | button.classList.add(muted ? 'muted' : 'unmuted');
|
|
1872 | 1877 | */
|
1873 | 1878 | this._disableButton = function(button)
|
1874 | 1879 | {
|
| 1880 | + if (button === null) |
| 1881 | + { |
| 1882 | + return; |
| 1883 | + } |
| 1884 | + |
1875 | 1885 | button.classList.remove('enabled');
|
1876 | 1886 | button.classList.add('disabled');
|
1877 | 1887 | };
|
|
1953 | 1963 |
|
1954 | 1964 | if (null === this.captionsButton)
|
1955 | 1965 | {
|
1956 |
| - throw new Error( |
1957 |
| - 'No element found with the provided selector for captions button' |
1958 |
| - ); |
| 1966 | + return; |
1959 | 1967 | }
|
1960 | 1968 |
|
1961 |
| - this.captionsButton.addEventListener( |
1962 |
| - 'click', |
1963 |
| - function() |
1964 |
| - { |
1965 |
| - this.captionsMuted = !this.captionsMuted; |
1966 |
| - }.bind(this) |
1967 |
| - ); |
| 1969 | + this.captionsButtonClick = function() |
| 1970 | + { |
| 1971 | + this.captionsMuted = !this.captionsMuted; |
| 1972 | + }.bind(this); |
| 1973 | + |
| 1974 | + this.captionsButton.addEventListener('click', this.captionsButtonClick); |
| 1975 | + |
1968 | 1976 | /**
|
1969 | 1977 | * Set the captions are enabled or not
|
1970 | 1978 | * @property {boolean} captionsMuted
|
|
2095 | 2103 |
|
2096 | 2104 | plugin.opened = function()
|
2097 | 2105 | {
|
| 2106 | + if (null === this.captionsButton) |
| 2107 | + { |
| 2108 | + return; |
| 2109 | + } |
| 2110 | + |
2098 | 2111 | this.captionsButton.classList.remove('disabled');
|
2099 | 2112 | this.captionsMuted = !!SavedData.read(CAPTIONS_MUTED);
|
2100 | 2113 | this.setCaptionsStyles(SavedData.read(CAPTIONS_STYLES));
|
2101 | 2114 | };
|
2102 | 2115 |
|
2103 | 2116 | plugin.close = function()
|
2104 | 2117 | {
|
| 2118 | + if (null === this.captionsButton) |
| 2119 | + { |
| 2120 | + return; |
| 2121 | + } |
| 2122 | + |
2105 | 2123 | this._disableButton(this.captionsButton);
|
2106 | 2124 | };
|
2107 | 2125 |
|
2108 | 2126 | plugin.teardown = function()
|
2109 | 2127 | {
|
2110 |
| - this.captionsButton.off('click'); |
| 2128 | + if (null === this.captionsButton) |
| 2129 | + { |
| 2130 | + return; |
| 2131 | + } |
| 2132 | + |
| 2133 | + this.captionsButton.removeEventListener('click', this.captionsButtonClick); |
2111 | 2134 | delete this.captionsButton;
|
2112 | 2135 | delete this._captionsStyles;
|
2113 | 2136 | delete this.getCaptionsStyles;
|
|
2298 | 2321 |
|
2299 | 2322 | if (null === pauseFocus)
|
2300 | 2323 | {
|
2301 |
| - throw new Error('No element found with the provided for pauseFocus'); |
| 2324 | + return; |
2302 | 2325 | }
|
2303 | 2326 |
|
2304 | 2327 | pauseFocus.addEventListener('focus', function()
|
|
2404 | 2427 |
|
2405 | 2428 | plugin.teardown = function()
|
2406 | 2429 | {
|
2407 |
| - document |
2408 |
| - .querySelector(this.options.pauseFocusSelector) |
2409 |
| - .removeEventListener('focus'); |
| 2430 | + var pauseFocus = document.querySelector(this.options.pauseFocusSelector); |
| 2431 | + if (pauseFocus !== null) |
| 2432 | + { |
| 2433 | + pauseFocus.removeEventListener('focus'); |
| 2434 | + } |
| 2435 | + |
2410 | 2436 | document.removeEventListener('focus', this._onDocClick);
|
2411 | 2437 | document.removeEventListener('click', this._onDocClick);
|
2412 | 2438 | delete this._onDocClick;
|
|
2445 | 2471 |
|
2446 | 2472 | if (null === this.helpButton)
|
2447 | 2473 | {
|
2448 |
| - throw new Error( |
2449 |
| - 'No element found with the provided selector for help button' |
2450 |
| - ); |
| 2474 | + return; |
2451 | 2475 | }
|
2452 | 2476 |
|
2453 |
| - this.helpButton.addEventListener( |
2454 |
| - 'click', |
2455 |
| - function() |
| 2477 | + // store the listener so that we can use it later |
| 2478 | + this.helpButtonClick = function() |
| 2479 | + { |
| 2480 | + if (!this.paused && !this.helpButton.classList.contains('disabled')) |
2456 | 2481 | {
|
2457 |
| - if (!this.paused && !this.helpButton.classList.contains('disabled')) |
2458 |
| - { |
2459 |
| - this.client.send('playHelp'); |
2460 |
| - } |
2461 |
| - }.bind(this) |
2462 |
| - ); |
| 2482 | + this.client.send('playHelp'); |
| 2483 | + } |
| 2484 | + }.bind(this); |
| 2485 | + |
| 2486 | + this.helpButton.addEventListener('click', this.helpButtonClick); |
2463 | 2487 |
|
2464 | 2488 | this.helpButton.tooltip = function()
|
2465 | 2489 | {
|
|
2538 | 2562 |
|
2539 | 2563 | plugin.teardown = function()
|
2540 | 2564 | {
|
2541 |
| - this.helpButton.off('click'); |
| 2565 | + if (null === this.helpButton) |
| 2566 | + { |
| 2567 | + return; |
| 2568 | + } |
| 2569 | + |
| 2570 | + this.helpButton.removeEventListener('click', this.helpButtonClick); |
2542 | 2571 | delete this.helpButton;
|
2543 | 2572 | delete this._helpEnabled;
|
2544 | 2573 | };
|
|
2562 | 2591 | */
|
2563 | 2592 | this.pauseButton = document.querySelectorAll(this.options.pauseButton);
|
2564 | 2593 |
|
2565 |
| - if (1 > this.pauseButton.length) |
2566 |
| - { |
2567 |
| - throw new Error( |
2568 |
| - 'No element/elements found with provided selector(s) for pause button(s)' |
2569 |
| - ); |
2570 |
| - } |
| 2594 | + this.onPauseToggle = onPauseToggle.bind(this); |
2571 | 2595 |
|
2572 |
| - this.pauseButton.forEach( |
2573 |
| - function(element) |
2574 |
| - { |
2575 |
| - element.addEventListener('click', onPauseToggle.bind(this)); |
2576 |
| - }.bind(this) |
2577 |
| - ); |
| 2596 | + this.pauseButton.forEach(function(element) |
| 2597 | + { |
| 2598 | + element.addEventListener('click', this.onPauseToggle); |
| 2599 | + }.bind(this)); |
2578 | 2600 |
|
2579 | 2601 | /**
|
2580 | 2602 | * If the application is currently paused manually
|
|
2686 | 2708 |
|
2687 | 2709 | plugin.close = function()
|
2688 | 2710 | {
|
2689 |
| - this._disableButton(this.pauseButton); |
| 2711 | + this.pauseButton.forEach(this._disableButton.bind(this)); |
2690 | 2712 | this.paused = false;
|
2691 | 2713 | };
|
2692 | 2714 |
|
|
2695 | 2717 | this.pauseButton.forEach(
|
2696 | 2718 | function(element)
|
2697 | 2719 | {
|
2698 |
| - element.removeEventListener('click', onPauseToggle.bind(this)); |
| 2720 | + element.removeEventListener('click', this.onPauseToggle); |
2699 | 2721 | }.bind(this)
|
2700 | 2722 | );
|
2701 | 2723 | delete this.pauseButton;
|
|
2844 | 2866 | * @property {HTMLElement} soundButton
|
2845 | 2867 | */
|
2846 | 2868 | this.soundButton = document.querySelector(this.options.soundButton);
|
2847 |
| - this.soundButton.addEventListener('click', onSoundToggle.bind(this)); |
2848 |
| - |
2849 |
| - if (null === this.soundButton) |
2850 |
| - { |
2851 |
| - throw new Error( |
2852 |
| - 'No element found with provided selector for sound button' |
2853 |
| - ); |
2854 |
| - } |
2855 | 2869 |
|
2856 | 2870 | /**
|
2857 | 2871 | * Reference to the music mute button
|
2858 | 2872 | * @property {HTMLElement} musicButton
|
2859 | 2873 | */
|
2860 | 2874 | this.musicButton = document.querySelector(this.options.musicButton);
|
2861 |
| - this.musicButton.addEventListener('click', onMusicToggle.bind(this)); |
2862 |
| - |
2863 |
| - if (null === this.musicButton) |
2864 |
| - { |
2865 |
| - throw new Error( |
2866 |
| - 'No element found with provided selector for music button' |
2867 |
| - ); |
2868 |
| - } |
2869 | 2875 |
|
2870 | 2876 | /**
|
2871 | 2877 | * Reference to the sound effects mute button
|
2872 | 2878 | * @property {HTMLElement} sfxButton
|
2873 | 2879 | */
|
2874 | 2880 | this.sfxButton = document.querySelector(this.options.sfxButton);
|
2875 |
| - this.sfxButton.addEventListener('click', onSFXToggle.bind(this)); |
2876 |
| - |
2877 |
| - if (null === this.sfxButton) |
2878 |
| - { |
2879 |
| - throw new Error('No element found with provided selector for sfx button'); |
2880 |
| - } |
2881 | 2881 |
|
2882 | 2882 | /**
|
2883 | 2883 | * Reference to the voice-over mute button
|
2884 | 2884 | * @property {HTMLElement} voButton
|
2885 | 2885 | */
|
2886 | 2886 | this.voButton = document.querySelector(this.options.voButton);
|
2887 |
| - this.voButton.addEventListener('click', onVOToggle.bind(this)); |
2888 | 2887 |
|
2889 |
| - if (null === this.voButton) |
| 2888 | + if (null !== this.soundButton) |
2890 | 2889 | {
|
2891 |
| - throw new Error( |
2892 |
| - 'No element found with provided selector for voice-over button' |
2893 |
| - ); |
| 2890 | + this.soundButton.addEventListener('click', onSoundToggle.bind(this)); |
| 2891 | + } |
| 2892 | + |
| 2893 | + if (null !== this.musicButton) |
| 2894 | + { |
| 2895 | + this.musicButton.addEventListener('click', onMusicToggle.bind(this)); |
| 2896 | + } |
| 2897 | + |
| 2898 | + if (null !== this.sfxButton) |
| 2899 | + { |
| 2900 | + this.sfxButton.addEventListener('click', onSFXToggle.bind(this)); |
| 2901 | + } |
| 2902 | + |
| 2903 | + if (null !== this.voButton) |
| 2904 | + { |
| 2905 | + this.voButton.addEventListener('click', onVOToggle.bind(this)); |
2894 | 2906 | }
|
2895 | 2907 |
|
2896 | 2908 | /**
|
|
2985 | 2997 | 'features',
|
2986 | 2998 | function(features)
|
2987 | 2999 | {
|
2988 |
| - this.voButton.style.display = 'none'; |
2989 |
| - this.musicButton.style.display = 'none'; |
2990 |
| - this.soundButton.style.display = 'none'; |
2991 |
| - this.sfxButton.style.display = 'none'; |
| 3000 | + if (this.voButton !== null) |
| 3001 | + { |
| 3002 | + this.voButton.style.display = 'none'; |
| 3003 | + } |
| 3004 | + |
| 3005 | + if (this.musicButton !== null) |
| 3006 | + { |
| 3007 | + this.musicButton.style.display = 'none'; |
| 3008 | + } |
| 3009 | + |
| 3010 | + if (this.soundButton !== null) |
| 3011 | + { |
| 3012 | + this.soundButton.style.display = 'none'; |
| 3013 | + } |
2992 | 3014 |
|
2993 |
| - if (features.vo) this.voButton.style.display = 'inline-block'; |
2994 |
| - if (features.music) this.musicButton.style.display = 'inline-block'; |
2995 |
| - if (features.sound) this.soundButton.style.display = 'inline-block'; |
2996 |
| - if (features.sfxButton) this.sfxButton.style.display = 'inline-block'; |
| 3015 | + if (this.sfxButton !== null) |
| 3016 | + { |
| 3017 | + this.sfxButton.style.display = 'none'; |
| 3018 | + } |
| 3019 | + |
| 3020 | + if (features.vo && this.voButton) this.voButton.style.display = 'inline-block'; |
| 3021 | + if (features.music && this.musicButton) this.musicButton.style.display = 'inline-block'; |
| 3022 | + if (features.sound && this.soundButton) this.soundButton.style.display = 'inline-block'; |
| 3023 | + if (features.sfxButton && this.sfxButton) this.sfxButton.style.display = 'inline-block'; |
2997 | 3024 | }.bind(this)
|
2998 | 3025 | );
|
2999 | 3026 | };
|
|
3049 | 3076 |
|
3050 | 3077 | plugin.opened = function()
|
3051 | 3078 | {
|
3052 |
| - this.soundButton.classList.remove('disabled'); |
3053 |
| - this.sfxButton.classList.remove('disabled'); |
3054 |
| - this.voButton.classList.remove('disabled'); |
3055 |
| - this.musicButton.classList.remove('disabled'); |
| 3079 | + if (this.soundButton !== null) |
| 3080 | + { |
| 3081 | + this.soundButton.classList.remove('disabled'); |
| 3082 | + } |
| 3083 | + |
| 3084 | + if (this.sfxButton !== null) |
| 3085 | + { |
| 3086 | + this.sfxButton.classList.remove('disabled'); |
| 3087 | + } |
| 3088 | + |
| 3089 | + if (this.voButton !== null) |
| 3090 | + { |
| 3091 | + this.voButton.classList.remove('disabled'); |
| 3092 | + } |
| 3093 | + |
| 3094 | + if (this.musicButton !== null) |
| 3095 | + { |
| 3096 | + this.musicButton.classList.remove('disabled'); |
| 3097 | + } |
3056 | 3098 |
|
3057 | 3099 | this.soundMuted = !!SavedData.read(SOUND_MUTED);
|
3058 | 3100 | this.musicMuted = !!SavedData.read(MUSIC_MUTED);
|
|
3070 | 3112 |
|
3071 | 3113 | plugin.teardown = function()
|
3072 | 3114 | {
|
3073 |
| - this.soundButton.removeEventListener('click', onSoundToggle.bind(this)); |
3074 |
| - this.musicButton.removeEventListener('click', onMusicToggle.bind(this)); |
3075 |
| - this.sfxButton.removeEventListener('click', onSFXToggle.bind(this)); |
3076 |
| - this.voButton.removeEventListener('click', onVOToggle.bind(this)); |
| 3115 | + if (this.soundButton !== null) |
| 3116 | + { |
| 3117 | + this.soundButton.removeEventListener('click', onSoundToggle.bind(this)); |
| 3118 | + } |
| 3119 | + |
| 3120 | + if (this.musicButton !== null) |
| 3121 | + { |
| 3122 | + this.musicButton.removeEventListener('click', onMusicToggle.bind(this)); |
| 3123 | + } |
| 3124 | + |
| 3125 | + if (this.sfxButton !== null) |
| 3126 | + { |
| 3127 | + this.sfxButton.removeEventListener('click', onSFXToggle.bind(this)); |
| 3128 | + } |
| 3129 | + |
| 3130 | + if (this.voButton !== null) |
| 3131 | + { |
| 3132 | + this.voButton.removeEventListener('click', onVOToggle.bind(this)); |
| 3133 | + } |
| 3134 | + |
3077 | 3135 | delete this.voButton;
|
3078 | 3136 | delete this.sfxButton;
|
3079 | 3137 | delete this.musicButton;
|
|
0 commit comments