Skip to content

Commit

Permalink
Merge branch 'remove-tabs' of https://github.com/jdanyow/templating i…
Browse files Browse the repository at this point in the history
…nto jdanyow-remove-tabs
  • Loading branch information
EisenbergEffect committed Mar 14, 2015
2 parents 1532c09 + f3cb35d commit a696025
Show file tree
Hide file tree
Showing 6 changed files with 158 additions and 158 deletions.
20 changes: 10 additions & 10 deletions src/behavior-instance.js
@@ -1,9 +1,9 @@
export class BehaviorInstance {
constructor(behavior, executionContext, instruction){
this.behavior = behavior;
this.executionContext = executionContext;
constructor(behavior, executionContext, instruction){
this.behavior = behavior;
this.executionContext = executionContext;

var observerLookup = behavior.observerLocator.getObserversLookup(executionContext),
var observerLookup = behavior.observerLocator.getObserversLookup(executionContext),
handlesBind = behavior.handlesBind,
attributes = instruction.attributes,
boundProperties = this.boundProperties = [],
Expand All @@ -13,16 +13,16 @@ export class BehaviorInstance {
for(i = 0, ii = properties.length; i < ii; ++i){
properties[i].initialize(executionContext, observerLookup, attributes, handlesBind, boundProperties);
}
}
}

created(context){
if(this.behavior.handlesCreated){
this.executionContext.created(context);
}
}

bind(context){
var skipSelfSubscriber = this.behavior.handlesBind,
bind(context){
var skipSelfSubscriber = this.behavior.handlesBind,
boundProperties = this.boundProperties,
i, ii, x, observer, selfSubscriber;

Expand Down Expand Up @@ -50,9 +50,9 @@ export class BehaviorInstance {
if(this.view){
this.view.bind(this.executionContext);
}
}
}

unbind(){
unbind(){
var boundProperties = this.boundProperties,
i, ii;

Expand All @@ -67,7 +67,7 @@ export class BehaviorInstance {
for(i = 0, ii = boundProperties.length; i < ii; ++i){
boundProperties[i].binding.unbind();
}
}
}

attached(){
if(this.behavior.handlesAttached){
Expand Down
124 changes: 62 additions & 62 deletions src/children.js
@@ -1,7 +1,7 @@
var noMutations = [];

export class ChildObserver {
constructor(property, changeHandler, selector){
constructor(property, changeHandler, selector){
this.selector = selector;
this.changeHandler = changeHandler;
this.property = property;
Expand All @@ -13,86 +13,86 @@ export class ChildObserver {
}

export class ChildObserverBinder {
constructor(selector, target, property, behavior, changeHandler){
this.selector = selector;
this.target = target;
this.property = property;
this.target = target;
constructor(selector, target, property, behavior, changeHandler){
this.selector = selector;
this.target = target;
this.property = property;
this.target = target;
this.behavior = behavior;
this.changeHandler = changeHandler;
this.observer = new MutationObserver(this.onChange.bind(this));
}
this.observer = new MutationObserver(this.onChange.bind(this));
}

bind(source){
bind(source){
var items, results, i, ii, node, behavior = this.behavior;

this.observer.observe(this.target, {childList:true, subtree: true});
this.observer.observe(this.target, {childList:true, subtree: true});

items = behavior[this.property];
if(!items){
items = behavior[this.property] = [];
}else{
items.length = 0;
}
items = behavior[this.property];
if(!items){
items = behavior[this.property] = [];
}else{
items.length = 0;
}

results = this.target.querySelectorAll(this.selector);
results = this.target.querySelectorAll(this.selector);

for(i = 0, ii = results.length; i < ii; ++i){
node = results[i];
items.push(node.primaryBehavior ? node.primaryBehavior.executionContext : node);
}
for(i = 0, ii = results.length; i < ii; ++i){
node = results[i];
items.push(node.primaryBehavior ? node.primaryBehavior.executionContext : node);
}

if(this.changeHandler){
this.behavior[this.changeHandler](noMutations);
}
}
}

unbind(){
this.observer.disconnect();
}
unbind(){
this.observer.disconnect();
}

onChange(mutations){
var items = this.behavior[this.property],
selector = this.selector;
onChange(mutations){
var items = this.behavior[this.property],
selector = this.selector;

mutations.forEach(record => {
var added = record.addedNodes,
removed = record.removedNodes,
prev = record.previousSibling,
mutations.forEach(record => {
var added = record.addedNodes,
removed = record.removedNodes,
prev = record.previousSibling,
i, ii, primary, index, node;

for(i = 0, ii = removed.length; i < ii; ++i){
node = removed[i];
if(node.nodeType === 1 && node.matches(selector)){
primary = node.primaryBehavior ? node.primaryBehavior.executionContext : node;
index = items.indexOf(primary);
if(index != -1){
items.splice(index, 1);
}
}
}

for(i = 0, ii = added.length; i < ii; ++i){
node = added[i];
if(node.nodeType === 1 && node.matches(selector)){
primary = node.primaryBehavior ? node.primaryBehavior.executionContext : node;
index = 0;

while(prev){
if(prev.nodeType === 1 && prev.matches(selector)){
index++;
}

prev = prev.previousSibling;
}

items.splice(index, 0, primary);
}
}
});
for(i = 0, ii = removed.length; i < ii; ++i){
node = removed[i];
if(node.nodeType === 1 && node.matches(selector)){
primary = node.primaryBehavior ? node.primaryBehavior.executionContext : node;
index = items.indexOf(primary);
if(index != -1){
items.splice(index, 1);
}
}
}

for(i = 0, ii = added.length; i < ii; ++i){
node = added[i];
if(node.nodeType === 1 && node.matches(selector)){
primary = node.primaryBehavior ? node.primaryBehavior.executionContext : node;
index = 0;

while(prev){
if(prev.nodeType === 1 && prev.matches(selector)){
index++;
}

prev = prev.previousSibling;
}

items.splice(index, 0, primary);
}
}
});

if(this.changeHandler){
this.behavior[this.changeHandler](mutations);
}
}
}
}
114 changes: 57 additions & 57 deletions src/content-selector.js
Expand Up @@ -8,27 +8,27 @@ if (Element && !Element.prototype.matches) {
var placeholder = [];

function findInsertionPoint(groups, index){
var insertionPoint;
var insertionPoint;

while(!insertionPoint && index >= 0){
insertionPoint = groups[index][0];
index--;
}
while(!insertionPoint && index >= 0){
insertionPoint = groups[index][0];
index--;
}

return insertionPoint || anchor;
return insertionPoint || anchor;
}

export class ContentSelector {
static applySelectors(view, contentSelectors, callback){
var currentChild = view.fragment.firstChild,
contentMap = new Map(),
nextSibling, i, ii, contentSelector;
static applySelectors(view, contentSelectors, callback){
var currentChild = view.fragment.firstChild,
contentMap = new Map(),
nextSibling, i, ii, contentSelector;

while (currentChild) {
while (currentChild) {
nextSibling = currentChild.nextSibling;

if(currentChild.viewSlot){
var viewSlotSelectors = contentSelectors.map(x => x.copyForViewSlot());
var viewSlotSelectors = contentSelectors.map(x => x.copyForViewSlot());
currentChild.viewSlot.installContentSelectors(viewSlotSelectors);
}else{
for(i = 0, ii = contentSelectors.length; i < ii; i++){
Expand All @@ -50,61 +50,61 @@ export class ContentSelector {
}

for(i = 0, ii = contentSelectors.length; i < ii; ++i){
contentSelector = contentSelectors[i];
callback(contentSelector, contentMap.get(contentSelector) || placeholder);
contentSelector = contentSelectors[i];
callback(contentSelector, contentMap.get(contentSelector) || placeholder);
}
}

constructor(anchor, selector){
this.anchor = anchor;
this.selector = selector;
this.all = !this.selector;
this.groups = [];
}

copyForViewSlot(){
return new ContentSelector(this.anchor, this.selector);
}

matches(node){
return this.all ||
(node.nodeType === 1 && node.matches(this.selector));
}

add(group){
var anchor = this.anchor,
parent = anchor.parentNode,
}

constructor(anchor, selector){
this.anchor = anchor;
this.selector = selector;
this.all = !this.selector;
this.groups = [];
}

copyForViewSlot(){
return new ContentSelector(this.anchor, this.selector);
}

matches(node){
return this.all ||
(node.nodeType === 1 && node.matches(this.selector));
}

add(group){
var anchor = this.anchor,
parent = anchor.parentNode,
i, ii;

for(i = 0, ii = group.length; i < ii; ++i){
parent.insertBefore(group[i], anchor);
}
for(i = 0, ii = group.length; i < ii; ++i){
parent.insertBefore(group[i], anchor);
}

this.groups.push(group);
}
this.groups.push(group);
}

insert(index, group){
if(group.length){
var anchor = findInsertionPoint(this.groups, index) || this.anchor,
parent = anchor.parentNode,
insert(index, group){
if(group.length){
var anchor = findInsertionPoint(this.groups, index) || this.anchor,
parent = anchor.parentNode,
i, ii;

for(i = 0, ii = group.length; i < ii; ++i){
parent.insertBefore(group[i], anchor);
}
}
for(i = 0, ii = group.length; i < ii; ++i){
parent.insertBefore(group[i], anchor);
}
}

this.groups.splice(index, 0, group);
}
this.groups.splice(index, 0, group);
}

removeAt(index, fragment){
var group = this.groups[index],
removeAt(index, fragment){
var group = this.groups[index],
i, ii;

for(i = 0, ii = group.length; i < ii; ++i){
fragment.appendChild(group[i]);
}
for(i = 0, ii = group.length; i < ii; ++i){
fragment.appendChild(group[i]);
}

this.groups.splice(index, 1);
}
this.groups.splice(index, 1);
}
}

0 comments on commit a696025

Please sign in to comment.