{"id":4,"date":"2013-07-03T17:35:08","date_gmt":"2013-07-03T17:35:08","guid":{"rendered":"http:\/\/www.webmasterninjas.com\/developer\/?p=4"},"modified":"2019-04-22T21:55:26","modified_gmt":"2019-04-22T21:55:26","slug":"javascript-modular-design","status":"publish","type":"post","link":"https:\/\/www.webmasterninjas.com\/developer\/javascript-modular-design","title":{"rendered":"Javascript Modular Design"},"content":{"rendered":"<p>So I just completed my update of my Facebook app <a title=\"My Amazon Wishlist\" href=\"https:\/\/apps.facebook.com\/importamazonwishlist\/\" target=\"_blank\" rel=\"noopener noreferrer\">My Amazon Wishlist<\/a>&nbsp; I converted all of my messy initialization and jquery UI event handling code into a nice neat single variable javascript module. &nbsp;It is sooooo much prettier&#8230;.cleaner, more modular (it&#8217;s right there in the name!), less likely to interfere with any other javascript includes. &nbsp;I briefly contemplated creating javascript objects for the lists&#8230;.if I were to recode it from the start that&#8217;s how I would do it, but for now I&#8217;ll leave it as is because cloning the objects is faster and it can stay as is until I decide to implement more features. &nbsp;The back-end is all php objects, and has made it incredibly easy to update and add features, as well as re-use in my wordpress plugin. &nbsp;I also updated from jQuery 1.8.1 to 1.10 and had to update a few deprecated function calls that were removed in 1.9 &#8230;.GO&nbsp;$(document).on(&#8216;click&#8217;, &#8216;id&#8217;, function(){});!&#8230;I also had to replace window.parent.document calls inside an iframe with &nbsp;with jQuery postmessage calls&#8230;.they actually turned out quite nicely&#8230;.you have to setup a listener in the parent frame, then in the iframe (or another website even..it solves the cross-domain problem). post the message to the parent. &nbsp;In my case I was sending multiple pieces of data, so I put it into an array, stringified it and passed it to the parent. &nbsp;One thing I would note&#8230;.in the listener you should make it so that it only accepts messages from the website you expect to be sending messages. &nbsp;Here&#8217;s the code from the iframe:<\/p>\n<p>var msgArray = new Object();<br \/>\nmsgArray[&#8216;newHeight&#8217;] = $(&#8216;#aws-item&#8217;).height().toString();<br \/>\nmsgArray[&#8216;listNo&#8217;] = listNo;<br \/>\nmsgArray[&#8216;itemNo&#8217;] = itemNo;<br \/>\nmsgArray[&#8216;iframeID&#8217;] = iframeID;<br \/>\nvar message = JSON.stringify(msgArray);<br \/>\nparent.window.postMessage(message, &#8216;*&#8217;);<\/p>\n<p>And so ends my first article for my new website! &nbsp;I think I&#8217;ll write the next one on how I localized (<span style=\"color: #000080;\"><span style=\"font-family: Calibri, sans-serif;\"><span style=\"font-size: medium;\"><span>L10N)&nbsp;<\/span><\/span><\/span><\/span>my WordPress plugin&nbsp;<a href=\"http:\/\/wordpress.org\/plugins\/easy-amazon-wishlist\/\">http:\/\/wordpress.org\/plugins\/easy-amazon-wishlist\/<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>So I just completed my update of my Facebook app My Amazon Wishlist&nbsp; I converted all of my messy initialization and jquery UI event handling code into a nice neat single variable javascript module. &nbsp;It is sooooo much prettier&#8230;.cleaner, more &hellip; <a href=\"https:\/\/www.webmasterninjas.com\/developer\/javascript-modular-design\">Continue reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[8,14],"tags":[16,17,15],"_links":{"self":[{"href":"https:\/\/www.webmasterninjas.com\/developer\/wp-json\/wp\/v2\/posts\/4"}],"collection":[{"href":"https:\/\/www.webmasterninjas.com\/developer\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.webmasterninjas.com\/developer\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.webmasterninjas.com\/developer\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.webmasterninjas.com\/developer\/wp-json\/wp\/v2\/comments?post=4"}],"version-history":[{"count":5,"href":"https:\/\/www.webmasterninjas.com\/developer\/wp-json\/wp\/v2\/posts\/4\/revisions"}],"predecessor-version":[{"id":40,"href":"https:\/\/www.webmasterninjas.com\/developer\/wp-json\/wp\/v2\/posts\/4\/revisions\/40"}],"wp:attachment":[{"href":"https:\/\/www.webmasterninjas.com\/developer\/wp-json\/wp\/v2\/media?parent=4"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.webmasterninjas.com\/developer\/wp-json\/wp\/v2\/categories?post=4"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.webmasterninjas.com\/developer\/wp-json\/wp\/v2\/tags?post=4"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}