Git Product home page Git Product logo

jquery-aop's Introduction

jquery-aop

Add features of aspect-oriented programming (AOP) to jQuery.

Introduction

jQuery AOP is a very small plugin that adds AOP features to javascript. It allows to add advices (Before, After, After Throw, After Finally, Around and Introduction) to any global or instance object.

Features

  • Allows to add Before, After, After Throw, After Finally, Around and Introduction advices.
  • Allows to define point-cuts using regex to match multiple methods.
  • Works with global function and object methods.
  • Advices can be removed after being applied.
  • Just 1091 bytes! (Packed and Gzipped)
  • Integrated into jQuery.

Quick Start

Starting with jQuery AOP is really easy!


jQuery.aop.before( {target: String, method: 'replace'}, 
  function(regex, newString) { 
    alert("About to replace string '" + this + "' with '" + newString + "' using regEx '" + regex + "'");
  }
);

More samples on Reference...

What is new on 1.3?

The latest release of jQuery AOP includes:

  • Support after throw and after finally advices
  • some bug fixes

No breaking changes from 1.2.

What is new on 1.2?

This is a bug fix release, solving some minor issues reported. No breaking changes from 1.1.

What is new on 1.1?

The latest release of jQuery AOP includes two new features:

  • Support for introductions
  • and support for regex matching of method names!

The new regex matching support breaks compatibility with the previous version because now the weaving methods return an array of functions instead of just one function.

But don't worry! You can revert to the old behavior if you need to: more details on BackwardsCompatibility!

jquery-aop's People

Contributors

googlecodeexporter avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

jquery-aop's Issues

Adding MIME-types to your files.

If you were to add the correct MIME-type to your files, you could easily
see your 'test' page for example.

In Eclipse or Aptana, go with 'Team -> Set Property -> svn:MIME'

Original issue reported on code.google.com by [email protected] on 2 Oct 2007 at 3:36

Publish to NPM

Hey, is it okay to publish to NPM please? I saw it used to be, but then it went to Bower and now Bower is basically dead.

instanceof added in r14 fails when crossing frame or iframes

What steps will reproduce the problem?

Reference a target object that lives in another frame (or an iframe)
For example: 

  jQuery.aop.after( {target: frames[0].EditArea, method: 'undo'}, 
                      function() {  whatever(); }
                    );

What is the expected output? What do you see instead?

  The script will fail as soon as the weaved method gets called and
references another variable in the target object.

What version of the product are you using? On what operating system?

  jquery-aop 1.2 with Firefox 3.5 or IE8 (but probably anywhere)

Please provide any additional information below.

  There's a known problem with using instanceof when referring to an object
in another frame.  It will fail because the other frame has its own global
object so "Function" in the first frame is not the same as "Function" in
the second frame.  As a result, the workaround that you added in revision
r14 (lines 27-40) kicks in when it shouldn't.  That changes the value of
'this' in the called method and things go downhill from there.

  Here are a couple good articles describing the problem and some solutions:

  http://dhtmlkitchen.com/?category=/JavaScript/&date=2007/10/10/&entry


http://thinkweb2.com/projects/prototype/instanceof-considered-harmful-or-how-to-
write-a-robust-isarray/

Original issue reported on code.google.com by [email protected] on 5 Aug 2009 at 10:22

Unable to determine stack above the joinpoint

What steps will reproduce the problem?
1. Make up a script that contains DoValidations, Clear, and Add global
functions. Clear and Add are called from within DoValidations
2.Weave 'after' advices for Clear and Add
3.In the Clear advice determine the stack leading upt to the Clear advice
4.In the Clear advice determine the caller. If DoValidations is an ancestor
to Clear, weave and advice for Add.
5. Call the DoValidations from an onready code. 

What is the expected output? What do you see instead?

What I expect to see is a stack frame containing the call of DoValidations,
the call to Clear and perhaps the advice anonymous function. What I see
instead is only the caller of the function determining the call stack, and
an anonymous standing for the advice

The Visual Studio debugger or the Firefox debugger show the entire stack
when I stop in the Clear advice

What version of the product are you using? On what operating system?
I am using 1.0 and the latest jSuery


Please provide any additional information below.


Original issue reported on code.google.com by [email protected] on 23 Apr 2009 at 10:40

Global javascript functions not explicitly added to window can't be weaved in Microsoft Internet Explorer

