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

sokrplare’s picture

Component: Code - Quiz module » Code - Import/Export

Agreed. The tricky part is getting that $max_length variable stored someplace the standalone JS file can get to it.

@sivaji - patch forthcoming I hope?

sokrplare’s picture

Component: Code - Import/Export » Code - Quiz core

Components have changed since this issue was created, switching to correct one.

djdevin’s picture

Issue summary: View changes
Status: Active » Closed (outdated)