Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

Callbacks for pre- or postprocessing elements #96

Open
wants to merge 1 commit into from

1 participant

@kaste

See it: http://jsbin.com/apixel/12/edit

Consider:

context = {
  beforeRemove: function(els, view){ return .slideUp(function(){ view.remove(); }); },
  afterInsert: function(els){ .effect('pulsate'); }
}

$('#tmpl').link(data, '#content', context);

Great stuff: {{for stuff ~afterInsert=~myEffectHdl }} works as expected.

#70

@kaste kaste Added beforeRemove and afterInsert callbacks for pre- or postprocessi…
…ng of elements.

context = {
  beforeRemove: function(els, view){ return .slideUp(function(){ view.remove(); }); },
  afterInsert: function(els){ .effect('pulsate'); }
}

Great stuff: {{for stuff ~afterInsert=~myEffectHdl }} works as expected.
30be316
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Jul 19, 2012
  1. @kaste

    Added beforeRemove and afterInsert callbacks for pre- or postprocessi…

    kaste authored
    …ng of elements.
    
    context = {
      beforeRemove: function(els, view){ return .slideUp(function(){ view.remove(); }); },
      afterInsert: function(els){ .effect('pulsate'); }
    }
    
    Great stuff: {{for stuff ~afterInsert=~myEffectHdl }} works as expected.
This page is out of date. Refresh to see the latest.
Showing with 19 additions and 2 deletions.
  1. +19 −2 jquery.views.js
View
21 jquery.views.js
@@ -205,10 +205,27 @@ this.jQuery && jQuery.link || (function(global, undefined) {
function arrayChangeHandler(ev, eventArgs) {
var context = this.ctx,
- beforeChange = context.beforeChange;
+ beforeChange = context.beforeChange,
+ skipDefaultHandler;
if (!beforeChange || beforeChange.call(this, ev, eventArgs) !== FALSE) {
- this._onDataChanged(eventArgs);
+ if (eventArgs.change && eventArgs.change === 'remove' && context.beforeRemove){
+ // the beforeRemove-handler can return a truthy value denoting that he already has removed the view
+ var view = this,
+ nodes = view.views[ eventArgs.index ].nodes;
+
+ view.remove = function(){ // convenience wrapper
+ view._onDataChanged(eventArgs);
+ };
+ skipDefaultHandler = context.beforeRemove.call(this, nodes, view, eventArgs);
+ }
+
+ skipDefaultHandler || this._onDataChanged(eventArgs);
+
+ if (eventArgs.change && eventArgs.change === "insert" && context.afterInsert) {
+ var nodes = this.views[ eventArgs.index ].nodes;
+ context.afterInsert.call(this, nodes, this, eventArgs);
+ }
if (context.afterChange) {
context.afterChange.call(this, ev, eventArgs);
}
Something went wrong with that request. Please try again.