From 4a3ba25547f6852c72b7ec54f27f851ab89980f1 Mon Sep 17 00:00:00 2001 From: Maxime Thirouin Date: Thu, 3 Apr 2014 06:53:41 +0200 Subject: [PATCH] Make attributes available --- pjax.js | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/pjax.js b/pjax.js index 537429b..8bc95f2 100644 --- a/pjax.js +++ b/pjax.js @@ -340,8 +340,25 @@ , loadContent: function(html, options) { var tmpEl = document.implementation.createHTMLDocument() + + // parse HTML attributes to copy them + // since we are forced to use documentElement.innerHTML (outerHTML can't be used for ) + , htmlRegex = /]+>/gi + , htmlAttribsRegex = /\s?[a-z:]+(?:\=(?:\'|\")[^\'\">]+(?:\'|\"))*/gi + , matches = html.match(htmlRegex) + if (matches.length) { + matches = matches[0].match(htmlAttribsRegex) + if (matches.length) { + matches.shift() + matches.forEach(function(htmlAttrib) { + var attr = htmlAttrib.trim().split("=") + tmpEl.documentElement.setAttribute(attr[0], attr[1].slice(1, -1)) + }) + } + } + tmpEl.documentElement.innerHTML = html - // this.log("load content", tmpEl.documentElement.innerHTML) + this.log("load content", tmpEl.documentElement.attributes, tmpEl.documentElement.innerHTML.length) // try { this.switchSelectors(this.options.selectors, tmpEl, document, options)