jQuery is up to version 1.4! In addition to several new features and the "usual" rewrite of the code, all documentation has been revised so really more readable than before. impostato a _blank ! But we see the question of this post; problem: add, using jQuery, a class to all tags a possessing the attribute target set to _blank !
Articles Tagged 'target'
How to select a group of tags that have no children of a certain type
iPhone: Create a way to respond to events that cross class
Normally an event, which is nothing but a message is fixed (set and implemented) in the same class or context, the function or procedure "caller". o in un UIViewController . For example if we add a button UIButton via code (programmatically), we can find our class in a UIView or a UIViewController . In both cases the task allocation and initialization of the button will be followed by the setting of target that should receive a message when it "clicks" the button, type:
1 2 3 4 5 6 7 8 9 | [ UIButton buttonWithType : UIButtonTypeRoundedRect ] ; UIButton * button = [UIButton buttonWithType: UIButtonTypeRoundedRect]; 10 , 180 , 300 , 30 ) ; bottone.frame = CGRectMake (10, 180, 300, 30); @ "Press me" forState : UIControlStateNormal ] ; [Button setTitle: @ "Press me" forState: UIControlStateNormal]; / / Decide who should receive the message UIControlEventTouchUpInside self action : @selector ( onButtonClicked ) forControlEvents : UIControlEventTouchUpInside ] ; [AddTarget button: self action: @ selector (onButtonClicked) forControlEvents: UIControlEventTouchUpInside]; / / ... void ) onButtonClicked { - (Void) {onButtonClicked / / ... } |
Line 5 of the code shown above decides who (subject) and what (method) "call" when our button is pressed. In the example illustrated above is also noticeable that the setting of the message of pressure is sent to the method onButtonClick implemented more below, then forming part of the same context (or class). potremmo inviare il nostro messaggio ad un qualsiasi altro oggetto, posto quindi al difuori del contesto in uso. The first consideration is obvious that we can do, then, is that by altering the parameters self and action we can send our message to any other object, then place also outside of the context in use. : Here's an example: a class UIApplicationDelegate create a UIViewController :
1 2 3 4 5 | / / / / MyAppDelegate.m / / SplashScreenController alloc ] ; splashScreenController = [SplashScreenController alloc]; splashScreenController.view ] ; [Window addSubview: splashScreenController.view]; |
associata al UIViewController stesso: The SplashScreenController exposes a method that allows you to animate the UIView associated with UIViewController same:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 | / / / / SplashScreenController.m / / void ) animateBackgroundDown { - (Void) {animateBackgroundDown nil context : nil ] ; [UIView beginAnimations: nil context: nil]; 0.75 ] ; [UIView setAnimationDuration: 0.75]; UIViewAnimationCurveEaseInOut ] ; [UIView setAnimationCurve: UIViewAnimationCurveEaseInOut]; self ] ; [UIView setAnimationDelegate: self]; @selector ( onAnimationFinished ) ] ; [UIView setAnimationDidStopSelector: @ selector (onAnimationFinished)]; CGRect ) { 0 , 480 , 320 , 480 } ; self.view.frame = (CGRect) {0, 480, 320, 480}; ; [UIView commitAnimations]; } / / ... void ) onAnimationFinished { - (Void) {onAnimationFinished "Animazione terminata" ) ; NSLog (@ "Animation terminated"); } |
. The above code shows a method defined inside the class SplashScreenController type UIViewController . ) onAnimationFinished definito più sotto, facente parte sempre della classe SplashScreenController . It does nothing but animate the UIView animating it down, and when the animation is complete, call (send a message to itself - hence self ) onAnimationFinished defined below, is part of the class always SplashScreenController . , non saremo informati della fine dell'animazione: It follows that in our myAppDelegate , when we invoke the method animateBackgroundDown , we will not be informed of the end of the animation:
1 2 3 4 | / / / / MyAppDelegate.m / / ; [SplashScreenController animateBackgroundDown]; |
What we want, instead, is to create a new version of animateBackgroundDown as to tell him where to send the message end animation and which method to call. In practice we want to make sure you can write in our class myAppDelegate :
1 2 3 4 5 6 7 8 | / / / / MyAppDelegate.m / / self selector : @selector ( onAnimationFinished ) ] ; [SplashScreenController animateBackgroundDown: self selector: @ selector (onAnimationFinished)]; / / ... void ) onAnimationFinished { - (Void) {onAnimationFinished "Animazione terminata" ) ; NSLog (@ "Animation terminated"); } |
, bensì in myAppDelegate . This time the method onAnimationFinished is not in the UIViewController , but in myAppDelegate . nel modo seguente: To do this simply change the method animateBackgroundDown in UIViewController as follows:
1 2 3 4 5 6 7 8 9 10 11 12 | / / / / SplashScreenController.m / / void ) animateBackgroundDown : ( id ) target selector : ( SEL ) selector { - (Void) animateBackgroundDown: (id) target selector: (SEL) selector { nil context : nil ] ; [UIView beginAnimations: nil context: nil]; 0.75 ] ; [UIView setAnimationDuration: 0.75]; UIViewAnimationCurveEaseInOut ] ; [UIView setAnimationCurve: UIViewAnimationCurveEaseInOut]; target ] ; [UIView setAnimationDelegate: target]; selector ] ; [UIView setAnimationDidStopSelector: selector]; CGRect ) { 0 , 480 , 320 , 480 } ; self.view.frame = (CGRect) {0, 480, 320, 480}; ; [UIView commitAnimations]; } |
). Now we have a method that accepts the "context" ( target ) and the method to call ( selector ). a qualsiasi altro “oggetto” / classe in grado di riceverlo. Now, when the animation ends, the message AnimationDidStop will be sent to myAppDelegate any other "object" / class that can receive it.
Very short snippet: jQuery auto target blank link
Nothing new, but the sign to remind me: how to add an image to all the links that open a new page:
1 | ) . addClass ( 'external' ) ; jQuery ('a [@ target = _blank]'). addClass ('external'); |






Latest Comments
Mark : Thank you very much, I've lit
I solved it by setting [cc_objc] / / OptionViewController.m - ...
Giovambattista Fazioli : @ Mark: I suggest you think a more correct approach. If you run the subclass of the tab ...
Mark : Excuse the spam .. I noticed that there is an error .. here is the correction [cc_objc] / PrimaClasse.h ** ** / # import ...
Marco : forgotten .. in [cci] OptionViewController [/ cci] for [cci] @ syntetize [/ cci] I put the delegate
louis : very clear and simple I have to admit that writing a pa hardly use delegates created by ...