Permalink
Browse files

adding a destroy option; fixes #11

  • Loading branch information...
1 parent 35f91aa commit e23210699a7107560aed4f9febe1db6518d4a017 @heygrady committed Mar 4, 2013
Showing with 28 additions and 4 deletions.
  1. +24 −4 jquery.textshadow.js
  2. +4 −0 readme.md
View
@@ -25,10 +25,18 @@
options = value;
value = null;
}
- var opts = options || {};
- var useStyle = opts.useStyle === false ? false : true;
- var numShadows = opts.numShadows || 1;
+ var opts = options || {},
+ useStyle = opts.useStyle === false ? false : true,
+ numShadows = opts.numShadows || 1,
+ doDestroy = opts.destroy || false;
+ // handle clearing all of the shadows
+ if (doDestroy) {
+ return this.each(function() {
+ destroy(this);
+ });
+ }
+
// loop the found items
return this.each(function() {
var $elem = $(this),
@@ -37,7 +45,7 @@
// find the copy elements
$copy = $elem.find(copySelector);
-
+
// create them if none exist
if (!$copy.length) {
// create all of the elements
@@ -65,6 +73,7 @@
}
});
};
+
//---------------------
// For splitting words
@@ -143,6 +152,17 @@
origNode = $('<span class="' + prefix + '-original" />')[0],
copyNode = $('<span class="' + prefix + '-copy ' + prefix + '-copy-1" />')[0];
+ // Removes the generated elements
+ function destroy(elem) {
+ var $elem = $(elem);
+
+ $elem.find('.' + prefix + '-copy').remove();
+ $elem.find('.' + prefix + '-original').unwrap().each(function() {
+ $(this).replaceWith(this.childNodes);
+ });
+ }
+
+ // Wrap words in generated elements
function wrapWord(text) {
if (!text.length) { // IE 9
return null;
View
@@ -13,6 +13,7 @@ It is recommended to use this library with a feature detection library such as [
- **useStyle** *boolean* default: true - When `useStyle` is true the styles will be read using `currentStyle` and applied as an inline style to each element. Setting `useStyle` to false will skip this step and allow the special IE styles to be set in the CSS.
- **numShadows** *integer* default: 1 - Only applies when `useStyle` is false. Will create multiple shadow nodes for use with multiple shadows. At least one shadow node is always created.
+- **destroy** *boolean* default: false - Removes any generated HTML elements. This will effectively remove the shadow from IE9 and below. This **does not** remove shadows defined in CSS from browsers that natively support shadows.
### Example Usage
```javascript
@@ -27,6 +28,9 @@ if (!Modernizr.textshadow) {
// creates extra nodes for multiple shadows
$('h1').textshadow({useStyle: false, numShadows: 4});
+ // destroys the generated HTML structure
+ $('h1').textshadow({destroy: true});
+
// normal
$('h1').textshadow('3px 3px 2px #000');

0 comments on commit e232106

Please sign in to comment.