initial commits
parent
0f9ec01005
commit
811f246ad3
20
ziba.js
20
ziba.js
|
@ -20,26 +20,38 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||||
THE SOFTWARE.
|
THE SOFTWARE.
|
||||||
*/
|
*/
|
||||||
export function transform(rootElement) {
|
export function transform(rootElement) {
|
||||||
|
console.log("[ziba][transform] begin")
|
||||||
|
|
||||||
if (undefined === rootElement) {
|
if (undefined === rootElement) {
|
||||||
|
console.log("[ziba][transform] root-elelemt is undefined")
|
||||||
|
console.log("[ziba][transform] end")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
transform_link(rootElement)
|
transform_link(rootElement)
|
||||||
|
|
||||||
|
console.log("[ziba][transform] end")
|
||||||
}
|
}
|
||||||
|
|
||||||
function transform_link(rootElement) {
|
function transform_link(rootElement) {
|
||||||
|
console.log("[ziba][transform_link] begin")
|
||||||
|
|
||||||
if (undefined === rootElement) {
|
if (undefined === rootElement) {
|
||||||
console.log("[ziba] root-elelemt is undefined")
|
console.log("[ziba][transform_link] root-elelemt is undefined")
|
||||||
|
console.log("[ziba][transform_link] end")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
const tagName = "ziba-link"
|
const tagName = "ziba-link"
|
||||||
const elements = rootElement.getElementsByTagName(tagName)
|
const elements = rootElement.getElementsByTagName(tagName)
|
||||||
if (!elements) {
|
if (!elements) {
|
||||||
console.log("[ziba] no elements")
|
console.log("[ziba][transform_link] no elements")
|
||||||
console.log("[ziba] rootElement.innerHTML=", rootElement.innerHTML)
|
console.log("[ziba][transform_link] rootElement.innerHTML=", rootElement.innerHTML)
|
||||||
|
console.log("[ziba][transform_link] end")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
const length = elements.length
|
||||||
|
console.log("[ziba][transform_link] found", length, tagName)
|
||||||
|
|
||||||
// Because we are doing a replaceWith() on the HTMLCollection,
|
// Because we are doing a replaceWith() on the HTMLCollection,
|
||||||
// we need to iterate through it backwards, because the HTMLCollection
|
// we need to iterate through it backwards, because the HTMLCollection
|
||||||
|
@ -65,4 +77,6 @@ function transform_link(rootElement) {
|
||||||
|
|
||||||
element.replaceWith(anchor)
|
element.replaceWith(anchor)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
console.log("[ziba][transform_link] end")
|
||||||
}
|
}
|
||||||
|
|
|
@ -66,6 +66,13 @@ function testTransform() {
|
||||||
html:'<ziba-link title="1 2 3 4">ONCE TWICE THRICE FOURCE</ziba-link>',
|
html:'<ziba-link title="1 2 3 4">ONCE TWICE THRICE FOURCE</ziba-link>',
|
||||||
expected:'<a href="./1 2 3 4">ONCE TWICE THRICE FOURCE</a>',
|
expected:'<a href="./1 2 3 4">ONCE TWICE THRICE FOURCE</a>',
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
{
|
||||||
|
html:'<ul><li><ziba-link>one</ziba-link></li><li><ziba-link>two</ziba-link></li><li><ziba-link>three</ziba-link></li></ul>',
|
||||||
|
expected:'<ul><li><a href="./one">one</a></li><li><a href="./two">two</a></li><li><a href="./three">three</a></li></ul>',
|
||||||
|
},
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue