Skip to content

Commit

Permalink
updated: small code fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
GianlucaGuarini committed Jul 5, 2015
1 parent b15a1d8 commit fb82b29
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 41 deletions.
34 changes: 8 additions & 26 deletions lib/browser/tag/old-ie-hacks.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,7 @@ function tbodyInnerHTML(el, html, tagName) {
div.innerHTML = '<table>' + html + '</table>'
child = div.firstChild

while (loops--) {
child = child.firstChild
}
while (loops--) child = child.firstChild

el.appendChild(child)

Expand All @@ -33,27 +31,13 @@ function optionInnerHTML(el, html) {
eachMatch = html.match(eachRegx),
ifMatch = html.match(ifRegx)

if (innerValue) {
opt.innerHTML = innerValue[1]
} else {
opt.innerHTML = html
}

if (valuesMatch) {
opt.value = valuesMatch[1]
}

if (selectedMatch) {
opt.setAttribute('riot-selected', selectedMatch[1])
}
if (innerValue) opt.innerHTML = innerValue[1]
else opt.innerHTML = html

if (eachMatch) {
opt.setAttribute('each', eachMatch[1])
}

if (ifMatch) {
opt.setAttribute('if', ifMatch[1])
}
if (valuesMatch) opt.value = valuesMatch[1]
if (selectedMatch) opt.setAttribute('riot-selected', selectedMatch[1])
if (eachMatch) opt.setAttribute('each', eachMatch[1])
if (ifMatch) opt.setAttribute('if', ifMatch[1])

el.appendChild(opt)
}
Expand All @@ -73,9 +57,7 @@ function optgroupInnerHTML(el, html) {
innerContent = options
}

if (labelMatch) {
opt.setAttribute('riot-label', labelMatch[1])
}
if (labelMatch) opt.setAttribute('riot-label', labelMatch[1])

if (innerContent) {
var innerOpt = mkEl('div')
Expand Down
9 changes: 4 additions & 5 deletions lib/browser/tag/tag.js
Original file line number Diff line number Diff line change
Expand Up @@ -164,21 +164,20 @@ function Tag(impl, conf, innerHTML) {

if (p) {

if (parent) {
if (parent)
// remove this tag from the parent tags object
// if there are multiple nested tags with same name..
// remove this element form the array
if (isArray(parent.tags[tagName])) {
if (isArray(parent.tags[tagName]))
each(parent.tags[tagName], function(tag, i) {
if (tag._id == self._id)
parent.tags[tagName].splice(i, 1)
})
} else
else
// otherwise just delete the tag instance
parent.tags[tagName] = undefined
} else {
else
while (el.firstChild) el.removeChild(el.firstChild)
}

if (!keepRootTag)
p.removeChild(el)
Expand Down
15 changes: 7 additions & 8 deletions lib/browser/tag/vdom.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,8 @@ function injectStyle(css) {
if (rs) {
rs.parentNode.insertBefore(styleNode, rs)
rs.parentNode.removeChild(rs)
} else {
document.head.appendChild(styleNode)
}
} else document.head.appendChild(styleNode)

}

styleNode._rendered = true
Expand Down Expand Up @@ -123,14 +122,14 @@ riot.mount = function(selector, tagName, opts) {

// crawl the DOM to find the tag
if (typeof selector === T_STRING) {
if (selector === '*') {
if (selector === '*')
// select all the tags registered
// and also the tags found with the riot-tag attribute set
selector = allTags = selectAllTags()
} else {
else
// or just the ones named like the selector
selector += addRiotTags(selector.split(','))
}

els = $$(selector)
}
else
Expand All @@ -142,9 +141,9 @@ riot.mount = function(selector, tagName, opts) {
// get all custom tags
tagName = allTags || selectAllTags()
// if the root els it's just a single tag
if (els.tagName) {
if (els.tagName)
els = $$(tagName, els)
} else {
else {
// select all the children for all the different root elements
var nodeList = []
each(els, function (_el) {
Expand Down
4 changes: 2 additions & 2 deletions test/tag/loop-context.tag
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
<loop-context>

<li each={ items }>
<a onclick={ parent.toggle }>{ title }</a>
<a onclick={ parent.remove }>remove</a>
<a onclick={ toggle }>{ title }</a>
<a onclick={ remove }>remove</a>
<a onclick={ fn }>fn</a>
<span if={ done }>{ parent.rand }</span>
</li>
Expand Down

0 comments on commit fb82b29

Please sign in to comment.