/*
---
 
script: Update.js
 
description: Update widget with html or json
 
license: Public domain (http://unlicense.org).

authors: Yaroslaff Fedin
 
requires:
  - LSD.Action

provides:
  - LSD.Action.Update
  - LSD.Action.Append
  - LSD.Action.Replace
  - LSD.Action.Before
  - LSD.Action.After

...
*/

LSD.Action.Update = LSD.Action.build({
  container: true,
  
  enable: function(target, content) {
    if (!content) return LSD.warn('Update action did not recieve content');
    if (content.charAt) {
      var fragment = document.createFragment(content);
      var children = LSD.slice(fragment.childNodes);
    } else {
      var fragment = document.createFragment('');
      if (!content.hasOwnProperty('length')) {
        var children = [content];
        fragment.appendChild(content);
      } else for (var i = 0, child; child = children[i++];) fragment.appendChild(child);
    }
    var widget = LSD.Module.DOM.find(target);
    if (widget.element == target) {
      parent = widget.parentNode;
      var element = target;
      target = parent;
    } else {
      var element = target, parent = widget;
      widget = null;
    }
    this.options.update.apply(this, [element, widget, parent, fragment, children]);
  },
  
  update: function(element, widget, parent, fragment, children) {
    (widget || parent).removeLayout(null, element.childNodes, element);
    element.appendChild(fragment);
    (widget || parent).addLayout(null, children, element);
  }
});

LSD.Action.Append = LSD.Action.build({
  enable: LSD.Action.Update.prototype.options.enable,
  
  update: function(element, widget, parent, fragment, children) {
    element.appendChild(fragment);
    (widget || parent).addLayout(null, children, element)
  }
});

LSD.Action.Replace = LSD.Action.build({
  enable: LSD.Action.Update.prototype.options.enable,

  update: function(element, widget, parent, fragment) {
    var parentNode = element.parentNode
    parentNode.replaceChild(fragment, element, children);
    parent.removeLayout(null, widget || element);
    parent.addLayout(null, children, parentNode);
  }
});

LSD.Action.Before = LSD.Action.build({
  enable: LSD.Action.Update.prototype.options.enable,

  update: function(element, widget, parent, fragment, children) {
    target.parentNode.insertBefore(fragment, element);
    parent.addLayout(null, children, element.parentNode, {before: element});
  }
});

LSD.Action.After = LSD.Action.build({
  enable: LSD.Action.Update.prototype.options.enable,

  update: function(element, widget, parent, fragment, children) {
    element.parentNode.insertBefore(fragment, element.nextSibling);
    parent.addLayout(null, children, element.parentNode, {before: element.nextSibling});
  }
});
@@ -342,30 +342,8 @@
 d(%7B%0A
-  container: true,%0A  %0A
   en
@@ -860,24 +860,166 @@
 ild);%0A    %7D%0A
+    if (target.lsd) %7B%0A      var widget = target;%0A      var element = widget.toElement();%0A      var parent = target.parentNode;%0A    %7D else %7B%0A  
     var widg
@@ -1052,24 +1052,26 @@
 arget);%0A    
+  
 if (widget.e
@@ -1092,24 +1092,26 @@
 et) %7B%0A      
+  
 parent = wid
@@ -1122,24 +1122,26 @@
 parentNode;%0A
+  
       var el
@@ -1162,29 +1162,8 @@
 ;%0A  
-    target = parent;%0A
     
@@ -1163,32 +1163,34 @@
 %0A      %7D else %7B%0A
+  
       var elemen
@@ -1224,16 +1224,18 @@
 ;%0A      
+  
 widget =
@@ -1241,16 +1241,24 @@
 = null;%0A
+      %7D%0A
     %7D%0A  
@@ -1999,16 +1999,26 @@
 fragment
+, children
 ) %7B%0A    
@@ -2098,26 +2098,16 @@
  element
-, children
 );%0A    p
@@ -2374,21 +2374,22 @@
 ) %7B%0A    
-targe
+elemen
 t.parent

Make Update treat widgets just as elements, fix two typos