Skip to content

Commit c52f309

Browse files
authored
Merge pull request #11 from SpringRoll/feature/remove-jquery
Feature/remove jquery
2 parents 9476eff + e1d714a commit c52f309

13 files changed

+325
-179
lines changed

bower.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -30,4 +30,4 @@
3030
"src",
3131
"test"
3232
]
33-
}
33+
}

dist/container.js

+143-85
Original file line numberDiff line numberDiff line change
@@ -1841,6 +1841,11 @@
18411841
{
18421842
function removeListeners(button)
18431843
{
1844+
if (button === null)
1845+
{
1846+
return;
1847+
}
1848+
18441849
button.classList.remove('unmuted');
18451850
button.classList.remove('muted');
18461851
button.classList.add(muted ? 'muted' : 'unmuted');
@@ -1872,6 +1877,11 @@
18721877
*/
18731878
this._disableButton = function(button)
18741879
{
1880+
if (button === null)
1881+
{
1882+
return;
1883+
}
1884+
18751885
button.classList.remove('enabled');
18761886
button.classList.add('disabled');
18771887
};
@@ -1953,18 +1963,16 @@
19531963

19541964
if (null === this.captionsButton)
19551965
{
1956-
throw new Error(
1957-
'No element found with the provided selector for captions button'
1958-
);
1966+
return;
19591967
}
19601968

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+
19681976
/**
19691977
* Set the captions are enabled or not
19701978
* @property {boolean} captionsMuted
@@ -2095,19 +2103,34 @@
20952103

20962104
plugin.opened = function()
20972105
{
2106+
if (null === this.captionsButton)
2107+
{
2108+
return;
2109+
}
2110+
20982111
this.captionsButton.classList.remove('disabled');
20992112
this.captionsMuted = !!SavedData.read(CAPTIONS_MUTED);
21002113
this.setCaptionsStyles(SavedData.read(CAPTIONS_STYLES));
21012114
};
21022115

21032116
plugin.close = function()
21042117
{
2118+
if (null === this.captionsButton)
2119+
{
2120+
return;
2121+
}
2122+
21052123
this._disableButton(this.captionsButton);
21062124
};
21072125

21082126
plugin.teardown = function()
21092127
{
2110-
this.captionsButton.off('click');
2128+
if (null === this.captionsButton)
2129+
{
2130+
return;
2131+
}
2132+
2133+
this.captionsButton.removeEventListener('click', this.captionsButtonClick);
21112134
delete this.captionsButton;
21122135
delete this._captionsStyles;
21132136
delete this.getCaptionsStyles;
@@ -2298,7 +2321,7 @@
22982321

22992322
if (null === pauseFocus)
23002323
{
2301-
throw new Error('No element found with the provided for pauseFocus');
2324+
return;
23022325
}
23032326

23042327
pauseFocus.addEventListener('focus', function()
@@ -2404,9 +2427,12 @@
24042427

24052428
plugin.teardown = function()
24062429
{
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+
24102436
document.removeEventListener('focus', this._onDocClick);
24112437
document.removeEventListener('click', this._onDocClick);
24122438
delete this._onDocClick;
@@ -2445,21 +2471,19 @@
24452471

24462472
if (null === this.helpButton)
24472473
{
2448-
throw new Error(
2449-
'No element found with the provided selector for help button'
2450-
);
2474+
return;
24512475
}
24522476

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'))
24562481
{
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);
24632487

24642488
this.helpButton.tooltip = function()
24652489
{
@@ -2538,7 +2562,12 @@
25382562

25392563
plugin.teardown = function()
25402564
{
2541-
this.helpButton.off('click');
2565+
if (null === this.helpButton)
2566+
{
2567+
return;
2568+
}
2569+
2570+
this.helpButton.removeEventListener('click', this.helpButtonClick);
25422571
delete this.helpButton;
25432572
delete this._helpEnabled;
25442573
};
@@ -2562,19 +2591,12 @@
25622591
*/
25632592
this.pauseButton = document.querySelectorAll(this.options.pauseButton);
25642593

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);
25712595

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));
25782600

25792601
/**
25802602
* If the application is currently paused manually
@@ -2686,7 +2708,7 @@
26862708

26872709
plugin.close = function()
26882710
{
2689-
this._disableButton(this.pauseButton);
2711+
this.pauseButton.forEach(this._disableButton.bind(this));
26902712
this.paused = false;
26912713
};
26922714

@@ -2695,7 +2717,7 @@
26952717
this.pauseButton.forEach(
26962718
function(element)
26972719
{
2698-
element.removeEventListener('click', onPauseToggle.bind(this));
2720+
element.removeEventListener('click', this.onPauseToggle);
26992721
}.bind(this)
27002722
);
27012723
delete this.pauseButton;
@@ -2844,53 +2866,43 @@
28442866
* @property {HTMLElement} soundButton
28452867
*/
28462868
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-
}
28552869

28562870
/**
28572871
* Reference to the music mute button
28582872
* @property {HTMLElement} musicButton
28592873
*/
28602874
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-
}
28692875

28702876
/**
28712877
* Reference to the sound effects mute button
28722878
* @property {HTMLElement} sfxButton
28732879
*/
28742880
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-
}
28812881

28822882
/**
28832883
* Reference to the voice-over mute button
28842884
* @property {HTMLElement} voButton
28852885
*/
28862886
this.voButton = document.querySelector(this.options.voButton);
2887-
this.voButton.addEventListener('click', onVOToggle.bind(this));
28882887

2889-
if (null === this.voButton)
2888+
if (null !== this.soundButton)
28902889
{
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));
28942906
}
28952907

28962908
/**
@@ -2985,15 +2997,30 @@
29852997
'features',
29862998
function(features)
29872999
{
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+
}
29923014

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';
29973024
}.bind(this)
29983025
);
29993026
};
@@ -3049,10 +3076,25 @@
30493076

30503077
plugin.opened = function()
30513078
{
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+
}
30563098

30573099
this.soundMuted = !!SavedData.read(SOUND_MUTED);
30583100
this.musicMuted = !!SavedData.read(MUSIC_MUTED);
@@ -3070,10 +3112,26 @@
30703112

30713113
plugin.teardown = function()
30723114
{
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+
30773135
delete this.voButton;
30783136
delete this.sfxButton;
30793137
delete this.musicButton;

dist/container.min.js

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)