You are here

function quiz_set_auto_title in Quiz 6.4

Same name and namespace in other branches
  1. 8.6 quiz.admin.inc \quiz_set_auto_title()
  2. 8.4 quiz.admin.inc \quiz_set_auto_title()
  3. 8.5 quiz.admin.inc \quiz_set_auto_title()
  4. 6.6 quiz.admin.inc \quiz_set_auto_title()
  5. 6.5 quiz.admin.inc \quiz_set_auto_title()
  6. 7.6 quiz.admin.inc \quiz_set_auto_title()
  7. 7 quiz.admin.inc \quiz_set_auto_title()
  8. 7.4 quiz.admin.inc \quiz_set_auto_title()
  9. 7.5 quiz.admin.inc \quiz_set_auto_title()
  10. 6.x quiz.admin.inc \quiz_set_auto_title()
1 call to quiz_set_auto_title()
theme_quiz_question_creation_form in question_types/quiz_question/quiz_question.theme.inc
Theme the question creation form

File

./quiz.admin.inc, line 2602
Administrator interface for Quiz module.

Code

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');
}