// Code goes here
jQuery(function ($) {
var $checkbox = $(':checkbox');
var $result = $('#result');
var selected = [];
$checkbox.on('change', function () {
var $this = $(this);
var isChecked = $this.is(':checked');
var value = $this.data('value');
console.log(isChecked, value);
if (isChecked) {
selected.push(value);
} else {
selected.splice(
selected.indexOf(value),
1
);
}
setResult();
});
function setResult() {
$result.html(selected.join(', ') || 'Nothing');
}
setResult();
});
jQuery(function ($) {
var $doc = $(document);
var isDown = false;
$doc.on('mousedown', function () {
isDown = true;
});
$doc.on('mouseup', function () {
isDown = false;
});
$doc.on('keypress', function (event) {
if (isDown) {
console.log(
'pressed via mousedown',
event.which
);
}
});
});
var re = /(?:^https?:\/\/(?:www\.)?)|(?:\/$)/g;
var strings = [
'http://foo.bar',
'http://foo.bar/',
'http://www.foo.bar',
'http://www.foo.bar/',
'https://foo.bar',
'https://foo.bar/',
'https://www.foo.bar',
'https://www.foo.bar/'
];
strings.forEach(function (string) {
console.log(string.replace(re, ''));
});