Skip to content

Commit

Permalink
Implemented our examples table enhancements. Need to move functionali…
Browse files Browse the repository at this point in the history
…ty and new egrep function to separate files.
  • Loading branch information
baphled committed Aug 5, 2010
1 parent 8eca1b9 commit 90cac35
Showing 1 changed file with 71 additions and 0 deletions.
71 changes: 71 additions & 0 deletions public/javascripts/application.js
Expand Up @@ -64,4 +64,75 @@ $(document).ready(function() {
}

instantiateOrderedListEvents();

var $originalSteps = null;

var displayExamples = function(event) {

var $headings = $('table.ui-tabs:visible > thead tr:last td b'), // get headings
$currentRow = $('td', this),
$steps = $('ul.steps:visible li').egrep(/<(\w+)>/i); // get steps with <>'s

if (event.type == 'mouseenter') {
$originalSteps = $('ul.steps:visible li').clone();
}

// search through each of the headings
$currentRow.each(function() {
var $row = $(this);
var found = false;

$headings.each(function(){
var $heading = $(this),
matcher = '<' + $heading.text() + '>';
// search and replace matcher with the steps value
if (found == false) {
$steps.each(function() {
var $step = $(this);
// if the step contains the matcher
var re = new RegExp(matcher);
if (re.exec($step.text())) {
var newString = $step.text().replace(matcher, $row.text());
// replace text
$step.text(newString);
// return found
found = true;
}
});
}
});
});
};

var restoreExamples = function() {
// revert
$('ul.steps:visible li').replaceWith($originalSteps);
}

$('table.ui-tabs tbody tr').hover(displayExamples, restoreExamples);
});

(function($) {
$.fn.egrep = function(pat) {
var out = [];
var textNodes = function(n) {
if (n.nodeType == Node.TEXT_NODE) {
var t = typeof pat == 'string' ?
n.nodeValue.indexOf(pat) != -1 :
pat.test(n.nodeValue);
if (t) {
out.push(n.parentNode);
}
}
else {
$.each(n.childNodes, function(a, b) {
textNodes(b);
});
}
};
return this.each(function() {
textNodes(this);
});

};
})(jQuery);

0 comments on commit 90cac35

Please sign in to comment.