Permalink
Browse files

[Fix bug 766924] Whitelist element IDs.

- Only allow whitelisted element IDs in the hash on /feedback.
- Fix a bunch of trailing whitespace issues.
  • Loading branch information...
1 parent e29a35c commit aaf99da89662de6723ada5375cfed2bb55f64298 James Socol committed Jun 21, 2012
Showing with 27 additions and 22 deletions.
  1. +27 −22 media/js/feedback.js
View
@@ -6,12 +6,12 @@
for ( ; node; i++, node = node.previousSibling);
return i;
},
-
+
switchTo: function(what, callback) {
var fromElem = this,
toElem = $(what),
width = $(window).width();
-
+
if (fromElem.nodeIndex() < toElem.nodeIndex()) {
var fromEnd = -width;
var toStart = width;
@@ -24,81 +24,86 @@
toElem.addClass('entering')
.css({ left: toStart, right: -toStart, display: 'block' });
$('html').addClass('transitioning');
-
+
toElem.one('transitionend', function(e) {
fromElem.css({ display: 'none' });
toElem.removeClass('entering');
$('html').removeClass('transitioning');
if (callback) callback();
});
-
+
setTimeout(function() {
fromElem.css({ left: fromEnd, right: -fromEnd });
toElem.css({ left: 0, right: 0 });
}, 100);
-
+
return this;
},
submitButton: function(state) {
var textElem = this.find('span');
var oldHTML = textElem.html();
var newTextAttr = (state == 'waiting') ? 'data-waittext' : 'data-text';
-
+
this.toggleClass('waiting', state == 'waiting');
textElem.html( this.attr(newTextAttr) );
-
+
if (state == 'waiting') this.attr('data-text', oldHTML);
-
+
return this;
},
clickEnable: function(bindTo) {
return this.each(function() {
onClick.call(this);
$(this).click(onClick);
});
-
+
function onClick() {
var checked = this.checked;
$(bindTo)[0].disabled = !checked;
}
}
});
-
+
var currentArticle;
-
+
function countRemaining(inputElement) {
var counter = $('#' + $(inputElement).attr('id') + '-counter'),
max = $(inputElement).attr('data-max-length'),
remaining = max - $(inputElement).val().length;
-
+
$(counter).text(remaining);
$(counter).toggleClass('no-characters-remaining', remaining < 0);
$(counter).toggleClass('limited-characters-remaining', remaining <= Math.round(max * 0.2));
$('#' + $(inputElement).attr('id').replace(/-description/, '') + '-submit a').toggleClass('disabled', (max == remaining || remaining < 0));
}
-
+
function getArticle(href) {
- var hash = (href || '').replace(/^.*#/, '') || 'intro';
+ var hash = (href || '').replace(/^.*#/, '') || 'intro',
+ validhashes = ['intro', 'happy', 'sad', 'idea'];
+ // If passed an invalid hash, go to the intro.
+ if (-1 === validhashes.indexOf(hash.toLowerCase())) {
+ hash = 'intro';
+ }
var elem = $('#'+hash);
return elem.length ? elem : $('#intro');
}
-
+
function goToArticle(href, pushState, callback)
{
var oldArticle = currentArticle;
var newArticle = getArticle(href);
-
+
if (oldArticle.get(0) == newArticle.get(0)) {
return;
}
if (pushState) window.history.pushState('', '', '#' + newArticle.attr('id'));
currentArticle = newArticle;
-
+
oldArticle.switchTo(newArticle, callback);
}
-
+
$(function() {
// Look for errors and show that initially
var errorlst = $('article .errorlist');
@@ -115,20 +120,20 @@
window.onpopstate = function(e) {
goToArticle(document.location.hash);
};
-
+
$('.submit a').click(function(e) {
if ($(this).hasClass('disabled') === false) {
$(this).closest('form').submit();
}
-
+
return false;
});
-
+
$('article form').submit(function(e) {
var button = $(this).find('.submit a');
button.submitButton('waiting');
});
-
+
$('article textarea').each(function(i, element) {
countRemaining(element);
});

0 comments on commit aaf99da

Please sign in to comment.