demo

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
Next revision
Previous revision
demo [2010/03/16 21:58]
aspectscript
demo [2010/03/16 22:26] (current)
aspectscript
Line 14: Line 14:
         <textarea id="code" name="code" style="width:720px; height:441px">//enter your code here</textarea>         <textarea id="code" name="code" style="width:720px; height:441px">//enter your code here</textarea>
         </div>         </div>
-        <div style="float: rigth; text-align: left;">+        <div style="float: rigth; text-align: left; margin-left: 10px;">
           <p>Step 0:<br><a href="javascript:setCode('step0');">removeTag code</a></p>           <p>Step 0:<br><a href="javascript:setCode('step0');">removeTag code</a></p>
-          <p>Step X:<br><a href="javascript:setCode('step1');">Aspect Structure</a></p> +<hr> 
-          <p>Step X:<br><a href="javascript:setCode('step2');">Batch Aspect</a></p>+          <p>Step 1:<br><a href="javascript:setCode('step1');">Aspect Structure</a></p
 +<hr
 +          <p>Step 2:<br><a href="javascript:setCode('step2');">Batch Aspect</a></p> 
 +<hr> 
 +          <p>Step 3:<br><a href="javascript:setCode('step3');">RemoveAll Aspect</a></p>
  
-          <br><br><br><br><br><br><br><br><br><br><br><br><br><br><br>+<hr> 
 +          <p>Step 4:<br><a href="javascript:setCode('step4');">Everything together</a></p> 
 + 
 +<hr> 
 + 
 +         <p>Step 5:<br><a href="javascript:setCode('step5');">Everything together (2)</a></p> 
 + 
 +          <br>
           <input type="submit" value="  Run it!  ">           <input type="submit" value="  Run it!  ">
         </div>                 </div>        
Line 68: Line 79:
     </pre>     </pre>
     <pre id="step2">     <pre id="step2">
-AspectScript.deploy({+var batchAspect = AspectScript.deploy({
     kind: AspectScript.AROUND,     kind: AspectScript.AROUND,
     pointcut: function(jp){     pointcut: function(jp){
Line 83: Line 94:
             this.removals.shift().proceed();             this.removals.shift().proceed();
         }         }
 +    }
 +});
 +    </pre>
 +
 +<pre id="step3">
 +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;
 +    }
 +});
 +    </pre>
 +
 +  <pre id="step4">
 +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;
 +    }
 +});
 +    </pre>
 +
 +  <pre id="step5">
 +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.1268776730.txt.gz
  • Last modified: 2010/03/16 21:58
  • by aspectscript