Skip to content

Commit

Permalink
Tidied up Boxy.ask() slightly
Browse files Browse the repository at this point in the history
  • Loading branch information
Jason committed Oct 10, 2008
1 parent fbf6133 commit 01bb2f5
Showing 1 changed file with 18 additions and 18 deletions.
36 changes: 18 additions & 18 deletions src/javascripts/jquery.boxy.js
Expand Up @@ -208,30 +208,23 @@ jQuery.extend(Boxy, {
{show: true, unloadOnHide: true});

var body = jQuery('<div></div>').append(jQuery('<div class="question"></div>').html(question));

// ick
var map = {}, answerStrings = [];
if (answers instanceof Array) {
for (var i = 0; i < answers.length; i++) {
map[answers[i]] = answers[i];
answerStrings.push(answers[i]);
}
} else {
for (var k in answers) {
map[answers[k]] = k;
answerStrings.push(answers[k]);
}
}


var buttons = jQuery('<form class="answers"></form>');
buttons.html(jQuery.map(answerStrings, function(v) {
return "<input type='button' value='" + v + "' />";
buttons.html(jQuery.map(Boxy._values(answers), function(v) {
return "<input type='button' value='" + v + "' />"
}).join(' '));

jQuery('input[type=button]', buttons).click(function() {
var clicked = this;
Boxy.get(this).hide(function() {
if (callback) callback(map[clicked.value]);
if (callback) {
jQuery.each(answers, function(i, val) {
if (val == clicked.value) {
callback(answers instanceof Array ? val : i);
return false;
}
});
}
});
});

Expand All @@ -251,6 +244,13 @@ jQuery.extend(Boxy, {
if (typeof arguments[i] != 'undefined') return false;
return true;
},

_values: function(t) {
if (t instanceof Array) return t;
var o = [];
for (var k in t) o.push(t[k]);
return o;
},

_handleResize: function(evt) {
jQuery('.boxy-modal-blackout').css('display', 'none')
Expand Down

0 comments on commit 01bb2f5

Please sign in to comment.