What steps will reproduce the problem?
1. create a javascript file with these 2 functions
function Get1() {
    console.log('in get1');
}
window.Get2 = function() 
{
    console.log('in get2');
    return "2";
}
2. Create an AOP advice such as 
jQuery.aop.around( {target: window, method: /Get(\d+)/}
that will log when the AOP function fires

What is the expected output? What do you see instead?
Only Get2 will fire in IE. 
Get1 in IE is not part of the target window functions so it doesn't fire.  
It would be great if there were a syntax or a fix that would allow global 
functions to be caught by the AOP.  Is there a syntax for the target or a fix 
that could capture the global javascript functions ?




What version of the product are you using? On what operating system? On
what browser?


Please provide any additional information below.

Original issue reported on code.google.com by [email protected] on 15 Jan 2012 at 1:05

Regular expression 'around' specification not working

What steps will reproduce the problem?
Please browse to the included file (TestAOP.html) and choose one or the
other for the confirm statement.

What is the expected output? What do you see instead?

I should see three alerts:

alert('Executing method DoValidations');
alert('DoValidations');
alert('Done with answer false);

or 

alert('Executing method DoAddressValidations');
alert('DoAddressValidations');
alert('Done with answer true);

depending on whether I chose the other confirm option.

The file specifies to an 'around' advice for either DoValidations or
DoAddressValidations. I specify the regular expression
/DoValidations|DoAddresValidations/

What version of the product are you using? On what operating system?

jQuery-1.3.1.js
aop.js version 1.1

Please provide any additional information below.

I am including the file that should be placed in the same folder as jquery
and aop.js should be in the path ../AOP/jQueryAOP/src/

Original issue reported on code.google.com by [email protected] on 6 May 2009 at 1:11

Attachments:

[Exception... "'No method: undefined' when calling method: [nsIDOMEventListener::handleEvent]" nsresult: "0x8057001e (NS_ERROR_XPC_JS_THREW_STRING)" location: "<unknown>" data: no] jquery-aop with multiple libs: (NS_ERROR_XPC_JS_THREW_STRING)" location: "<unknown>" data: no]

What steps will reproduce the problem?
1.
use the following libraries:
jquery-dimension
jquery-uit
jasorb
jquery.menu
jquery.boxy

2.
load the page with jquery.aop
3.

What is the expected output? What do you see instead?

[Exception... "'No method: undefined' when calling method:
[nsIDOMEventListener::handleEvent]"  nsresult: "0x8057001e
(NS_ERROR_XPC_JS_THREW_STRING)"  location: "<unknown>"  data: no]

Line 0



What version of the product are you using? On what operating system?
Linux, firefox 2.0.0.13

Please provide any additional information below.

I know i am using a lot of libs but it should work, this is a real bug

Original issue reported on code.google.com by [email protected] on 15 Jul 2008 at 8:07

.before gives error in IE8

In search()
builds an array thats indexed by numbers and returns it.

in weave()
Iteration over the returned methods with

for (var i in methods)
  advices[advices.length] = weaveOne(methods[i].source, methods[i].method, methods[i].advice);

have undesired effects in
give errors with IE8 when extra functionality is added to the array object

Using

for (var i=0; i<methods.length; i++)
  advices[advices.length] = weaveOne(methods[i].source, methods[i].method, methods[i].advice);

ensures that its only the numeric entries for the array from search thats weaved.

so bugfix:
change

for (var i in methods)

to

for (var i=0; i<methods.length; i++)

in aop.js line 174, and it works in IE8 even when Array is Shim'ed

Adding an Around aspect

Hi, I have just been playing around with adding Around aspects, and
discovered a small problem: I needed my around aspect to be able to add an
argument and remove an argument, and I couldn't do that with the standard
'arguments' object (which is not a real array) that is available from
invocation.arguments. So, I modified the weaver to pass in a modified
object that is an array. Updated code is below:

        else if (advice.type == _around) {
            aspect = function() {
                var args = Array.prototype.slice.call(arguments); //convert
to real array
                var invocation = { object: this, args: args };
                return advice.value.apply(invocation.object, [{ arguments:
invocation.args, method: method, proceed : 
                    function() {
                        return old.apply(invocation.object, invocation.args);
                    }
                }] );
            };
        }



Original issue reported on code.google.com by [email protected] on 12 Jun 2008 at 11:55

Add advice types for after-throwing and after-finally

There are two additional advice types that should be supported: after-throw 
(triggered only after failed execution of the method) and after-finally 
(triggered always after the execution of the method regardless of the success 
or failure of it). 

This will complement the existing 'after' advice that triggers only after 
successful execution of the method.

Original issue reported on code.google.com by [email protected] on 13 Oct 2009 at 7:51

Urgent,jQUery AOP fails in IE7 and IE7.

After having committed to use jquery.aop in a project, now I am stuck as I
must support IE6 and IE7. I have installed and executed several aspects
successfully in IE8

1.Advice 'after' for {target:window,method:'getElementById')
2.In advice alert that we intercepted and return the value from the
intercepted method.
3. Execute a call to getElementById

Expected output:
Alert that the advice is executing 'Advice for getElementById called'

What I get instead is an exception:
From line 29 of the aop.js 'Object does not support this property or method'

jQuery1.3.2.js
aop.js version 1.1


I maybe completely off base, but what appears to be happening is that the
aspect is not written to the global scope. In IE8 it works properly. Maybe
it would be possible to initialize the aspect to point to a specified scope.

I'd appreciate any help as I am stuck at the moment.

Thanks

P.S. The included file includes aop.js and jquery.1.3.2.js from the local
folder.

Original issue reported on code.google.com by [email protected] on 8 Jul 2009 at 9:44

Attachments:

The aop is invalid When the pointcut.target is intanceof Function

for exp: jQuery is a Function and jQuery.get can't be intercepted!

$.aop.before({target:jQueryObj,method:"get"},function(invocation){
                        alert("Intercept the method 
get of jQuery !");
                        //return 
invocation.proceed();
                    });

I modify the aop.js in line 88. 
old code: 
var source = (typeof(pointcut.target.prototype) != 'undefined') ? 
pointcut.target.prototype : pointcut.target

new code:
var source = (typeof(pointcut.target) !== 'function' && 
typeof(pointcut.target.prototype) != 'undefined') ? 
pointcut.target.prototype : 
pointcut.target;

Then the bug is fixed!
But the test.case01 gonna be failed.
because String,Function,Number and Date are function in JavaScript

I correct the test.case01 like this :
old code : {target: String, method: 'indexOf' }
new code : {target: String.prototype, method: 'indexOf' }
test.case01 passed and the code is bad smell ^_^

I think using a Array like [Number,Date,String] to recognize the variable 
to be a type constructor function.
If it's true ,the pointcut.target is it's prototype else itself !

Original issue reported on code.google.com by [email protected] on 10 Oct 2009 at 3:55

Unexpected exception thrown

What steps will reproduce the problem?
1. attempt to set an advice on a global function that does not exist


What is the expected output? What do you see instead?

I expect nothing when the function is not there - simply don't weave it. I
expect the advice to be weaved when the function exists.

what I see instead is that the weave throws an unknown exception (not the
one in the weave code which is 'No method ...' exception), at line 79 at
'source[method]'


What version of the product are you using? On what operating system?

Version 1.1 running with jQuery 1.3.1


Please provide any additional information below.

Original issue reported on code.google.com by [email protected] on 23 Apr 2009 at 6:10

aop.around on body; pointcut.target is undefined

What steps will reproduce the problem?
1. create an advice with target body document.getElementsByTagNam('body')[0] 
and method "appendChild"

What is the expected output? What do you see instead?
* expected: advice added
* instead: advice not added, error in javascript console (pointcut.target is 
undefined)

What version of the product are you using? On what operating system? On
what browser?

* latest version on Firefox 9beta

Original issue reported on code.google.com by [email protected] on 23 Nov 2011 at 11:36

aop doesn't work with live-bound events.

Here's an example test page illustrating the issue. Click the text that appears.

<html>
<body>

<script type="text/javascript" src="jquery.js">
</script>
<script type="text/javascript" src="aop.pack-1.3.js">
</script>
<script type="text/javascript" >
function hey(){
alert("Hey");
}

function ho(){
alert("ho");
}

$(document).ready(function(){
    jQuery.aop.before({target:window,method:'ho'},hey);
    ho();

    $('a').live('click',hey);
    createLink();
});

function createLink()
{
$('body').append($("<a>test</a>"));
}
</script>
</body>
</html>

Original issue reported on code.google.com by [email protected] on 30 Jul 2010 at 4:10

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.