<commit_before>$.index.open();

var NUM_COLS = 4;
var selected;

var letters = "ABCDEFGHIJKLMNOPQRSTUVWXYZ".split('');
var new_column = Ti.UI.createPickerColumn();

for(var j=0;j<NUM_COLS;j++) { // FIXME words greater than 13-14 letters drop the last picker column

	for (var i = 0; i < letters.length; i++) {
		var row = Ti.UI.createPickerRow();
		row.title = letters[i],
		new_column.addRow(row);
	}
    $.picker.add(new_column);
}

$.picker.addEventListener('change',function(e) {
	selected =  e.selectedValue.join('');
	Ti.API.info( selected );
//    Ti.API.info("You selected row: "+e.row+", column: "+e.column+", custom_item: "+e.row.custom_item);
//    label.text = "row index: "+e.rowIndex+", column index: "+e.columnIndex;
});

var xhr = Ti.Network.createHTTPClient({
    onload: function(e) {
        Ti.API.debug(this.responseText);
        var doc = this.responseXML.documentElement;
        // The following is ugly and requires explanation so here goes:
        // API is sub-optimal and this is a work around
        // API returns '200 OK' even if word is NOT found
        // returns suggestions that look just like definitions
        // existence of suggestion nodes means word wasn't found
        // or a '200 OK' and an empty list if nothing remotely similar exists 
        // work around by looking for suggestions and treating as word not found if present
        var suggestions = doc.getElementsByTagName("suggestion");
        Ti.API.info("suggestions.length=" + suggestions.length);
        if( (suggestions.length > 0) || (! doc.getElementsByTagName("entry")) ) {
          $.definition.text = "Word doesn't exist in dictionary.";
        } 
        else {
          Ti.API.info("good API call");
          $.definition.text = doc.getElementsByTagName("entry").item(0).getAttribute("id") + 
            ": " + doc.getElementsByTagName("pr").item(0).text +
             " " + doc.getElementsByTagName("dt").item(0).text;
        }
    },
    onerror: function(e) {
		// this function is called when an error occurs, including a timeout
        Ti.API.debug(e.error);
        alert('error');
    },
    timeout:5000  /* in milliseconds */
});


function doClick(e){
    Titanium.API.info("You clicked the button.  Selected = " + selected);
    var url = "http://www.dictionaryapi.com/api/v1/references/sd2/xml/" + selected + "?key=<KEY>";
    Ti.API.info(url);
    xhr.open("GET", url);
    xhr.send();  // request is actually sent with this statement
};<commit_msg>modified picker to display word on open<commit_after>

var word = "FOOL".split("");
var alphabet = "ABCDEFGHIJKLMNOPQRSTUVWXYZ".split('');
var selected;



for(var j=0;j<word.length;j++) { // FIXME words greater than 13-14 letters drop the last picker column
    var new_column = Ti.UI.createPickerColumn();
	for (var i = 0; i < alphabet.length; i++) {
		var row = Ti.UI.createPickerRow();
		row.title = alphabet[i],
		new_column.addRow(row);
	}
    $.picker.add(new_column);
}

$.picker.addEventListener('change',function(e) {
	selected =  e.selectedValue.join('');
	Ti.API.info( selected );
//    Ti.API.info("You selected row: "+e.row+", column: "+e.column+", custom_item: "+e.row.custom_item);
//    label.text = "row index: "+e.rowIndex+", column index: "+e.columnIndex;
});

var xhr = Ti.Network.createHTTPClient({
    onload: function(e) {
        Ti.API.debug(this.responseText);
        var doc = this.responseXML.documentElement;
        // The following is ugly and requires explanation so here goes:
        // API is sub-optimal and this is a work around
        // API returns '200 OK' even if word is NOT found
        // returns suggestions that look just like definitions
        // existence of suggestion nodes means word wasn't found
        // or a '200 OK' and an empty list if nothing remotely similar exists 
        // work around by looking for suggestions and treating as word not found if present
        var suggestions = doc.getElementsByTagName("suggestion");
        Ti.API.info("suggestions.length=" + suggestions.length);
        if( (suggestions.length > 0) || (! doc.getElementsByTagName("entry")) ) {
          $.definition.text = "Word doesn't exist in dictionary.";
        } 
        else {
          Ti.API.info("good API call");
          $.definition.text = doc.getElementsByTagName("entry").item(0).getAttribute("id") + 
            ": " + doc.getElementsByTagName("pr").item(0).text +
             " " + doc.getElementsByTagName("dt").item(0).text;
        }
    },
    onerror: function(e) {
		// this function is called when an error occurs, including a timeout
        Ti.API.debug(e.error);
        alert('error');
    },
    timeout:5000  /* in milliseconds */
});


function doClick(e){
    Titanium.API.info("You clicked the button.  Selected = " + selected);
    var url = "http://www.dictionaryapi.com/api/v1/references/sd2/xml/" 
              + selected + "?key=<KEY>";
    Ti.API.info(url);
    xhr.open("GET", url);
    xhr.send();  
};


$.index.addEventListener('open', function() {
	Ti.API.info("in open event listener.");
      for(var k=0; k<word.length; k++) {
      	Ti.API.info("word[k]=" + word[k]);
      	Ti.API.info("indexOf()=" + alphabet.indexOf( word[k] ));
      	$.picker.setSelectedRow(k, alphabet.indexOf( word[k] ), false);
      }
      setTimeout(function(){ // FIXME this may be a race condition; 
        $.button.fireEvent('click');
      }, 200);
      
});
 

$.index.open();
{'fraction_non_alphanumeric': 0.15273193986065273, 'fraction_numerical': 0.008984231756508984, 'mean_word_length': 2.830758426966292, 'pattern_counts': {'":': 2, '<': 10, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 2}, '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': '6166399', 'n_tokens_mistral': 1746, 'n_tokens_neox': 1667, 'n_words': 437}