function quiz_set_auto_title() is a mess. It does nothing but adding an inline js script which need to be moved to its own js file.
function quiz_set_auto_title() {
$max_length = variable_get('quiz_autotitle_length', 50);
drupal_add_js('
$(document).ready(function () {
function quizStripTags(str) {
return str.replace(/<\/?[^>]+>/gi, \'\');
}
function quizUpdateTitle() {
if (quizStripTags($("#edit-body").val()).length > '. $max_length .') {
$("#edit-title").val(quizStripTags($("#edit-body").val()).substring(0, '. $max_length .' - 3) + "...");
}
else {
$("#edit-title").val(quizStripTags($("#edit-body").val()).substring(0, '. $max_length .'));
}
}
$("#edit-body").keyup(quizUpdateTitle);
// Do not use auto title if a title already has been set
if($("#edit-title").val().length > 0){
$("#edit-body").unbind("keyup", quizUpdateTitle);
}
$("#edit-title").keyup(function() {
$("#edit-body").unbind("keyup", quizUpdateTitle);
});
});
', 'inline');
}
Comments
Comment #1
sokrplare commentedAgreed. The tricky part is getting that $max_length variable stored someplace the standalone JS file can get to it.
@sivaji - patch forthcoming I hope?
Comment #2
sokrplare commentedComponents have changed since this issue was created, switching to correct one.
Comment #3
djdevin