<commit_before><!--
Array-Based Stacks Pop Proficiency Exercise.
Written by <NAME> and <NAME>
-->

<!DOCTYPE html>
<html data-require="math">
<head>
  <title>Array-Based Stacks Pop Proficiency Exercise</title>
  <script src="../../lib/jquery.min.js"></script>
  <script src="../../lib/jquery-ui.min.js"></script>
  <script src="../../JSAV/lib/jquery.transform.light.js"></script>
  <script src="../../JSAV/lib/raphael.js"></script>
  <script src="../../ODSAkhan-exercises/khan-exercise.js"></script>
  <script src="../../JSAV/build/JSAV.js"></script>
  <link rel="stylesheet" href="../../JSAV/css/JSAV.css" type="text/css" />

  <style>
    .jsavcontainer {
	  height: 150px;
      border: 0px;
    }
	.jsavcanvas{
	  height: 150px;
	}
	.jsavnode {
      line-height: 30px !important;
      min-width: 30px !important;
      max-width: 30px !important;
      min-height: 30px !important;
      max-height: 30px !important;
    }
    .jsavpointer{
      width: 40px;
      border: 1px solid #bbb;
      text-align: center;
	  cursor: pointer;
    }
    #reset { margin-right: 20px;}
    .highlight{
      background-color: yellow;
    }
  </style>
</head>
<body>

<script>
var jsav,           // The JSAV object
  answerArr = [],   // The (internal) array that stores the correct answer
  cloneArr = [],    // A copy of the (internal) array at the start of the exercise for reset
  returnVal,
  jsavArr,          // The array that the user manipulates (JSAV object)
  arrReturn,
  labelReturn,
  selected_pointer,
  pointerIndex,     // The index of array by which the pointer points to.
  pointerTop,       // 'top' pointer
  status,
  userInput,        // Boolean: Tells us if user ever did anything
  selected_index;   // Position that has been selected by user for swap

JSAV._types.Pointer.prototype.click = function(fn){
  var pointer = this;
  this.element.click(function(){fn(pointer)});
}
// pointer click handler
function pclick(pointer){
  if(status == 1){
    jsavArr.css(selected_index, {"font-size": "100%"});
    jsavArr.unhighlight(selected_index);
    selected_pointer = pointer;
    selected_pointer.element.toggleClass('highlight');
    status = 2;
  }else if(status == 2){
    selected_pointer.element.removeClass('highlight');
	status = 0;
  }else{
    selected_pointer = pointer;
    selected_pointer.element.toggleClass('highlight');
    status = 2;
  }
  userInput = true;
}

// Click event handler on the array 'jsavArr'
function clickHandler(index, e) {
  if (status == 0) { // if nothing currently selected
    jsavArr.css(index, {"font-size": "110%"});
	selected_index = index;
	jsavArr.highlight(index);
    status = 1;
  } else if(status == 1) {	
	jsavArr.css(index, {"font-size": "110%"});
	jsavArr.highlight(index);
	jsavArr.css(selected_index, {"font-size": "100%"});
	jsavArr.unhighlight(selected_index);
	selected_index = index;  // Reset to nothing selected
  } else if (status == 2){
    selected_pointer.target(jsavArr, {relativeIndex : index,targetIndex : index});
    jsav.container.trigger("jsav-updaterelative");
    selected_pointer.element.removeClass('highlight');
    pointerIndex = index;
    status = 0;
  }
  userInput = true;
};

// Click event handler on the array 'returnArr'
function copyHandler(index, e) {
  if(selected_index !== -1){
      jsav.effects.moveValue(jsavArr, selected_index, this, 0);
      jsavArr.css(selected_index, { "background-color": "#ddd" });
      jsavArr.css(selected_index, {"font-size": "100%"});
      jsavArr.unhighlight(selected_index);
      selected_index = -1;
      status = 0;
      userInput = true;
  } 

}


// reset function definition
function f_reset(max_size, arr_size) {
  selected_index = -1;
  status = 0; 

  if($("#jsav")){
    $("#jsav").empty();
  }
  jsav = new JSAV("jsav");	
  jsav.SPEED = 80;
  jsavArr = jsav.ds.array(cloneArr, {indexed: true, center: false, top : 50});
  arrReturn = jsav.ds.array([""], {left:31 * arr_size - ((arr_size>0)?31:0), top : 120});
  labelReturn = jsav.label("return", {left:arrReturn.element.position().left - 45, top : 125});

  pointerTop = jsav.pointer("top", jsavArr, {
                              targetIndex : arr_size
                            });
  pointerIndex = arr_size;

  pointerTop.click(pclick);
  jsav.recorded();
  jsav.forward();
  // Bind the clickHandler to handle click events on the array
  jsavArr.click(clickHandler);
  arrReturn.click(copyHandler);
  userInput = false;
};

