Skip to content

Instantly share code, notes, and snippets.

@meglio
Last active December 14, 2015 16:29
Show Gist options
  • Save meglio/5115377 to your computer and use it in GitHub Desktop.
Save meglio/5115377 to your computer and use it in GitHub Desktop.
Replaces jQuery element or its content temporarily with watch symbol of iconic font (icon-refresh). To be used with http://fortawesome.github.com
/**
* Replaces jQuery element or its content temporarily with watch symbol of iconic font (icon-refresh)
*
* To be used with http://fortawesome.github.com
*/
function replaceByWatch(el, replaceInnerContent) {
var watch = $icon('icon-refresh icon-spin')
if (replaceInnerContent) {
var content = el.children().hide()
if (!content.length) {
content = el.text()
el.text('')
}
el.data('replacedByWatch_InnerContent', content).append(watch)
}
else
el.hide().after(watch)
el.data('replacedByWatch', watch)
}
function removeWatch(el) {
el.data('replacedByWatch').remove()
var content = el.data('replacedByWatch_InnerContent')
el.removeData('replacedByWatch replacedByWatch_InnerContent')
switch (typeof content) {
case 'undefined': el.show(); break
case 'string': el.text(content); break
default: content.show(); break
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment