Sha256: 678f5475f3553a21e3d5d94738766044c41d90a1e0e2c11d67761080ef40ab7b
Contents?: true
Size: 1.53 KB
Versions: 56
Compression:
Stored size: 1.53 KB
Contents
module Volt module CommentSearchers if RUBY_PLATFORM == 'opal' NO_XPATH = `!!window._phantom || !document.evaluate` else NO_XPATH = false end def find_by_comment(text, in_node = `document`) if NO_XPATH find_by_comment_without_xml(text, in_node) else node = nil ` node = document.evaluate("//comment()[. = ' " + text + " ']", in_node, null, XPathResult.UNORDERED_NODE_ITERATOR_TYPE, null).iterateNext(); ` node end end # PhantomJS does not support xpath in document.evaluate def find_by_comment_without_xml(text, in_node) match_text = " #{text} " ` function walk(node) { if (node.nodeType === 8 && node.nodeValue === match_text) { return node; } var children = node.childNodes; if (children) { for (var i=0;i < children.length;i++) { var matched = walk(children[i]); if (matched) { return matched; } } } return null; } return walk(in_node); ` end # Returns an unattached div with the nodes from the passed # in html. def build_from_html(html) temp_div = nil ` temp_div = document.createElement('div'); var doc = jQuery.parseHTML(html); if (doc) { for (var i=0;i < doc.length;i++) { temp_div.appendChild(doc[i]); } } ` temp_div end end end
Version data entries
56 entries across 56 versions & 1 rubygems