// Initialise the exercise
function initJSAV(max_size, arr_size, insertValue) {
  var i, j;
  userInput = false;
  selected_index = -1;
  insertEnable = false;
  status = 0; 
  answerArr.length = 0; // Out with the old

  // Give random numbers in range 0..999
  for (i = 0; i < arr_size; i++) {
    answerArr[i] = Math.floor(Math.random() * 1000);
  }
  for(i = 0; i < max_size - arr_size; i++)
  {
    answerArr.push.apply(answerArr, [""]);<commit_msg>Fixed pointer position in listAStackPop exercise.<commit_after><!--
Array-Based Stacks Pop Proficiency Exercise.
Written by <NAME> and <NAME>
-->

<!DOCTYPE html>
<html data-require="math">
<head>
  <title>Array-Based Stacks Pop Proficiency Exercise</title>
  <script src="../../lib/jquery.min.js"></script>
  <script src="../../lib/jquery-ui.min.js"></script>
  <script src="../../JSAV/lib/jquery.transform.light.js"></script>
  <script src="../../JSAV/lib/raphael.js"></script>
  <script src="../../ODSAkhan-exercises/khan-exercise.js"></script>
  <script src="../../JSAV/build/JSAV.js"></script>
  <link rel="stylesheet" href="../../JSAV/css/JSAV.css" type="text/css" />

  <style>
    .jsavcontainer {
	  height: 150px;
      border: 0px;
    }
	.jsavcanvas{
	  height: 150px;
	}
	.jsavnode {
      line-height: 30px !important;
      min-width: 30px !important;
      max-width: 30px !important;
      min-height: 30px !important;
      max-height: 30px !important;
    }
    .jsavpointer{
      width: 40px;
      border: 1px solid #bbb;
      text-align: center;
	  cursor: pointer;
    }
    #reset { margin-right: 20px;}
    .highlight{
      background-color: yellow;
    }
  </style>
</head>
<body>

<script>
var jsav,           // The JSAV object
  answerArr = [],   // The (internal) array that stores the correct answer
  cloneArr = [],    // A copy of the (internal) array at the start of the exercise for reset
  returnVal,
  jsavArr,          // The array that the user manipulates (JSAV object)
  arrReturn,
  labelReturn,
  selected_pointer,
  pointerIndex,     // The index of array by which the pointer points to.
  pointerTop,       // 'top' pointer
  status,
  userInput,        // Boolean: Tells us if user ever did anything
  selected_index;   // Position that has been selected by user for swap

JSAV._types.Pointer.prototype.click = function(fn){
  var pointer = this;
  this.element.click(function(){fn(pointer)});
}
// pointer click handler
function pclick(pointer){
  if(status == 1){
    jsavArr.css(selected_index, {"font-size": "100%"});
    jsavArr.unhighlight(selected_index);
    selected_pointer = pointer;
    selected_pointer.element.toggleClass('highlight');
    status = 2;
  }else if(status == 2){
    selected_pointer.element.removeClass('highlight');
	status = 0;
  }else{
    selected_pointer = pointer;
    selected_pointer.element.toggleClass('highlight');
    status = 2;
  }
  userInput = true;
}

// Click event handler on the array 'jsavArr'
function clickHandler(index, e) {
  if (status == 0) { // if nothing currently selected
    jsavArr.css(index, {"font-size": "110%"});
	selected_index = index;
	jsavArr.highlight(index);
    status = 1;
  } else if(status == 1) {	
	jsavArr.css(index, {"font-size": "110%"});
	jsavArr.highlight(index);
	jsavArr.css(selected_index, {"font-size": "100%"});
	jsavArr.unhighlight(selected_index);
	selected_index = index;  // Reset to nothing selected
  } else if (status == 2){
    selected_pointer.target(jsavArr, {targetIndex : index});
    jsav.container.trigger("jsav-updaterelative");
    selected_pointer.element.removeClass('highlight');
    pointerIndex = index;
    status = 0;
  }
  userInput = true;
};

// Click event handler on the array 'returnArr'
function copyHandler(index, e) {
  if(selected_index !== -1){
      jsav.effects.moveValue(jsavArr, selected_index, this, 0);
      jsavArr.css(selected_index, { "background-color": "#ddd" });
      jsavArr.css(selected_index, {"font-size": "100%"});
      jsavArr.unhighlight(selected_index);
      selected_index = -1;
      status = 0;
      userInput = true;
  } 

}


// reset function definition
function f_reset(max_size, arr_size) {
  selected_index = -1;
  status = 0; 

  if($("#jsav")){
    $("#jsav").empty();
  }
  jsav = new JSAV("jsav");	
  jsav.SPEED = 80;
  jsavArr = jsav.ds.array(cloneArr, {indexed: true, center: false, top : 50});
  arrReturn = jsav.ds.array([""], {left:31 * arr_size - ((arr_size>0)?31:0), top : 120});
  labelReturn = jsav.label("return", {left:arrReturn.element.position().left - 45, top : 125});

  pointerTop = jsav.pointer("top", jsavArr, {
                              targetIndex : arr_size
                            });
  pointerIndex = arr_size;

  pointerTop.click(pclick);
  jsav.displayInit();
  jsav.recorded();
  jsav.forward();
  // Bind the clickHandler to handle click events on the array
  jsavArr.click(clickHandler);
  arrReturn.click(copyHandler);
  userInput = false;
};

// Initialise the exercise
function initJSAV(max_size, arr_size, insertValue) {
  var i, j;
  userInput = false;
  selected_index = -1;
  insertEnable = false;
  status = 0; 
  answerArr.length = 0; // Out with the old

  // Give random numbers in range 0..999
  for (i = 0; i < arr_size; i++) {
    answerArr[i] = Math.floor(Math.random() * 1000);
  }
  for(i = 0; i < max_size - arr_size; i++)
  {
    answerArr.push.apply(answerArr, [""]);
{'fraction_non_alphanumeric': 0.15581111337268472, 'fraction_numerical': 0.017097496438021574, 'mean_word_length': 3.1342027766091713, 'pattern_counts': {'":': 12, '<': 59, '<?xml version=': 0, '>': 57, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2993391', 'n_tokens_mistral': 3466, 'n_tokens_neox': 3255, 'n_words': 785}