questionable js cleanup
This commit is contained in:
parent
2cc94ba296
commit
cb6f41fe29
@ -1,18 +0,0 @@
|
||||
$(function(){
|
||||
|
||||
$("form").on('click', "[data-id=input_option_adder]", function(){
|
||||
var $newLi = $(this).siblings('li').clone();
|
||||
$newLi.attr('style', '');
|
||||
$("[data-id=input_option_list]").append($newLi);
|
||||
$newLi.find('input').focus();
|
||||
});
|
||||
|
||||
$("#question_input_type").on('change', function(){
|
||||
var qid = $(this).attr('data-qid') === undefined ? '' : "/" + $(this).attr('data-qid');
|
||||
// /admin/question(/:question_id)/options/:input_type
|
||||
$("[data-id=input-options-wrapper]").load("/admin/question" + qid + "/options/" + $(this).val(), function(){
|
||||
$(".code-input textarea").linedtextarea();
|
||||
});
|
||||
});
|
||||
|
||||
});
|
@ -14,6 +14,3 @@
|
||||
//= require jquery_ujs
|
||||
//= require turbolinks
|
||||
//= require modernizr-lite/modernizr
|
||||
|
||||
//= require main/ajax-links
|
||||
//= require main/textarea-limit
|
||||
|
@ -1,13 +0,0 @@
|
||||
// Action Cable provides the framework to deal with WebSockets in Rails.
|
||||
// You can generate new channels where WebSocket features live using the rails generate channel command.
|
||||
//
|
||||
//= require action_cable
|
||||
//= require_self
|
||||
//= require_tree ./channels
|
||||
|
||||
// (function() {
|
||||
// this.App || (this.App = {});
|
||||
//
|
||||
// App.cable = ActionCable.createConsumer();
|
||||
//
|
||||
// }).call(this);
|
@ -1 +0,0 @@
|
||||
//= require html5shiv/dist/html5shiv.min
|
@ -1,27 +0,0 @@
|
||||
function handleAjaxResponse($el, callback) {
|
||||
var $header = $('header');
|
||||
$el.on("ajax:success", function(e, data){
|
||||
$header.after('<div class="success">' + data.message + '</div>');
|
||||
callback(data);
|
||||
}).on("ajax:error", function(e, xhr) {
|
||||
if (xhr.status === 400){
|
||||
$header.after('<div class="error">' + xhr.responseJSON.join('<br>') + '</div>');
|
||||
} else {
|
||||
$header.after('<div class="error">Oops! There was an error processing your request. Please try again.</div>');
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
function updateVotes(data){
|
||||
$("[data-id=up-votes]").html(data.upCount);
|
||||
$("[data-id=down-votes]").html(data.downCount);
|
||||
$("[data-id=my-vote]").html(data.myVote);
|
||||
}
|
||||
|
||||
$(document).ready(function() {
|
||||
$('[data-id=ajax-action]').each(function(){ handleAjaxResponse($(this)); });
|
||||
});
|
||||
|
||||
$(document).ready(function() {
|
||||
$('[data-id=vote-count]').each(function(){ handleAjaxResponse($(this), updateVotes); });
|
||||
});
|
@ -1,25 +0,0 @@
|
||||
$.fn.extend({
|
||||
characterLimiter: function(limit, label) {
|
||||
this.on("keyup focus show", function() {
|
||||
setCount(this, label);
|
||||
});
|
||||
|
||||
// TODO: append label container after $this, instead of hard HTML
|
||||
function setCount(src, label) {
|
||||
if(src !== undefined) {
|
||||
var chars = src.value.length;
|
||||
if (chars >= limit) {
|
||||
src.value = src.value.substr(0, limit);
|
||||
chars = limit;
|
||||
}
|
||||
label.html(limit - chars);
|
||||
}
|
||||
}
|
||||
|
||||
setCount(this[0], label);
|
||||
}
|
||||
});
|
||||
|
||||
$(document).ready(function() {
|
||||
$('textarea').characterLimiter(1000, $(".chars span"));
|
||||
});
|
@ -1,95 +0,0 @@
|
||||
/* global updateResults */
|
||||
// TODO: remove global ^ once live-coder is properly name spaced
|
||||
/**
|
||||
* Summary Page Answer Editor
|
||||
*/
|
||||
function disableForm($form){
|
||||
$form.find('fieldset').prop('disabled', true);
|
||||
$form.find('textarea').prop('disabled', true);
|
||||
$form.find('.button-save, .button-cancel').hide();
|
||||
$form.find('.button-edit').show();
|
||||
$form.find('.editable').removeClass('editable');
|
||||
$('.button-edit, .submit-button').removeClass('disabled-button');
|
||||
}
|
||||
|
||||
function restoreValues($form){
|
||||
$form.find('[type=radio][data-last], [type=checkbox][data-last]').each(function(){
|
||||
$(this).prop('checked', $(this).attr('data-last'));
|
||||
});
|
||||
|
||||
$form.find('textarea[data-last]').each(function(){
|
||||
$(this).val($(this).attr('data-last'));
|
||||
});
|
||||
}
|
||||
|
||||
function updateLocalValues($form){
|
||||
$form.find('[type=radio][data-last], [type=checkbox][data-last]').each(function(){
|
||||
$(this).attr('data-last', $(this).prop('checked') ? 'checked' : '');
|
||||
});
|
||||
|
||||
$form.find('textarea[data-last]').each(function(){
|
||||
$(this).attr('data-last', $(this).val());
|
||||
});
|
||||
}
|
||||
|
||||
function updateProgress(data) {
|
||||
$(".progress-bar").attr('aria-valuenow', data.progress)
|
||||
.attr('style','width: '+ data.progress +'%;')
|
||||
.find('span').text(data.progress + '%');
|
||||
if(data.can_submit === true){
|
||||
$('#summary-submit').find('.error').remove();
|
||||
$('#summary-submit').find('.submit-button').prop('disabled', false);
|
||||
}
|
||||
}
|
||||
|
||||
function prepareAjax($form) {
|
||||
$form.on("ajax:success", function(e, data){
|
||||
$form.prepend('<div class="success">' + data.message + '</div>');
|
||||
disableForm($form);
|
||||
updateLocalValues($form);
|
||||
updateProgress(data);
|
||||
}).on("ajax:error", function(e, xhr) {
|
||||
if (xhr.status === 400){
|
||||
$form.prepend('<div class="error">' + xhr.responseJSON.join('<br>') + '</div>');
|
||||
} else {
|
||||
$form.prepend('<div class="error">Oops! There was an error processing your request. Please try again.</div>');
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
function editClickHandler(e) {
|
||||
e.preventDefault();
|
||||
$('.button-edit, .submit-button').addClass('disabled-button');
|
||||
var $form = $(e.delegateTarget).closest('form');
|
||||
$(e.delegateTarget).addClass('editable');
|
||||
$form.find('fieldset').prop('disabled', false);
|
||||
$form.find('textarea').prop('disabled', false);
|
||||
$form.find('textarea').focus();
|
||||
$form.find('.button-edit').hide().delay();
|
||||
$form.find('.button-save, .button-cancel').show().delay();
|
||||
}
|
||||
|
||||
function cancelClickHandler(e) {
|
||||
e.preventDefault();
|
||||
var $form = $(e.delegateTarget).closest('form');
|
||||
$form.find('.error, .success').remove();
|
||||
disableForm($form);
|
||||
restoreValues($form);
|
||||
updateResults($form.find("[data-id=live-coder-answer]"));
|
||||
}
|
||||
|
||||
function saveClickHandler(e) {
|
||||
e.preventDefault();
|
||||
var $form = $(e.delegateTarget).closest('form');
|
||||
$form.find('.error, .success').remove();
|
||||
$form.submit();
|
||||
}
|
||||
|
||||
$('.summary_tpl fieldset').prop('disabled', true);
|
||||
$('.summary_tpl textarea').prop('disabled', true);
|
||||
$('.summary_tpl form').each(function(){ prepareAjax($(this)); });
|
||||
$('.summary_tpl .answer-sec')
|
||||
.find('.button-cancel, .button-save').hide().end()
|
||||
.on('click', '.button-edit', editClickHandler)
|
||||
.on('click', '.button-cancel', cancelClickHandler)
|
||||
.on('click', '.button-save', saveClickHandler);
|
Loading…
Reference in New Issue
Block a user