demo

Toggle Code/Page
function removeTag(userID, photoID){
    alert("Removed from pic #" + photoID);
}
    
AspectScript.deploy({
    kind: 
    pointcut: 
    advice: 
});
    
var batchAspect = AspectScript.deploy({
    kind: AspectScript.AROUND,
    pointcut: function(jp){
        return jp.isCall() && jp.fun === removeTag;
    },
    advice: function(jp){
        this.removals.push(jp.clone());
        updateActionsUI();
    },
    //other properties
    removals: [],
    applyChanges: function(){
        while(this.removals.length != 0){
            this.removals.shift().proceed();
        }
    }
});
    
var removeAllAspect = AspectScript.deploy({
    kind: AspectScript.AFTER,
    pointcut: AspectScript.Pointcuts.call(removeTag).and(function(jp){
        this.removedIds.push(jp.args[1]);
        return this.removedIds.length >= 3;
    }),
    advice: function(){
        if(confirm("Would you like to remove all tags from current album?")){
            for(var i = 1; i <= 5; ++i){
                if(this.shouldRemove(i)){
                    removeTag(1, i);
                }
            }
        }
    },
    //other properties
    removedIds: [],
    shouldRemove: function(idx){
        for(var i = 0; i < this.removedIds.length; ++i){
            if(this.removedIds[i] == idx){
                return false;
            }
        }
        return true;
    }
});
    
var batchAspect = AspectScript.deploy({
    kind: AspectScript.AROUND,
    pointcut: function(jp){
        return jp.isCall() && jp.fun === removeTag;
    },
    advice: function(jp){
        this.removals.push(jp.clone());
        updateActionsUI();
    },
    //other properties
    removals: [],
    applyChanges: function(){
        while(this.removals.length != 0){
            this.removals.shift().proceed();
        }
    }
});

var removeAllAspect = AspectScript.deploy({
    kind: AspectScript.AFTER,
    pointcut: AspectScript.Pointcuts.call(removeTag).and(function(jp){
        this.removedIds.push(jp.args[1]);
        return this.removedIds.length >= 3;
    }),
    advice: function(){
        if(confirm("Would you like to remove all tags from current album?")){
            for(var i = 1; i <= 5; ++i){
                if(this.shouldRemove(i)){
                    removeTag(1, i);
                }
            }
        }
    },
    //other properties
    removedIds: [],
    shouldRemove: function(idx){
        for(var i = 0; i < this.removedIds.length; ++i){
            if(this.removedIds[i] == idx){
                return false;
            }
        }
        return true;
    }
});
    
var batchAspect = AspectScript.deploy({
    kind: AspectScript.AROUND,
    pointcut: function(jp){
        return jp.isCall() && jp.fun === removeTag;
    },
    advice: function(jp){
        this.removals.push(jp.clone());
        updateActionsUI();
    },
    //other properties
    removals: [],
    applyChanges: function(){
        while(this.removals.length != 0){
            this.removals.shift().proceed();
        }
    }
});

var removeAllAspect = AspectScript.deploy({
    kind: AspectScript.AFTER,
    pointcut: AspectScript.Pointcuts.call(removeTag).and(function(jp){
        this.removedIds.push(jp.args[1]);
        return this.removedIds.length >= 3;
    }),
    advice: function(){
        if(confirm("Would you like to remove all tags from current album?")){
            AspectScript.down(this, function(){
                for(var i = 1; i <= 5; ++i){
                    if(this.shouldRemove(i)){
                        removeTag(1, i);
                    }
                }
            });
        }
    },
    //other properties
    removedIds: [],
    shouldRemove: function(idx){
        for(var i = 0; i < this.removedIds.length; ++i){
            if(this.removedIds[i] == idx){
                return false;
            }
        }
        return true;
    }
});
    

  • demo.txt
  • Last modified: 2010/03/16 19:26
  • by aspectscript