Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Fixing scrolling bugs

  • Loading branch information...
commit 16243399699ccf8899908d97c17ba8aba1b8692a 1 parent e0bcf4b
@mikeymckay authored
View
34 _attachments/app/views/QuestionView.coffee
@@ -199,21 +199,25 @@ class QuestionView extends Backbone.View
# Update the menu
Coconut.menuView.update()
+ @save()
+ @updateSkipLogic()
+ @actionOnChange(event)
else
@changedComplete = false
messageVisible = window.questionCache[targetName].find(".message").is(":visible")
- unless messageVisible
- wasValid = @validateOne
- key: targetName
- autoscroll: false
- button: "<button type='button' data-name='#{targetName}' class='validate_one'>Validate</button>"
-
- @save()
-
- @updateSkipLogic()
- @actionOnChange(event)
+# Hack by Mike to solve problem with autocomplete fields being validated before
+ _.delay =>
+ unless messageVisible
+ wasValid = @validateOne
+ key: targetName
+ autoscroll: false
+ button: "<button type='button' data-name='#{targetName}' class='validate_one'>Validate</button>"
+ @save()
+ @updateSkipLogic()
+ @actionOnChange(event)
+ @autoscroll(event) if wasValid
+ , 500
- @autoscroll(event) if wasValid and not messageVisible
onValidateOne: (event) ->
$target = $(event.target)
@@ -331,13 +335,14 @@ class QuestionView extends Backbone.View
clearTimeout @autoscrollTimer
+ # Some hacks in here to try and make it work
if event.jquery
$div = event
- name = $div.attr("data-question-name")
+ window.scrollTargetName = $div.attr("data-question-name") || $div.attr("name")
else
$target = $(event.target)
- name = $target.attr("name")
- $div = window.questionCache[name]
+ window.scrollTargetName = $target.attr("name")
+ $div = window.questionCache[window.scrollTargetName]
@$next = $div.next()
@@ -347,6 +352,7 @@ class QuestionView extends Backbone.View
@$next = @$next.next()
if @$next.is(":visible")
+ return if window.questionCache[window.scrollTargetName].find(".message").is(":visible")
$(window).on( "scroll", => $(window).off("scroll"); clearTimeout @autoscrollTimer; )
@autoscrollTimer = setTimeout(
=>
View
47 _attachments/app/views/QuestionView.js
@@ -146,7 +146,8 @@ QuestionView = (function(_super) {
};
QuestionView.prototype.onChange = function(event) {
- var $target, eventStamp, messageVisible, targetName, wasValid;
+ var $target, eventStamp, messageVisible, targetName,
+ _this = this;
$target = $(event.target);
eventStamp = $target.attr("id");
@@ -163,22 +164,29 @@ QuestionView = (function(_super) {
}
this.validateAll();
Coconut.menuView.update();
+ this.save();
+ this.updateSkipLogic();
+ return this.actionOnChange(event);
} else {
this.changedComplete = false;
messageVisible = window.questionCache[targetName].find(".message").is(":visible");
- if (!messageVisible) {
- wasValid = this.validateOne({
- key: targetName,
- autoscroll: false,
- button: "<button type='button' data-name='" + targetName + "' class='validate_one'>Validate</button>"
- });
- }
- }
- this.save();
- this.updateSkipLogic();
- this.actionOnChange(event);
- if (wasValid && !messageVisible) {
- return this.autoscroll(event);
+ return _.delay(function() {
+ var wasValid;
+
+ if (!messageVisible) {
+ wasValid = _this.validateOne({
+ key: targetName,
+ autoscroll: false,
+ button: "<button type='button' data-name='" + targetName + "' class='validate_one'>Validate</button>"
+ });
+ _this.save();
+ _this.updateSkipLogic();
+ _this.actionOnChange(event);
+ if (wasValid) {
+ return _this.autoscroll(event);
+ }
+ }
+ }, 500);
}
};
@@ -305,17 +313,17 @@ QuestionView = (function(_super) {
};
QuestionView.prototype.autoscroll = function(event) {
- var $div, $target, name, safetyCounter,
+ var $div, $target, safetyCounter,
_this = this;
clearTimeout(this.autoscrollTimer);
if (event.jquery) {
$div = event;
- name = $div.attr("data-question-name");
+ window.scrollTargetName = $div.attr("data-question-name") || $div.attr("name");
} else {
$target = $(event.target);
- name = $target.attr("name");
- $div = window.questionCache[name];
+ window.scrollTargetName = $target.attr("name");
+ $div = window.questionCache[window.scrollTargetName];
}
this.$next = $div.next();
if (!this.$next.is(":visible") && this.$next.length > 0) {
@@ -325,6 +333,9 @@ QuestionView = (function(_super) {
}
}
if (this.$next.is(":visible")) {
+ if (window.questionCache[window.scrollTargetName].find(".message").is(":visible")) {
+ return;
+ }
$(window).on("scroll", function() {
$(window).off("scroll");
return clearTimeout(_this.autoscrollTimer);
View
2  _attachments/index.html
@@ -33,7 +33,7 @@
<script type="text/javascript" src="js-libraries/jquery-1.7.2.min.js"></script>
-->
<script type="text/javascript" src="js-libraries/jquery-2.1.0.min.js"></script>
- <script type="text/javascript" src="js-libraries/jquery-migrate-1.2.1.js"></script>
+ <script type="text/javascript" src="js-libraries/jquery-migrate-1.2.1.min.js"></script>
<script type="text/javascript" src="js-libraries/underscore-min.js"></script>
<script type="text/javascript" src="js-libraries/backbone-min.js"></script>
<script type="text/javascript" src="js-libraries/jquery.couch.js"></script>
View
2  _docs/version.json
@@ -1 +1 @@
-{"version":"ae97a66","isApplicationDoc":true}
+{"version":"e0bcf4b","isApplicationDoc":true}
Please sign in to comment.
Something went wrong with that request. Please try again.