Skip to content

Instantly share code, notes, and snippets.

View djalmajr's full-sized avatar

Djalma Júnior djalmajr

View GitHub Profile
@djalmajr
djalmajr / span-surround.js
Last active August 29, 2015 14:23
Surround letters, words and lines with span
/**
* Wraps a string around each character/letter
*
* @param {string} str The string to transform
* @param {string} tmpl Template that gets interpolated
* @returns {string} The given input as splitted by chars/letters
*/
function wrapChars(str, tmpl) {
return str.replace(/\w/g, tmpl || "<span>$&</span>");
}
@djalmajr
djalmajr / toggleContentEditable.js
Last active August 29, 2015 14:14
Toggle element edit
var el = document.querySelector('.el'),
btn = document.querySelector('.btn-edit');
el.addEventListener('input', function (e) {
console.log(e.currentTarget.textContent);
});
btn.addEventListener('click', function () {
var isEditing = el.getAttribute('contenteditable');