Skip to content

Commit

Permalink
Drop jslider dependency
Browse files Browse the repository at this point in the history
jslider was incredibly buggy, and most likely the cause of the problems
with the teambuilder on mobile, and required some pretty ridiculous
hacks, and leaked memory.

We're now using HTML5 sliders, like we are with the volume controls.

HTML5 sliders aren't supported by IE9, but they're supported by most
other browsers PS cares about. If not, well, they won't look too ugly
probably...
  • Loading branch information
Zarel committed Dec 21, 2017
1 parent 31722b1 commit 5120e59
Show file tree
Hide file tree
Showing 9 changed files with 9 additions and 40 deletions.
3 changes: 0 additions & 3 deletions index.template.html
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@
<link rel="stylesheet" href="//play.pokemonshowdown.com/style/battle.css?" />
<link rel="stylesheet" href="//play.pokemonshowdown.com/style/utilichart.css?" />
<link rel="stylesheet" href="//play.pokemonshowdown.com/style/font-awesome.css?" />
<link rel="stylesheet" href="//play.pokemonshowdown.com/style/jquery.slider.min.css?" />
<meta name="apple-mobile-web-app-capable" content="yes" />
<link rel="manifest" href="/manifest.json" />
<meta name="google-signin-client_id" content="912270888098-jjnre816lsuhc5clj3vbcn4o2q7p4qvk.apps.googleusercontent.com">
Expand Down Expand Up @@ -145,8 +144,6 @@ <h3><button class="closebutton" tabindex="-1"><i class="fa fa-times-circle"></i>
var app = new App();
</script>

<script src="//play.pokemonshowdown.com/js/lib/jquery.slider.min.js?"></script>

<script src="//play.pokemonshowdown.com/data/pokedex.js?"></script>
<script src="//play.pokemonshowdown.com/data/moves.js?"></script>
<script src="//play.pokemonshowdown.com/data/items.js?"></script>
Expand Down
39 changes: 9 additions & 30 deletions js/client-teambuilder.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@
'input .statform input[type=number].numform': 'statChange',
'change select[name=nature]': 'natureChange',
'change select[name=ivspread]': 'ivSpreadChange',
'change .evslider': 'statSlide',
'input .evslider': 'statSlide',

// teambuilder events
'click .utilichart a': 'chartClick',
Expand Down Expand Up @@ -83,7 +85,6 @@
}
this.exportMode = false;
} else if (this.curSet) {
app.clearGlobalListeners();
this.curSet = null;
Storage.saveTeam(this.curTeam);
} else if (this.curTeam) {
Expand Down Expand Up @@ -1631,7 +1632,6 @@
},
updateChart: function (pokemonChanged, wasIncomplete) {
var type = this.curChartType;
app.clearGlobalListeners();
if (type === 'stats') {
this.search.qType = null;
this.search.qName = null;
Expand Down Expand Up @@ -1906,7 +1906,7 @@
buf += '<div class="col evslidercol"><div></div>';
for (var i in stats) {
if (i === 'spd' && this.curTeam.gen === 1) continue;
buf += '<div><input type="slider" name="evslider-' + i + '" value="' + Tools.escapeHTML(set.evs[i] === undefined ? (this.curTeam.gen > 2 ? '0' : '252') : '' + set.evs[i]) + '" min="0" max="252" step="4" class="evslider" /></div>';
buf += '<div><input type="range" name="evslider-' + i + '" value="' + Tools.escapeHTML(set.evs[i] === undefined ? (this.curTeam.gen > 2 ? '0' : '252') : '' + set.evs[i]) + '" min="0" max="252" step="4" class="evslider" tabindex="-1" aria-hidden="true" /></div>';
}
buf += '</div>';

Expand Down Expand Up @@ -2064,30 +2064,12 @@

buf += '</div>';
this.$chart.html(buf);
var self = this;
this.suppressSliderCallback = true;
app.clearGlobalListeners();
this.$chart.find('.evslider').slider({
from: 0,
to: 252,
step: 4,
skin: 'round_plastic',
onstatechange: function (val) {
if (!self.suppressSliderCallback) self.statSlide(val, this);
},
callback: function () {
self.save();
}
});
this.suppressSliderCallback = false;
},
setStatFormGuesses: function () {
this.updateStatForm(true);
},
setSlider: function (stat, val) {
this.suppressSliderCallback = true;
this.$chart.find('input[name=evslider-' + stat + ']').slider('value', val || 0);
this.suppressSliderCallback = false;
this.$chart.find('input[name=evslider-' + stat + ']').val(val || 0);
},
updateNature: function () {
var set = this.curSet;
Expand Down Expand Up @@ -2218,11 +2200,12 @@
}
}
},
statSlide: function (val, slider) {
var stat = slider.inputNode[0].name.substr(9);
statSlide: function (e) {
var slider = e.currentTarget;
var stat = slider.name.substr(9);
var set = this.curSet;
if (!set) return;
val = +val;
var val = +slider.value;
var originalVal = val;
var result = this.getStat(stat, set, val);
while (val && this.getStat(stat, set, val - 4) == result) val -= 4;
Expand All @@ -2245,7 +2228,7 @@

// Don't try this at home.
// I am a trained professional.
if (val !== originalVal) slider.o.pointers[0].set(val);
if (val !== originalVal) slider.value = val;

if (!set.evs) set.evs = {};
if (this.ignoreEVLimits) {
Expand Down Expand Up @@ -3360,10 +3343,6 @@
if (!format) return 7;
if (format.substr(0, 3) !== 'gen') return 6;
return parseInt(format.substr(3, 1), 10) || 6;
},
destroy: function () {
app.clearGlobalListeners();
Room.prototype.destroy.call(this);
}
});

Expand Down
6 changes: 0 additions & 6 deletions js/lib/jquery.slider.min.js

This file was deleted.

1 change: 0 additions & 1 deletion style/jquery.slider.min.css

This file was deleted.

Binary file removed style/slider/jslider.blue.png
Binary file not shown.
Binary file removed style/slider/jslider.plastic.png
Binary file not shown.
Binary file removed style/slider/jslider.png
Binary file not shown.
Binary file removed style/slider/jslider.round.plastic.png
Binary file not shown.
Binary file removed style/slider/jslider.round.png
Binary file not shown.

0 comments on commit 5120e59

Please sign in to comment.