Skip to content

Instantly share code, notes, and snippets.

@benbayard
Last active August 29, 2015 14:01
Show Gist options
  • Save benbayard/a831b02d9c2da54b5fff to your computer and use it in GitHub Desktop.
Save benbayard/a831b02d9c2da54b5fff to your computer and use it in GitHub Desktop.
(function($) {
function dumpTag() {
var oldTag = this.tagName;
var $newTag = $(this).addClass("mw-was-" + oldTag.toLowerCase());
$newTag.replaceWith(function() {
var attributes = "";
$.each($newTag[0].attributes, function(i, attr) {
// toEl.attr(attr.name, attr.value);
attributes = attributes + " " + attr.name + '="' + attr.value + '"';
});
return "<div" + attributes + ">" + $newTag.html() + "</div>";
});
}
$.fn.tableDump = function() {
this.filter("table").each(function() {
$this = $(this);
/* so here's what we need to do:
1) get all attributes from table, and replace it with a div with all those attributes.
2) DO THE SAME FOR EACH CHILD down to a td, or th!
*/
// list of table elements I care about.
var tableElements = "thead, tbody, tfoot, tr, td, th"
var bottom = "td, th";
var middle = "tr";
var top = "thead, tbody, tfoot, colgroup";
var tiptop = "table"
// $this.find(tableElements).each(dumpTag);
$this.find(bottom).each(dumpTag);
$this.find(middle).each(dumpTag);
$this.find(top).each(dumpTag);
$this.each(dumpTag);
});
return this;
};
}(jQuery));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment