BuySellAds.com

If you like my tutorials, you will love my book . It is chockful of advanced programming techniques and the only comprehensive barcode reference for serious iOS developers.
Our DNA is written in Objective-C
Jump

“Are You a Cocoa Crack?” Quiz (2)

It’s been more than half a year since I published the first installment of this Quiz aimed at Cocoa Cracks. Back then people seemed to like the challenges I presented. So I collected a few more nuggets. If you ever stumbled on an crash or strange result that you did not expect, then mail it to me.

These questions will show if you are really the Cocoa Crack you like to believe to be. To see the answer highlight the answer text with your mouse. No peeking! Respond in the comments how many you got correct.

Quiz: Warm Up. Your UI designer gave you a PNG with the instruction “just tile this in the background” of a UIView. Do you have to subclass UIView, overriding the drawRect of the view and performing drawImage for all tiles? Or is there a simpler method?

Answer: You create a UIImage by loading the PNG and then create a “color” from it with [UIColor colorWithPatternImage:image]. Then you apply this as the background color of the view.


Quiz: Suddenly your app crashes and when the debugger opens it first loads lots of stack frames. All you did is override a property like shown below. What’s the bug? Bonus Question: where’s the memory leak?

- (void) setTextColor:(UIColor *)newTextColor
{
	if (newTextColor != textColor)
	{
		[textColor release];
 
		if (newTextColor)
		{
			self.textColor = [newTextColor retain];
		}
		else // default
		{
			self.textColor = [[UIColor whiteColor] retain];
		}
		bubbleView.highlightedTextColor = textColor;
	}
}

Answer: You have an endless recursion. self.textColor is a simplified way to write [self setTextColor:]. So this method keeps calling itself until the stack is full and your app gets terminated. The leak is calling retain on an assignment to a retaining property. But if you fix the crashing bug by removing both self then there is no leak.


Quiz: You want to draw two lines in a drawRect, a horizontal black line and a white line 1 pixel below it. So you write the following code. But instead of the intended result you get this picture in magnification, the black is dark gray and the white is a lighter shade of gray. Why is that and how would you fix it?

CGContextRef currentContext = UIGraphicsGetCurrentContext();
 
// Draw a black line at the top and a white line 1 pixel below
 
CGContextSetLineWidth(currentContext, 1);
 
CGContextSetRGBStrokeColor(currentContext, 0.0, 0.0, 0.0, 1.0); // Black
CGContextMoveToPoint(currentContext, 0, 0); // top left
CGContextAddLineToPoint(currentContext, rect.size.width, 0); // to top right
CGContextStrokePath(currentContext);
 
CGContextSetRGBStrokeColor(currentContext, 1.0, 1.0, 1.0, 1.0); // White
CGContextMoveToPoint(currentContext, 0, 1); // left
CGContextAddLineToPoint(currentContext, rect.size.width, 1);
CGContextStrokePath(currentContext);

Answer: Core Graphics does not work on pixels directly, that’s why you use floating point numbers for coordinates. It works on coordinates and the resulting bitmap is always rendered. Half of the line width is always applied half a unit to each side of the line. To remedy this you need to move the coordinates of the lines by half a unit up or down.

(Thanks to Michael Kaye for sending this in)


Quiz: You have a UITableView and would like for it to have rounded corners. What’s the fastest way to achieve that? Which header is necessary?

Answer: You can have any UIView have rounded corners by setting the cornerRadius property of it’s CALayer. The layer of a UIView is actually what’s responsible for drawing the contents of the view. You need: to import


