Skip to content

Commit

Permalink
Merge pull request #22 from dgt41/jcaption
Browse files Browse the repository at this point in the history
Drop jQuery from JCaption script
  • Loading branch information
C-Lodder authored Oct 2, 2016
2 parents a699437 + 898bd25 commit 8f99d9f
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 32 deletions.
55 changes: 24 additions & 31 deletions media/system/js/caption.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,38 +12,31 @@
* @since 1.5
* @version 1.0
*/
var JCaption = function(_selector) {
var $, selector,

initialize = function(_selector) {
$ = jQuery.noConflict();
selector = _selector;
$(selector).each(function(index, el) {
createCaption(el);
})
var JCaption = function(selector) {
var initialize = function(selector) {
var elements = document.querySelectorAll(selector);
for (var i = 0, count = elements.length; i < count; i++) {
createCaption(elements[i]);
}
},

createCaption = function(element) {
var $el = $(element),
caption = $el.attr('title'),
width = $el.attr("width") || element.width,
align = $el.attr("align") || $el.css("float") || element.style.styleFloat || "none",
$p = $('<p/>', {
"text" : caption,
"class" : selector.replace('.', '_')
}),
$container = $('<div/>', {
"class" : selector.replace('.', '_') + " " + align,
"css" : {
"float" : align,
"width" : width
}
});
$el.before($container);
$container.append($el);
var container, caption = element.getAttribute('title'),
width = element.getAttribute("width") || element.width,
align = element.getAttribute("align") || element.style.styleFloat || "none",
pEl = createElement('<p/>');
pEl.text = caption;
pEl.class = selector.replace('.', '_');
container = createElement('<div/>');
container.class = selector.replace('.', '_') + " " + align;
container.style.styleFloat = align;
container.style.width = width;
container.parentNode.insertBefore(element, container);
container.innerHTML = element;
if (caption !== "") {
$container.append($p);
container.innerHTML = pEl;
}
}
initialize(_selector);
}
};

initialize(selector);
};
2 changes: 1 addition & 1 deletion media/system/js/caption.min.js

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

0 comments on commit 8f99d9f

Please sign in to comment.