For the past couple of days I have been busy moving, so there hasn’t been any blog updates. Instead of staying up till 3am coding I’ve been reorganizing trying to get situated at the new apartment. First time had the weekend off in a long time.
The goal of the library was to create a greeter. The greeter library function was to be able to give a formal and informal greeting when given a first and last name. It’d also have to support two languages English and Spanish. Lastly, the code would have to be reusable and easy to type ‘G$()’. The ‘G$()’ Function would mimic the jQuery $ operator to replace new to create function constructors. Also similarly to jQuery our new library/framework would have another library within it.
The first step was to structure safe code. Which meant to use an IIFE. Next step was to create a click event on login to set a greeting depending on the language chosen. Create a new object first name and last name. Then use the greeter to set a heading on html with an ID of greeting with the language chosen. The html greeting method sets up the jQuery object just needs a selector and have the language set appropriately. Next I needed to set up a click event for login. The ID was set up as login and use jQuery function to pass it the login ID and a click event and pass it a function object made on the fly with a function expression. After this I made a brand new object using G$() my object and pretend to know login was John Doe and hide entire select login drop with .hide. Lastly create a method chaining function as a single line of code.
Set language depending on what’s chosen in the select box. Chain a method that updates the H1 ID of greeting, set formal greeting to true and lastly .log to log it to the console.
That was it! A mini library/ framework that mimics the structure of jQuery and its approach of chain-able methods.<div class='sharedaddy sd-block sd-like jetpack-likes-widget-wrapper jetpack-likes-widget-unloaded' id='like-post-wrapper-155635758-373-5ce3d4b8c2a17' data-src='https://widgets.wp.com/likes/#blog_id=155635758&post_id=373&origin=trilamanila.com&obj_id=155635758-373-5ce3d4b8c2a17' data-name='like-post-frame-155635758-373-5ce3d4b8c2a17'><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>