This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<div id='qunit-fixture'> | |
<input type='checkbox' id='cb1' name='cb1' | |
data-toggle-target='#tb1' value='on'/> | |
<input type='text' id='tb1' name='tb1' value=''/> | |
</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/// <reference path="qunit.js" /> | |
/// <reference path="jquery-1.7.2.min.js" /> | |
/// <reference path="jquery.disabled-if-check-off.js" /> | |
test('initial state of text box is disabled.', function(){ | |
$('#cb1').disabledIfCheckOff(); | |
Qunit.equal($('#cb1').prop('checked'), false); | |
Qunit.equal($('#tb1').prop('disabled'), true); | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
test('initial state of text box is disabled.', function(){ | |
$('#qunit-fixture').append( | |
"<input type='checkbox' id='cb1' name='cb1' "+ | |
" data-toggle-target='#tb1' value='on'/>"+ | |
"<input type='text' id='tb1' name='tb1' value=''/>"); | |
$('#cb1').disabledIfCheckOff(); | |
Qunit.equal($('#cb1').prop('checked'), false); | |
Qunit.equal($('#tb1').prop('disabled'), true); | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function setupFixture(f) { | |
var lines = f.toString().split('\n'), html = [], i = 0; | |
do i++; while (!(lines[i-1].match(/\/\*[ \t\r]*$/))); | |
while (!(lines[i].match(/^[ \t\r]*\*\//))) html.push(lines[i++]); | |
$('#qunit-fixture').html(html.join('')); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
test('initial state of text box is disabled.', function(){ | |
setupFixture(function(){/* | |
<input type='checkbox' id='cb1' name='cb1' | |
data-toggle-target='#tb1' value='on'/> | |
<input type='text' id='tb1' name='tb1' value=''/> | |
*/}); | |
$('#cb1').disabledIfCheckOff(); | |
Qunit.equal($('#cb1').prop('checked'), false); | |
Qunit.equal($('#tb1').prop('disabled'), true); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function setupFixture(f) { | |
var html = Enumerable.from(f.toString().split('\n')) | |
.select("$.trim()") | |
.skipWhile("$.slice(-2) != '/*'") | |
.skip(1) | |
.takeWhile("$.slice(0, 2) != '*/'"); | |
$('#qunit-fixture').html(html.toArray().join('')); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<form method="post" enctype="multipart/form-data"> | |
<input type="file" name="file" id="file" value="" /> | |
<input type="submit" name="btn-upload" id="btn-upload" | |
value="Upload image..." /> | |
</form> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<script> | |
$(function () { | |
$("#file").change(function () { | |
$(this).closest("form").submit(); | |
}); | |
}); | |
</script> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$("#btn-upload").click(function () { | |
$("#file").click(); | |
return false; // must! | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<style> | |
#file { | |
display:none; | |
} | |
</style> |