Nuestro conocimiento compartido. Nuestro tesoro compartido. Wikipedia.
ShareCode
Permalink: http://www.treeweb.es/u/974/ 01/02/2011

ShareCode

1 var StackCards = function(parent) {2  3  this.dom = parent;4  this.stack = ([]);5  6  this._observer = new MutationObserver(function(mutations) {7  mutations.forEach(function(mutation) {8  var i;9  for (i in mutation.addedNodes)10  mutation.addedNodes[i].classList.remove('StackCard-out');11  });12  }); 13  14  this._observer_conf = { childList: true };15  16  this._observer.observe(this.dom, this._observer_conf);17 }18 19 StackCards.prototype.push = function(card) {20  card.setAttribute('b', 'StackCard');21  card.classList.add('StackCard-out');22  this.dom.appendChild(card);23  //this.dom.addEventListener('DOMNodeInserted', StackCards.prototype._topStackIn, true);24  this.stack.push(card);25 }26 27 StackCards.prototype.pop = function() {28  var card = this.stack.pop();29  this.dom.removeChild(card);30  return card;31 }32 33 StackCards.prototype._topStackIn = function() {34  alert(88);35  var top = this.dom.lastChild;36  if (top != null)37  top.classList.remove('StackCard-out');38 }39 40 41 42 /*43 var insertedNodes = [];44 var observer = new WebKitMutationObserver(function(mutations) {45  mutations.forEach(function(mutation) {46  for (var i = 0; i < mutation.addedNodes.length; i++)47  insertedNodes.push(mutation.addedNodes[i]);48  })49 });50 observer.observe(document, { childList: true });51 console.log(insertedNodes);52 53 */54 55 ////////////////////////////////////////////////////////////7756 57 var TestCard = function(n) {58  var dom = document.createElement('div');59  dom.innerHTML = 'THIS IS A CARD ('+n+')';60  return dom;61 }62 63 ////////////////////////////////////////////////////////////////64 65 var ms; //main stack66 67 window.addEventListener('load', function() {68  ms = new StackCards(document.body);69  70  var c1 = new TestCard('principal');71  c1.addEventListener('click', function(event){72  var c2 = new TestCard('secundaria');73  ms.push(c2);74  }, true);75  ms.push(c1);76 }, true);


Este ShareCode tiene versiones:
  1. ... (02/10/2012)
Enlace
El enlace para compartir es: