github.com/feiyang21687/docker@v1.5.0/docs/theme/mkdocs/js/dockerfile_tutorial_level.js (about)

     1  function check_form1 ()
     2  {
     3  	$('#level1_error0').hide();
     4  	$('#level1_error1').hide();
     5  	$('#level1_error2').hide();
     6  	$('#level1_error3').hide();
     7  	
     8  	$('#no_good').hide();	
     9  	$('#some_good').hide();		
    10  	$('#all_good').hide();
    11  
    12  	var a = clean_input($('#level1_q0').val()).toUpperCase();
    13  	var b = clean_input($('#level1_q1').val()).toUpperCase();
    14  	var c = clean_input($('#level1_q2').val()).toUpperCase();
    15  	var d = clean_input($('#level1_q3').val());
    16  	var points = 0;
    17  	
    18  	if (a == 'FROM'){
    19  		points = points + 1;
    20  	} else {
    21  		$('#level1_error0').show();
    22  	}
    23  	if (b == 'RUN') {
    24  		points = points + 1;
    25  	} else {
    26  		$('#level1_error1').show();
    27  	}
    28  	if (c == 'MAINTAINER') {
    29  		points = points + 1;
    30  	} else {
    31  		$('#level1_error2').show();
    32  	}
    33  	if (d == '#') {
    34  		points = points + 1;
    35  	} else {
    36  		$('#level1_error3').show();
    37  	}
    38  	if (points == 4) {// all good
    39  		$('#all_good').show();
    40  	} else if (points == 0) { // nothing good
    41  		$('#no_good').show();	
    42  	} else {// some good some bad
    43  		$('#some_good').show();
    44  	}
    45  	return (4 - points);
    46  }
    47  
    48  function check_form2 ()
    49  {
    50      $('.level_questions .alert').hide();
    51  
    52      var answers = {};
    53      answers[0] = ['FROM'];
    54      answers[1] = ['ENTRYPOINT', 'CMD'];
    55      answers[2] = ['#'];
    56      answers[3] = ['USER'];
    57      answers[4] = ['RUN'];
    58      answers[5] = ['EXPOSE'];
    59      answers[6] = ['MAINTAINER'];
    60      answers[7] = ['ENTRYPOINT', 'CMD'];
    61  
    62  	var points = 0;
    63  
    64      $.each($(".level"), function(num, input){
    65          var cleaned = clean_up(input.value);
    66          if ($.inArray(cleaned, answers[num]) == -1) {
    67              $( $(".level_error")[num]).show()
    68              $(input).addClass("error_input");
    69          } else {
    70              $( $(".level_error")[num]).hide()
    71              $(input).removeClass("error_input");
    72              points += 1;
    73          }
    74      })
    75  	if (points == 8) // all good
    76  	{
    77  		$('#all_good').show();
    78  	}
    79  	else if (points == 0) // nothing good
    80  	{
    81  		$('#no_good').show();
    82  	}
    83  	else // some good some bad
    84  	{
    85  		$('#some_good').show();
    86  	}
    87  	return (8- points);
    88  }
    89  
    90  function check_fill(answers)
    91  {
    92  	$('#dockerfile_ok').hide();
    93  	$('#dockerfile_ko').hide();
    94  
    95  	var errors = 0;
    96  
    97      $.each($(".l_fill"), function(num, input){
    98          var cleaned = clean_up(input.value);
    99          var id = input.id;
   100          if (answers[id] != cleaned) {
   101              $(input).addClass("error_input");
   102              errors += 1;
   103          } else {
   104              $(input).removeClass("error_input");
   105          }
   106      });
   107  
   108  	if (errors != 0)
   109  	{
   110  		$('#dockerfile_ko').show();
   111  	}
   112  	else
   113  	{
   114  		$('#dockerfile_ok').show();
   115  	}
   116  	return (errors);
   117  }
   118  
   119  $(document).ready(function() {
   120  
   121      $("#check_level1_questions").click( function(){
   122          errors = check_form1();
   123          dockerfile_log(1, '1_questions', errors);
   124         }
   125      );
   126  
   127      $("#check_level1_fill").click( function(){
   128          var answers = {};
   129          answers['from'] = 'FROM';
   130          answers['ubuntu'] = 'UNTU';
   131          answers['maintainer'] = 'MAINTAINER';
   132          answers['eric'] = 'RIC';
   133          answers['bardin'] = 'ARDIN';
   134          answers['run0'] = 'RUN';
   135          answers['run1'] = 'RUN';
   136          answers['run2'] = 'RUN';
   137          answers['memcached'] = 'MEMCACHED';
   138  
   139          var errors = check_fill(answers);
   140          dockerfile_log(1, '2_fill', errors);
   141      });
   142  
   143      $("#check_level2_questions").click( function(){
   144          errors = check_form2();
   145          dockerfile_log(2, '1_questions', errors);
   146         }
   147      );
   148  
   149      $("#check_level2_fill").click( function(){
   150          var answers = {};
   151          answers['from'] = "FROM";
   152          answers['ubuntu'] = "UNTU";
   153          answers['maintainer'] = "AINER";
   154          answers['roberto'] = "BERTO";
   155          answers['hashioka'] = "SHIOKA";
   156          answers['run0'] = "RUN";
   157          answers['run1'] = "RUN";
   158          answers['run2'] = "RUN";
   159          answers['run3'] = "RUN";
   160          answers['run4'] = "RUN";
   161          answers['run5'] = "RUN";
   162          answers['run6'] = "RUN";
   163          answers['entrypoint'] = "ENTRYPOINT";
   164          answers['user'] = "USER";
   165          answers['expose'] = "EXPOSE";
   166          answers['gcc'] = "GCC";
   167  
   168          var errors = check_fill(answers);
   169          dockerfile_log(2, '2_fill', errors);
   170      });
   171  
   172      $(".btn.btn-primary.back").click( function(event){
   173          event.preventDefault();
   174          window.history.back();
   175      })
   176  });