background preloader

Javascript

Facebook Twitter

Minify Javascript Online / Online JavaScript Packer. Underscore.js. Underscore is a JavaScript library that provides a whole mess of useful functional programming helpers without extending any built-in objects. It’s the answer to the question: “If I sit down in front of a blank HTML page, and want to start being productive immediately, what do I need?” … and the tie to go along with jQuery's tux and Backbone's suspenders. Underscore provides 80-odd functions that support both the usual functional suspects: map, select, invoke — as well as more specialized helpers: function binding, javascript templating, deep equality testing, and so on. It delegates to built-in functions, if present, so modern browsers will use the native implementations of forEach, map, reduce, filter, every, some and indexOf. The project is hosted on GitHub.

You can report bugs and discuss features on the issues page, on Freenode in the #documentcloud channel, or send tweets to @documentcloud. Collection Functions (Arrays or Objects) _.every([true, 1, null, 'yes'], _.identity); => false. JavaScript Patterns. Validate.js. Lightweight JavaScript form validation library inspired by CodeIgniter. No dependencies, just over 2kb gzipped, and customizable! Validate.js (development - 16kb) validate.min.js (minified - 2.1kb) Example All of the fields were successfully validated! Features Validate form fields from over a dozen rules No dependencies Customizable messages Supply your own validation callbacks for custom rules Chainable customization methods for ease of declaration Conditionally validate certain form fields Works in all major browsers (even IE6!) Modeled off the CodeIgniter form validation API Installation and Usage Include the JavaScript file in your source Create the validation object with your desired rules.

FormValidator new FormValidator(formName, fields, callback) The FormValidator object is attached to the window upon loading validate.js. The formName passed in to validate must be the exact value of the name attribute of the form name (required) - The name attribute of the element. Custom Validation Rules. JustGage.com. Handsontable - jQuery grid editor. Excel-like grid editing with HTML & JavaScript. Unify Client-Side and Server-Side Rendering by Embedding JSON. Not many applications I work on these days are solely using the traditional server-side rendering model.

Neither do they employ 100% client-side rendering and templating. Usually it’s a mix in which the ‘old’ world meets the new world, giving rise to some interesting design decisions. In this article I want to explore a solution that combines both worlds while minimizing the duplication of rendering logic by embedding JSON in the view. Let’s introduce a simple example to illustrate the JSON embedding trick. It’s on GitHub, with several branches showing different approaches.

Say we have a screen containing a product list with paging: After the initial request to the server, the first page of products is shown. What duplication? We have two main goals: Code for rendering the table should be written onceUser-experience must be as smooth as possible (i.e. no visible flickering for AJAX updates of the initial page) Think about how you would implement this example. 01. 02. 03. 04. 05. 06. 07. 08.

Changing Times For Web Developers – 6 Tips You Should Read To Survive. The context of this post is about the changing times for a web developer, and I see a lot of web developers still lagging behind especially in the .NET world. If you haven't yet started mastering your art and adapting to the changing trends, you should start today. Think about crafting your web applications properly. Use commonsense to mix and match based on scenarios. Here we go with 6 Tips to be a responsible web developer, and to stay on top of what you do. 1 – Learn to write better JavaScript and CSS If you don’t write proper JavaScript and CSS, you are dead.

Familiarize yourself with a higher level abstraction language to write JavaScript once you are comfortable with plain Javascript – Like CoffeeScript or TypeScript. JQuery – Alright, you know this, don’t you? More Oh yes, start learning TypeScript especially if you have a Microsoft technology/C# background. 2 – Familiarize yourself with a Responsive Framework My personal choices include Twitter Bootstrap and Zurb’s Foundation. Better list example. Simplifying and cleaning up views in KnockoutJS - Knock Me Out. A common source of discontent that I hear about Knockout.js is how easy it is to find yourself with complex and verbose data-bind attributes that contain logic and code that belongs elsewhere. Partially because of this issue, there has been interest lately in ways to unobtrusively apply bindings. If a robust solution is developed to handle this, then it may be an interesting option with its own pros and cons. However, I wanted to present another angle on this topic.

I believe that there are many techniques that can be used to reduce the complexity and general craziness of the data-bind attributes. Here are some common examples of bindings that could stand to be improved for various reasons: data-bind=”enable: items().length < 10” data-bind=”visible: ! Data-bind=”text: selectedItem() ? Data-bind=”click: function() { viewModel.selectItem($data); }” Let’s look at some ways that we could handle each of these bindings in a cleaner way. Encapsulating logic in a dependentObservable Final Thoughts. Utility functions in KnockoutJS - Knock Me Out. When working with KnockoutJS, there seem to be many common operations that you need to perform on your view model objects. Internally, Knockout has a number of utility functions used by the library itself, but many of these functions might actually be handy for anyone using the library. I wanted to build a sample that highlights a few of my favorite utilities. Handling data from the server One of the first tasks that you typically encounter is converting data from the server to a suitable format for use in Knockout.

Knockout has a utility function ko.utils.parseJson that will attempt to do a JSON.parse if it is available or fall back to evaluating it as a function string for older browsers. Now we have a JavaScript object, but in order to be useful in Knockout, we might need to convert some properties to observables and possibly add some computed observables. Dealing with arrays in your view model Now we have an array of items that is ready for use in Knockout.

Looping through an array. Knockout.js 2.2 is out now! - Knock Me Out.