Skip to content

Commit

Permalink
Add <img> tag wrapper #121
Browse files Browse the repository at this point in the history
  • Loading branch information
Alfiana Sibuea committed May 4, 2015
1 parent 2ff43e4 commit 826ec43
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 2 deletions.
24 changes: 24 additions & 0 deletions dist/waves.js
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,22 @@
wrapper.setAttribute('style', 'color:' + color + ';background:' + backgroundColor);
element.setAttribute('style', 'background-color:rgba(0,0,0,0);');
}

// Wrap <img> tag inside a span
function wrapImgTag(element) {

var parent = element.parentNode;

// If input already have parent just pass through
if (parent.tagName.toLowerCase() === 'i' && parent.classList.contains('waves-effect')) {
return;
}

// Put element as child
var wrapper = document.createElement('i');
parent.replaceChild(wrapper, element);
wrapper.appendChild(element);
}


/**
Expand Down Expand Up @@ -432,6 +448,7 @@
* or skimming effect should be applied to the elements.
*/
Waves.attach = function(elements, classes) {

elements = getWavesElements(elements);

if (toString.call(classes) === '[object Array]') {
Expand All @@ -441,13 +458,20 @@
classes = classes ? ' ' + classes : '';

var element;

for (var i = 0, len = elements.length; i < len; i++) {

element = elements[i];

if (element.tagName.toLowerCase() === 'input') {
wrapInputTag(element);
element = element.parentElement;
}

if (element.tagName.toLowerCase() === 'img') {
wrapImgTag(element);
element = element.parentElement;
}

element.className += ' waves-effect' + classes;
}
Expand Down
2 changes: 1 addition & 1 deletion dist/waves.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 826ec43

Please sign in to comment.