Last active
December 14, 2015 16:29
-
-
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
This file contains hidden or 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
/** | |
* 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