Quiz: You have created a UIViewController which shows a UIWebView and has a navigation bar. You want to set the title on the bar to be the same as the title of the HTML document once loading has finished. Would you need to parse the HTML with NSScanner to find the tag and extract it? Or is there a simpler method?</p> <p><strong>Answer:</strong> <span style="color: #fbfbfb">In the webViewDidFinishLoad: delegate method you retrieve the title via javascript and set it like that. self.title = [webView stringByEvaluatingJavaScriptFromString: @”document.title”];<br /> </span></p> <hr /> <p><strong>Quiz: </strong>You have written code to load some UIImages in the background (performSelectorOnBackgroundThread or NSInvocationOperation). The loading code calls the method below to resize the loaded image. This has “always working before”, but suddenly you keep getting a EXC_BAD_ACESS on the line marked. You have double checked all retains and even set NSZombieEnabled to YES because usually you get this message if you are using an overreleased object. But that did not fix the problem. What’s the reason for the crash and how would you fix it?</p> <div class="wp_codebox"><table><tr id="p186621"><td class="code" id="p1866code21"><pre class="objc" style="font-family:monospace;"><span style="color: #002200;">+</span> <span style="color: #002200;">(</span>UIImage<span style="color: #002200;">*</span><span style="color: #002200;">)</span>imageWithImage<span style="color: #002200;">:</span><span style="color: #002200;">(</span>UIImage<span style="color: #002200;">*</span><span style="color: #002200;">)</span>image scaledToSize<span style="color: #002200;">:</span><span style="color: #002200;">(</span>CGSize<span style="color: #002200;">)</span>newSize; <span style="color: #002200;">{</span> UIGraphicsBeginImageContext<span style="color: #002200;">(</span> newSize <span style="color: #002200;">)</span>; <span style="color: #002200;">[</span>image drawInRect<span style="color: #002200;">:</span>CGRectMake<span style="color: #002200;">(</span><span style="color: #2400d9;">0</span>,<span style="color: #2400d9;">0</span>,newSize.width,newSize.height<span style="color: #002200;">)</span><span style="color: #002200;">]</span>; <span style="color: #11740a; font-style: italic;">// &lt;- crash</span> UIImage<span style="color: #002200;">*</span> newImage <span style="color: #002200;">=</span> UIGraphicsGetImageFromCurrentImageContext<span style="color: #002200;">(</span><span style="color: #002200;">)</span>; UIGraphicsEndImageContext<span style="color: #002200;">(</span><span style="color: #002200;">)</span>;   <span style="color: #a61390;">return</span> newImage; <span style="color: #002200;">}</span></pre></td></tr></table></div> <p><strong>Answer:</strong> <span style="color: #fbfbfb">UIKit is not thread-safe. Therefore all drawing via UIKit needs to happen on the main thread. The UIGraphicsBeginImageContext works to create the context, but the memory for it is owned to the main thread and trying to access it with drawInRect from another thread is causing this exception. To fix it you need to rewrite this method to create your own bitmap context on the non-main thread so that you then own the memory for it. After creating the bitmap context you draw the image to it with CGContextDrawImage and then create a new CGImage with CGBitmapContextCreateImage. From the CGImage you create a UIImage to return from the method.</span></p> <hr /> <p><strong>Quiz: </strong>Off the top of your head: how many methods do you know of having a piece of code contained in one method being performed in the background? Which?</p> <p><strong>Answer:</strong> <span style="color: #fbfbfb">Correct Answers are: performSelectorOnBackgroundThread and creating an NSInvocationOperation from the selector as those work on an existing method. Creating an NSOperation sub-class or manual threading with NSThread are also valid answers, but those require that you move the code into a new class or need to be well versed with threading voodoo.<br /> </span></p> <hr /> <p>So how many answers did you know? Be honest! If you also have a Cocoa riddle like these to contribute please mail them directly to me (oliver@drobnik.com) and I will publish them in this format.</p> <div class="sharedaddy sd-sharing-enabled"><div class="robots-nocontent sd-block sd-social sd-social-icon sd-sharing"><h3 class="sd-title">Sharing:</h3><div class="sd-content"><ul><li class="share-twitter"><a rel="nofollow" data-shared="sharing-twitter-1866" class="share-twitter sd-button share-icon no-text" href="http://www.cocoanetics.com/2010/02/are-you-a-cocoa-crack-quiz-2/?share=twitter" target="_blank" title="Click to share on Twitter"><span></span><span class="sharing-screen-reader-text">Click to share on Twitter (Opens in new window)</span></a></li><li class="share-facebook"><a rel="nofollow" data-shared="sharing-facebook-1866" class="share-facebook sd-button share-icon no-text" href="http://www.cocoanetics.com/2010/02/are-you-a-cocoa-crack-quiz-2/?share=facebook" target="_blank" title="Share on Facebook"><span></span><span class="sharing-screen-reader-text">Share on Facebook (Opens in new window)</span></a></li><li class="share-pocket"><a rel="nofollow" data-shared="" class="share-pocket sd-button share-icon no-text" href="http://www.cocoanetics.com/2010/02/are-you-a-cocoa-crack-quiz-2/?share=pocket" target="_blank" title="Click to share on Pocket"><span></span><span class="sharing-screen-reader-text">Click to share on Pocket (Opens in new window)</span></a></li><li class="share-google-plus-1"><a rel="nofollow" data-shared="sharing-google-1866" class="share-google-plus-1 sd-button share-icon no-text" href="http://www.cocoanetics.com/2010/02/are-you-a-cocoa-crack-quiz-2/?share=google-plus-1" target="_blank" title="Click to share on Google+"><span></span><span class="sharing-screen-reader-text">Click to share on Google+ (Opens in new window)</span></a></li><li class="share-press-this"><a rel="nofollow" data-shared="" class="share-press-this sd-button share-icon no-text" href="http://www.cocoanetics.com/2010/02/are-you-a-cocoa-crack-quiz-2/?share=press-this" target="_blank" title="Click to Press This!"><span></span><span class="sharing-screen-reader-text">Click to Press This! (Opens in new window)</span></a></li><li class="share-linkedin"><a rel="nofollow" data-shared="sharing-linkedin-1866" class="share-linkedin sd-button share-icon no-text" href="http://www.cocoanetics.com/2010/02/are-you-a-cocoa-crack-quiz-2/?share=linkedin" target="_blank" title="Click to share on LinkedIn"><span></span><span class="sharing-screen-reader-text">Click to share on LinkedIn (Opens in new window)</span></a></li><li class="share-reddit"><a rel="nofollow" data-shared="" class="share-reddit sd-button share-icon no-text" href="http://www.cocoanetics.com/2010/02/are-you-a-cocoa-crack-quiz-2/?share=reddit" target="_blank" title="Click to share on Reddit"><span></span><span class="sharing-screen-reader-text">Click to share on Reddit (Opens in new window)</span></a></li><li class="share-email"><a rel="nofollow" data-shared="" class="share-email sd-button share-icon no-text" href="http://www.cocoanetics.com/2010/02/are-you-a-cocoa-crack-quiz-2/?share=email" target="_blank" title="Click to email this to a friend"><span></span><span class="sharing-screen-reader-text">Click to email this to a friend (Opens in new window)</span></a></li><li class="share-print"><a rel="nofollow" data-shared="" class="share-print sd-button share-icon no-text" href="http://www.cocoanetics.com/2010/02/are-you-a-cocoa-crack-quiz-2/#print" target="_blank" title="Click to print"><span></span><span class="sharing-screen-reader-text">Click to print (Opens in new window)</span></a></li><li><a href="#" class="sharing-anchor sd-button share-more"><span>More</span></a></li><li class="share-end"></li></ul><div class="sharing-hidden"><div class="inner" style="display: none;"><ul><li class="share-stumbleupon"><a rel="nofollow" data-shared="" class="share-stumbleupon sd-button share-icon no-text" href="http://www.cocoanetics.com/2010/02/are-you-a-cocoa-crack-quiz-2/?share=stumbleupon" target="_blank" title="Click to share on StumbleUpon"><span></span><span class="sharing-screen-reader-text">Click to share on StumbleUpon (Opens in new window)</span></a></li><li class="share-tumblr"><a rel="nofollow" data-shared="" class="share-tumblr sd-button share-icon no-text" href="http://www.cocoanetics.com/2010/02/are-you-a-cocoa-crack-quiz-2/?share=tumblr" target="_blank" title="Click to share on Tumblr"><span></span><span class="sharing-screen-reader-text">Click to share on Tumblr (Opens in new window)</span></a></li><li class="share-end"></li><li class="share-pinterest"><a rel="nofollow" data-shared="sharing-pinterest-1866" class="share-pinterest sd-button share-icon no-text" href="http://www.cocoanetics.com/2010/02/are-you-a-cocoa-crack-quiz-2/?share=pinterest" target="_blank" title="Click to share on Pinterest"><span></span><span class="sharing-screen-reader-text">Click to share on Pinterest (Opens in new window)</span></a></li><li class="share-end"></li></ul></div></div></div></div></div><div class='sharedaddy sd-block sd-like jetpack-likes-widget-wrapper jetpack-likes-widget-unloaded' id='like-post-wrapper-39982308-1866-553f9862f1b60' data-src='//widgets.wp.com/likes/#blog_id=39982308&post_id=1866&origin=www.cocoanetics.com&obj_id=39982308-1866-553f9862f1b60' data-name='like-post-frame-39982308-1866-553f9862f1b60'><h3 class='sd-title'>Like this:</h3><div class='likes-widget-placeholder post-likes-widget-placeholder' style='height:55px'><span class='button'><span>Like</span></span> <span class="loading">Loading...</span></div><span class='sd-text-color'></span><a class='sd-link-color'></a></div> <a class="FlattrButton" style="display:none;" href="http://www.cocoanetics.com/2010/02/are-you-a-cocoa-crack-quiz-2/" title=" “Are You a Cocoa Crack?” Quiz (2)" rev="flattr;uid:dr_touch;language:en_GB;category:text;tags:blog;popout:0;">It’s been more than half a year since I published the first installment of this Quiz aimed at Cocoa Cracks. Back then people seemed to like the challenges I presented....</a> <hr class="end_of_article" /> <div class="clear"></div> <p id="tags"></p> <p id="categories"><strong>Categories: </strong><a href="http://www.cocoanetics.com/category/qa/" rel="category tag">Q&A</a></p> <div class="clear"></div> </div><!--/end entry--> </div><!--/end post--> <div class="clear"></div> <div id="nav-below" class="navigation"> <div class="nav-previous"><a href="http://www.cocoanetics.com/2010/02/uiimageview-touch-handling-uibutton/" rel="prev"><span class="meta-nav">←</span> UIImageView + Touch Handling = UIButton</a></div> <div class="nav-next"><a href="http://www.cocoanetics.com/2010/02/app-information-string-tokens/" rel="next">App Information String Tokens <span class="meta-nav">→</span></a></div> </div><!-- #nav-below --> <div class="clear"></div> <h3 id="comments"> 5 Comments <a href="#respond" title="Leave a comment">»</a></h3> <ol class="commentlist" id="singlecomments"> <li class="comment even thread-even depth-1" id="li-comment-1551"> <div id="comment-1551"> <div class="comment-author vcard"> <img alt='' src='http://1.gravatar.com/avatar/369b3f412bd98b65e819e62880e00564?s=48&d=http%3A%2F%2F1.gravatar.com%2Favatar%2Fad516503a11cd5ca435acc9bb6523536%3Fs%3D48&r=G' class='avatar avatar-48 photo' height='48' width='48' /> <div class="commentmetadata"> <cite class="fn">pbernery</cite> <div class="comment-date"> <a href="http://www.cocoanetics.com/2010/02/are-you-a-cocoa-crack-quiz-2/#comment-1551"> March 8, 2010 | 8:52 pm </a> </div> </div> </div> <p>Really nice Quiz Dr.</p> <p>However I don’t agree with the drawRect and two lines question: antialiasing is enabled by default when using CG methods and when it is enabled, you get what you described in your point.<br /> To disable it and get thin, clear lines, simply set it to disabled:</p> <p>CGContextSetShouldAntialias(context, NO);</p> <div class="reply"> </div> <div class="clear"></div> </div> </li><!-- #comment-## --> <li class="comment byuser comment-author-c0diq odd alt thread-odd thread-alt depth-1" id="li-comment-4231"> <div id="comment-4231"> <div class="comment-author vcard"> <img alt='' src='http://0.gravatar.com/avatar/e77ec2fb252946e03b3dde99d77ec75a?s=48&d=http%3A%2F%2F0.gravatar.com%2Favatar%2Fad516503a11cd5ca435acc9bb6523536%3Fs%3D48&r=G' class='avatar avatar-48 photo' height='48' width='48' /> <div class="commentmetadata"> <cite class="fn">c0diq</cite> <div class="comment-date"> <a href="http://www.cocoanetics.com/2010/02/are-you-a-cocoa-crack-quiz-2/#comment-4231"> February 10, 2012 | 1:06 am </a> </div> </div> </div> <p>textColor quiz: You didn’t specify the property was declared retained. It could have been assign only (although that’d be weird.</p> <p>UIGraphicsBeginImageContext quiz: Since iOS4 it is thread safe.</p> <p>background methods: You can use dispatch queues too with blocks.</p> <p>UITableView rounded corner: I believe the fastest way would be using a UIImage as a mark.</p> <div class="reply"> </div> <div class="clear"></div> </div> </li><!-- #comment-## --> <li class="comment byuser comment-author-c0diq even thread-even depth-1" id="li-comment-4232"> <div id="comment-4232"> <div class="comment-author vcard"> <img alt='' src='http://0.gravatar.com/avatar/e77ec2fb252946e03b3dde99d77ec75a?s=48&d=http%3A%2F%2F0.gravatar.com%2Favatar%2Fad516503a11cd5ca435acc9bb6523536%3Fs%3D48&r=G' class='avatar avatar-48 photo' height='48' width='48' /> <div class="commentmetadata"> <cite class="fn">c0diq</cite> <div class="comment-date"> <a href="http://www.cocoanetics.com/2010/02/are-you-a-cocoa-crack-quiz-2/#comment-4232"> February 10, 2012 | 1:06 am </a> </div> </div> </div> <p>mark -> mask</p> <div class="reply"> </div> <div class="clear"></div> </div> </li><!-- #comment-## --> <li class="comment byuser comment-author-iKy1e odd alt thread-odd thread-alt depth-1" id="li-comment-4695"> <div id="comment-4695"> <div class="comment-author vcard"> <img alt='' src='http://1.gravatar.com/avatar/5a321423163e276e074caadc52c367a6?s=48&d=http%3A%2F%2F1.gravatar.com%2Favatar%2Fad516503a11cd5ca435acc9bb6523536%3Fs%3D48&r=G' class='avatar avatar-48 photo' height='48' width='48' /> <div class="commentmetadata"> <cite class="fn">iKy1e</cite> <div class="comment-date"> <a href="http://www.cocoanetics.com/2010/02/are-you-a-cocoa-crack-quiz-2/#comment-4695"> August 29, 2012 | 1:02 am </a> </div> </div> </div> <p>The UIImage performSelectorOnBackgroundThread crash is out of date isn’t it? I seem to remember that with iOS 5 (or 6?) UIImage was made thread safe for simple operations like this. Wasn’t it?</p> <div class="reply"> </div> <div class="clear"></div> </div> </li><!-- #comment-## --> </ol> <div id="comment_pagination"> <div id="older"> </div> <div id="newer"> </div> </div> <h3 id="trackbacks"> Trackbacks</h3> <ol id="trackbacklist"> <li class="" id="comment-6113"> <cite> <a href='http://www.cocoanetics.com/2013/08/ios-developer-challenge/' rel='external nofollow' class='url'>iOS Developer Challenge | Cocoanetics</a> </cite> </li> </ol> <div id="respond"> <h3> Leave a Comment </h3> <p id="cancel-comment-reply"> <a rel="nofollow" id="cancel-comment-reply-link" href="/2010/02/are-you-a-cocoa-crack-quiz-2/#respond" style="display:none;">Cancel Reply</a> </p> <form action="http://www.cocoanetics.com/wp-comments-post.php" method="post" id="commentform"> <p> <input class="field" type="text" name="author" id="author" value="" tabindex="1" /> <label for="author"> Name </label> </p> <p> <input type="text" name="email" id="email" value="" tabindex="2" class="field" /> <label for="email"> Mail (will not be published) </label> </p> <p> <input type="text" name="url" id="url" value="" tabindex="3" class="field" /> <label for="url"> Website </label> </p> <input type='hidden' name='comment_post_ID' value='1866' id='comment_post_ID' /> <input type='hidden' name='comment_parent' id='comment_parent' value='0' /> <input type="hidden" name="redirect_to" value="/2010/02/are-you-a-cocoa-crack-quiz-2/" /> <p> <textarea name="comment" class="field" id="comment" cols="10" rows="10" tabindex="4"></textarea> </p> <p style="display: none;"><input type="hidden" id="akismet_comment_nonce" name="akismet_comment_nonce" value="bf308272f0" /></p><p class="comment-subscription-form"><input type="checkbox" name="subscribe_comments" id="subscribe_comments" value="subscribe" style="width: auto; -moz-appearance: checkbox; -webkit-appearance: checkbox;" /> <label class="subscribe-label" id="subscribe-label" for="subscribe_comments">Notify me of follow-up comments by email.</label></p><p class="comment-subscription-form"><input type="checkbox" name="subscribe_blog" id="subscribe_blog" value="subscribe" style="width: auto; -moz-appearance: checkbox; -webkit-appearance: checkbox;" /> <label class="subscribe-label" id="subscribe-blog-label" for="subscribe_blog">Notify me of new posts by email.</label></p><p style="display: none;"><input type="hidden" id="ak_js" name="ak_js" value="76"/></p> <p> <input name="submit" type="submit" id="submit" class="button" tabindex="5" value="Submit Comment" /> </p> </form> </div> </div><!--/content--> </div> <!--/main--> <div id="copyright_footer"> <div id="copyright_left"> <ul id="register_login_links"> <li><a class="sign_in_link" href="http://www.cocoanetics.com/wp-login.php?redirect_to=http%3A%2F%2Fwww.cocoanetics.com%2F2010%2F02%2Fare-you-a-cocoa-crack-quiz-2%2F">Log In</a></li> <li><a class="register_link" href="http://www.cocoanetics.com/wp-login.php?redirect_to=http%3A%2F%2Fwww.cocoanetics.com%2F2010%2F02%2Fare-you-a-cocoa-crack-quiz-2%2F&action=register">Register</a></li> </ul> </div> <div id="copyright_right"> © 2015 <span class="url fn org"> <a href="http://www.drobnik.com/">Drobnik KG</a> </span> </div> </div> </div> </div> <!--/wrapper--> <div id="footer"> <div id="text-4" class="widget widget_text"><h3 class="widgettitle">CC</h3> <div class="textwidget"><p>License:<br /> <a href="http://creativecommons.org/licenses/by-nc-nd/3.0/"><img class="alignleft size-full wp-image-4229" src="/files/cc-image.jpg" alt="" width="88" height="31" /></a></p> </div> </div><div id="text-10" class="widget widget_text"><h3 class="widgettitle">AddThis</h3> <div class="textwidget"><script type="text/javascript"> var addthis_share = { templates: { twitter: '{{title}}: {{url}} via @Cocoanetics' } } </script></div> </div></div> <div id="footer_footer"></div> <!--/footer--> <!-- tracker added by Ultimate Google Analytics plugin v1.6.0: http://www.oratransplant.nl/uga --> <script type="text/javascript"> var gaJsHost = (("https:" == document.location.protocol) ? "https://ssl." : "http://www."); document.write(unescape("%3Cscript src='" + gaJsHost + "google-analytics.com/ga.js' type='text/javascript'%3E%3C/script%3E")); </script> <script type="text/javascript"> var pageTracker = _gat._getTracker("UA-260144-2"); pageTracker._initData(); pageTracker._trackPageview(); </script> <!-- Advertising Manager v3.5.1 (1.232 seconds.) --> <div style="display:none"> <div class="grofile-hash-map-369b3f412bd98b65e819e62880e00564"> </div> <div class="grofile-hash-map-e77ec2fb252946e03b3dde99d77ec75a"> </div> <div class="grofile-hash-map-5a321423163e276e074caadc52c367a6"> </div> </div> <script type="text/javascript"> WPCOM_sharing_counts = {"http:\/\/www.cocoanetics.com\/2010\/02\/are-you-a-cocoa-crack-quiz-2\/":1866} </script> <script type="text/javascript"> var windowOpen; jQuery(document).on( 'ready post-load', function(){ jQuery( 'a.share-twitter' ).on( 'click', function() { if ( 'undefined' !== typeof windowOpen ){ // If there's another sharing window open, close it. windowOpen.close(); } windowOpen = window.open( jQuery(this).attr( 'href' ), 'wpcomtwitter', 'menubar=1,resizable=1,width=600,height=350' ); return false; }); }); </script> <script type="text/javascript"> var windowOpen; jQuery(document).on( 'ready post-load', function(){ jQuery( 'a.share-facebook' ).on( 'click', function() { if ( 'undefined' !== typeof windowOpen ){ // If there's another sharing window open, close it. windowOpen.close(); } windowOpen = window.open( jQuery(this).attr( 'href' ), 'wpcomfacebook', 'menubar=1,resizable=1,width=600,height=400' ); return false; }); }); </script> <script type="text/javascript"> var windowOpen; jQuery(document).on( 'ready post-load', function(){ jQuery( 'a.share-pocket' ).on( 'click', function() { if ( 'undefined' !== typeof windowOpen ){ // If there's another sharing window open, close it. windowOpen.close(); } windowOpen = window.open( jQuery(this).attr( 'href' ), 'wpcompocket', 'menubar=1,resizable=1,width=450,height=450' ); return false; }); }); </script> <script type="text/javascript"> var windowOpen; jQuery(document).on( 'ready post-load', function(){ jQuery( 'a.share-google-plus-1' ).on( 'click', function() { if ( 'undefined' !== typeof windowOpen ){ // If there's another sharing window open, close it. windowOpen.close(); } windowOpen = window.open( jQuery(this).attr( 'href' ), 'wpcomgoogle-plus-1', 'menubar=1,resizable=1,width=480,height=550' ); return false; }); }); </script> <script type="text/javascript"> var windowOpen; jQuery(document).on( 'ready post-load', function(){ jQuery( 'a.share-linkedin' ).on( 'click', function() { if ( 'undefined' !== typeof windowOpen ){ // If there's another sharing window open, close it. windowOpen.close(); } windowOpen = window.open( jQuery(this).attr( 'href' ), 'wpcomlinkedin', 'menubar=1,resizable=1,width=580,height=450' ); return false; }); }); </script> <div id="sharing_email" style="display: none;"> <form action="/2010/02/are-you-a-cocoa-crack-quiz-2/" method="post"> <label for="target_email">Send to Email Address</label> <input type="email" name="target_email" id="target_email" value="" /> <label for="source_name">Your Name</label> <input type="text" name="source_name" id="source_name" value="" /> <label for="source_email">Your Email Address</label> <input type="email" name="source_email" id="source_email" value="" /> <img style="float: right; display: none" class="loading" src="http://www.cocoanetics.com/wp-content/plugins/jetpack/modules/sharedaddy/images/loading.gif" alt="loading" width="16" height="16" /> <input type="submit" value="Send Email" class="sharing_send" /> <a href="#cancel" class="sharing_cancel">Cancel</a> <div class="errors errors-1" style="display: none;"> Post was not sent - check your email addresses! </div> <div class="errors errors-2" style="display: none;"> Email check failed, please try again </div> <div class="errors errors-3" style="display: none;"> Sorry, your blog cannot share posts by email. </div> </form> </div> <script type="text/javascript"> var windowOpen; jQuery(document).on( 'ready post-load', function(){ jQuery( 'a.share-tumblr' ).on( 'click', function() { if ( 'undefined' !== typeof windowOpen ){ // If there's another sharing window open, close it. windowOpen.close(); } windowOpen = window.open( jQuery(this).attr( 'href' ), 'wpcomtumblr', 'menubar=1,resizable=1,width=450,height=450' ); return false; }); }); </script> <script type="text/javascript"> jQuery(document).on('ready', function(){ jQuery('body').on('click', 'a.share-pinterest', function(e){ e.preventDefault(); // Load Pinterest Bookmarklet code var s = document.createElement("script"); s.type = "text/javascript"; s.src = window.location.protocol + "//assets.pinterest.com/js/pinmarklet.js?r=" + ( Math.random() * 99999999 ); var x = document.getElementsByTagName("script")[0]; x.parentNode.insertBefore(s, x); // Trigger Stats var s = document.createElement("script"); s.type = "text/javascript"; s.src = this + ( this.toString().indexOf( '?' ) ? '&' : '?' ) + 'js_only=1'; var x = document.getElementsByTagName("script")[0]; x.parentNode.insertBefore(s, x); }); }); </script> <script type='text/javascript' src='http://www.cocoanetics.com/wp-content/plugins/akismet/_inc/form.js?ver=3.1.1'></script> <script type='text/javascript' src='http://www.cocoanetics.com/wp-includes/js/comment-reply.min.js?ver=4.1.4'></script> <script type='text/javascript' src='http://s0.wp.com/wp-content/js/devicepx-jetpack.js?ver=201518'></script> <script type='text/javascript' src='http://s.gravatar.com/js/gprofiles.js?ver=2015Apraa'></script> <script type='text/javascript'> /* <![CDATA[ */ var WPGroHo = {"my_hash":""}; /* ]]> */ </script> <script type='text/javascript' src='http://www.cocoanetics.com/wp-content/plugins/jetpack/modules/wpgroho.js?ver=4.1.4'></script> <script type='text/javascript' src='http://www.cocoanetics.com/wp-content/plugins/jetpack/_inc/postmessage.js?ver=3.4.3'></script> <script type='text/javascript' src='http://www.cocoanetics.com/wp-content/plugins/jetpack/_inc/jquery.jetpack-resize.js?ver=3.4.3'></script> <script type='text/javascript' src='http://www.cocoanetics.com/wp-content/plugins/jetpack/_inc/jquery.inview.js?ver=3.4.3'></script> <script type='text/javascript' src='http://www.cocoanetics.com/wp-content/plugins/jetpack/modules/likes/queuehandler.js?ver=3.4.3'></script> <script type='text/javascript'> /* <![CDATA[ */ var sharing_js_options = {"lang":"en","counts":"1"}; /* ]]> */ </script> <script type='text/javascript' src='http://www.cocoanetics.com/wp-content/plugins/jetpack/modules/sharedaddy/sharing.js?ver=3.4.3'></script> <script type="text/javascript"> (function() { var s = document.createElement('script'), t = document.getElementsByTagName('script')[0]; s.type = 'text/javascript'; s.async = true; s.src = 'http://api.flattr.com/js/0.6/load.js?mode=auto'; t.parentNode.insertBefore(s, t); })(); </script> <iframe src='http://widgets.wp.com/likes/master.html?ver=20141028#ver=20141028&mp6=1' scrolling='no' id='likes-master' name='likes-master' style='display:none;'></iframe> <div id='likes-other-gravatars'><div class="likes-text"><span>%d</span> bloggers like this:</div><ul class="wpl-avatars sd-like-gravatars"></ul></div> <script type='text/javascript' src='http://stats.wp.com/e-201518.js' async defer></script> <script type='text/javascript'> _stq = window._stq || []; _stq.push([ 'view', {v:'ext',j:'1:3.4.3',blog:'39982308',post:'1866',tz:'2'} ]); _stq.push([ 'clickTrackerInit', '39982308', '1866' ]); </script> <script type="text/javascript"> jQuery(document).ready(function(){ jQuery("ul.menu").superfish(); jQuery("#searchfield").attr("value","Search..."); jQuery("#searchfield").focusin(function(){ jQuery("#searchfield").attr("value",""); }); jQuery("#searchfield").focusout(function() { var formvalue = jQuery("#searchfield").attr("value"); if (formvalue=="") { jQuery("#searchfield").attr("value", "Search..."); } }); if (navigator.userAgent.indexOf('Safari') != -1 && navigator.userAgent.indexOf('Mac') != -1 && navigator.userAgent.indexOf('Chrome') == -1) { jQuery('html').addClass('safari_mac'); } }); </script> <script type="text/javascript"> jQuery("li.cat-item a").each(function(){ // Remove Titles from wp_list_categories jQuery(this).removeAttr('title'); }) jQuery("li.page_item a").each(function(){ // Remove Titles from wp_list_pages jQuery(this).removeAttr('title'); }) </script> </body> </html>