9 JavaScript Libraries for Working with Local Storage. The HTML5 Local Storage API (part of Web Storage) has excellent browser support and is being used in more and more applications. It has a simple API and certainly has its drawbacks, similar to cookies. Over the past year or so I’ve come across quite a few tools and libraries that use the localStorage API so I’ve compiled many of them together into this post with some code examples and discussion of the features. Lockr Lockr is a wrapper for the localStorage API and lets you use a number of useful methods and features. Other features include: Retrieve all key/value pairs with the Lockr.get() methodCompile all key/value pairs into an array with Lockr.getAll()Delete all stored key/value pairs with Lockr.flush()Add/remove values under a hash key using Lockr.sadd and Lockr.srem The Local Storage Bridge A 1KB library to facilitate exchanging messages between tabs in the same browser, using localStorage as the communication channel.
Barn store.js In addition, there are some more advanced features: Dialog Widget. Description: Open content in an interactive overlay. A dialog is a floating window that contains a title bar and a content area. The dialog window can be moved, resized and closed with the 'x' icon by default. If the content length exceeds the maximum height, a scrollbar will automatically appear. A bottom button bar and semi-transparent modal overlay layer are common options that can be added. Focus Upon opening a dialog, focus is automatically moved to the first item that matches the following: The first element within the dialog with the autofocus attribute The first :tabbable element within the dialog's content The first :tabbable element within the dialog's buttonpane The dialog's close button The dialog itself While open, the dialog widget ensures that keyboard navigation using the 'tab' key causes the focus to cycle amongst the focusable elements in the dialog, not elements outside of it.
Hiding the close button Theming ui-dialog: The outer container of the dialog. Dependencies appendTo. Bulk Upload in AngularJS. Download source - 3.7 MB Introduction While working with SPA (Single Page Application) using AngularJS in my project, I needed bulk upload to be implemented. I was stuck for some time and finally achieved this.
So I thought it might be helpful for some others who have to implement bulk upload in their apps. In this demo, I have used Visual Studio 2012, .NET Framework 4.5, AngularJs, Bootstrap and .mdf files for the database operations. Demo Overview This demo is small medical bill application, where a user can upload multiple bills (not physical files) to the server in one go. Important Things for Bulk Upload The way you define your model in AngularJS is very important to pass to server side. Creating Project in Visual Studio Open Visual Studio 2012 and create a project with MVC4 template and I have named the project BulkInsert_Angularjs, but you can name it anything you want.
Now, add these installed files to your MVC project. Setting Up Database Angular Code Explanation Client-side Routing. Knockout : Home. Introduction to KnockoutJS | Chetan's blog. Introduction Knockout, developed by Steve Sanderson, is free open source JavaScript library available under MIT license. It was first released in 2010 and since its initial release it has caught attention of industry and has been very popular. It is written purely in JavaScript and works on any web platform, any web browser and has no other dependencies.
Features like easy bindings, observables and template support makes it truly unique and very useful for any enterprise application. It’s very robust and takes care of lot of heavy lifting for your application and provides an elegance interface to build apps. At a very high level Knockout offers: Ø Declarative bindings of UI controls to your Data model Ø Automatic UI refresh based on your data Ø Dependency Tracking Ø Template support Bindings: To understand the simplicity and power and knockout bindings, imagine a simple scenario where you have to display employee information on UI: Well, fortunately, knockout has a solution for us.
Us. 1. 2. A simple modal feedback form with no plugins < JavaScript. 1 Tweet5 Shares1 ShareFeedback Almost every website these days has some kind of comment or feedback form. Often they rely on Facebook, Disqus or other third-party services, or require bloated libraries such as jQuery to function. Here you can find instructions for setting up a very basic feedback form using just a few lines of CSS and JavaScript. The form will appear in a modal (popup) with the background greyed out. 1. Setting up the HTML Below you will see code for a basic HTML form. Above this, there is a button that will appear on the page, #modal_open, and the form is contained by #modal_wrapper (any other containing element can also be used). This is all pretty simple. The autofocus attribute on the first input field works in Safari, Chrome and Opera in setting focus on that field when the modal window is displayed.
The HTML5 required attribute is recognised in IE10 and higher, and many browsers will now display the associated title text as a tooltip if the field is left empty. 2. 3.
Create a Modal Dialog Using CSS and Javascript | Raven. Back in my early programming days, before I switched over to web development, I spent most of my time writing software for Windows. I look back on that time with fond memories. 8-bit icons, OLE2, and no silly Start menus. With the recent Web 2.0 boom, many web developers have returned to their roots and begun building sites that resemble desktop applications. AJAX (the second coming of javascript) lets designers borrow elements from the desktop paradigm and use them on their websites. One element that I find myself using quite a bit are modal dialogs. In a desktop application, a modal dialog is a box or message that forces you to dismiss it before you can use any other part of the program. When used sparingly, it can be a great way to direct the user’s attention to a specific element and force them to make a decision. With a little CSS and Javascript we can accomplish this same effect on the web.
The code behind this effect is surprisingly simple. The overlay <div> The CSS The Javascript. Http-server. A simple zero-configuration command-line http server http-server is a simple, zero-configuration command-line http server. It is powerful enough for production usage, but it's simple and hackable enough to be used for testing, local development, and learning. Installation via npm. If you don't have npm yet: curl | sh Once you have npm: npm install http-server -g This will install http-server globally so that it may be run from the command line. Usage: http-server [path] [options] [path] defaults to . mkdir myapp cd myapp/ jitsu install http-server If you do not have jitsu installed you can install it via npm install jitsu -g Usage Starting http-server locally node bin/http-server Now you can visit to view your server Deploy http-server to nodejitsu jitsu deploy You will now be prompted for a subdomain to deploy your application on Available Options: -p Port to use (defaults to 8080) -a Address to use (defaults to 0.0.0.0) -S or --ssl Enable https.
Localizing Times in JavaScript | CSS-Tricks. Say you have a time you'd like to display on your site. You've entered it in your time zone. You can always be specific and say something like: 3:00 PM Eastern Standard Time. Then leave it up to whoever is reading to convert it to their local time. Every Time Zone is a great site for that. But it can be nice to localize the time for the reader. I'm sure there are a number of ways to do this. Libraries Moment.js and Moment Timezone are a pair that can get this done. We'll also need to detect the time zone itself, and thankfully there is a library for that. So we'll be using: jstz.jsmoment.jsmoment-timezone.js Package or link those up however you will. Step 1: Get the Timezone Might as well stash it in localStorage after you've gotten it.
If (! Step 2: Get a Time Value Moment expects a date/time value (in UTC) like: If we're only interested in the time, we can create the date portion of that string from Moment itself of today's date (just makes the formatting way easier). Step 3: Localize the time. Using the Media Capture API in the Browser. Today I’d like to experiment with the Media Capture and Streams API, developed jointly at the W3C by the Web Real-Time Communications Working Group and the Device APIs Working Group. Some developers may know it simply as getUserMedia, which is the main interface that allows webpages to access media capture devices such as webcams and microphones. You can find the source code for this project on my GitHub. Additionally, here’s a working demo for you to experiment with. In the latest Windows 10 preview release, Microsoft added support for media capture APIs in the Microsoft Edge browser for the first time.
Much of this code was taken from the Photo Capture sample that the Edge dev team produced at their test drive site. For those of you who want to dive a bit deeper, Eric Bidelman has a great article at HTML5 rocks which goes into the storied history of this API. Getting up to speed The getUserMedia() method is a good starting point to understand the Media Capture APIs. Feature detection.
Understanding Angular's $apply() and $digest() $apply() and $digest() are two core, and sometimes confusing, aspects of AngularJS. To understand how AngularJS works one needs to fully understand how $apply() and $digest() work. This article aims to explain what $apply() and $digest() really are, and how they can be useful in your day-to-day AngularJS programming. $apply and $digest Explored AngularJS offers an incredibly awesome feature known as two way data binding which greatly simplifies our lives. The second argument passed to $watch() is known as a listener function, and is called whenever the value of aModel changes.
It’s the $digest cycle where the watchers are fired. The $digest cycle starts as a result of a call to $scope. So far, so good! Now, let’s assume you attach an ng-click directive to a button and pass a function name to it. Note: $scope. When Do You Call $apply() Manually? If AngularJS usually wraps our code in $apply() and starts a $digest cycle, then when do you need to do call $apply() manually? Conclusion. Tryit Editor v2.5. AngularJS: API: ngRepeat. The ngRepeat directive instantiates a template once per item from a collection. Each template instance gets its own scope, where the given loop variable is set to the current collection item, and $index is set to the item index or key. Special properties are exposed on the local scope of each template instance, including: Creating aliases for these properties is possible with ngInit. This may be useful when, for instance, nesting ngRepeats. It is possible to get ngRepeat to iterate over the properties of an object using the following syntax: <div ng-repeat="(key, value) in myObj"> ...
You need to be aware that the JavaScript specification does not define the order of keys returned for an object. Version 1.4 removed the alphabetic sorting. If this is not desired, the recommended workaround is to convert your object into an array that is sorted into the order that you prefer before providing it to ngRepeat. By default, ngRepeat does not allow duplicate items in arrays. AngularJS: API: date. 7 Essential JavaScript Functions. I remember the early days of JavaScript where you needed a simple function for just about everything because the browser vendors implemented features differently, and not just edge features, basic features, like addEventListener and attachEvent. Times have changed but there are still a few functions each developer should have in their arsenal, for performance for functional ease purposes. debounce The debounce function can be a game-changer when it comes to event-fueled performance.
If you aren't using a debouncing function with a scroll, resize, key* event, you're probably doing it wrong. Here's a debounce function to keep your code efficient: function debounce(func, wait, immediate) { var timeout; return function() { var context = this, args = arguments; var later = function() { timeout = null; if (! The debounce function will not allow a callback to be used more than once per given time frame.
Poll Polling has long been useful on the web and will continue to be in the future! Once isNative. What is the best auto-suggest search algorithm for javascript. Algorithm - Getting the closest string match. Live Search with Quicksilver Style. Agershun/alasql. CodeMontage. Login Projects These open source, community-driven projects are making the world better and could really use your help. Check them out and contribute however you'd like. Or, view organizations. Excited to contribute, but can't dig in right now? Code Later! Open Science Framework Save Promoting integrity, reproducibility and transparency in the scientific workflow. Technologies JavaScript, Python Causes Science, Open Data OKN Open Data Census Application Save Open government data dashboard at JavaScript Civic Engagement, Open Data Ushahidi Android Application Save Android application that sends reports with images and location data as well as receives alerts from others who have sent in reports to the Ushahidi site.
Android, Java Civic Engagement, Disaster Relief, International Development, Open Data Shareabouts Save Shareabouts is a mapping application for crowdsourced info gathering. CASH Music Platform Save Community Building, Open Data OpenTreeMap for iOS Save iOS, GIS Python. Promise. The Promise object is used for asynchronous computations. A Promise represents a value which may be available now, or in the future, or never. SyntaxEdit new Promise( /* executor */ function(resolve, reject) { ... } ); Parameters executor A function that is passed with the arguments resolve and reject. DescriptionEdit A Promise is a proxy for a value not necessarily known when the promise is created. A Promise is in one of these states: pending: initial state, not fulfilled or rejected. fulfilled: meaning that the operation completed successfully. rejected: meaning that the operation failed.
A pending promise can either be fulfilled with a value, or rejected with a reason (error). As the Promise.prototype.then() and Promise.prototype.catch() methods return promises, they can be chained. Not to be confused with: Several other languages have mechanisms for lazy evaluation and deferring a computation, which they also call “promises” — e.g. PropertiesEdit Promise.length Promise.prototype MethodsEdit. Map/reduce queries. Map/reduce queries, also known as secondary indexes, are one of the most powerful features in PouchDB. However, they can be quite tricky to use, so this guide is designed to dispell some of the mysteries around them. Many developers make the mistake of using the query() API when the more performant allDocs() API, would be a better fit.
Before you solve a problem with secondary indexes, you should ask yourself: can I solve this with the primary index (_id) instead? Mappin' and reducin' The PouchDB query() API (which corresponds to the _view API in CouchDB) has two modes: temporary queries and persistent queries. Temporary queries Temporary queries are very slow, and we only recommend them for quick debugging during development. In the above example, the result object will contain all documents where the name attribute is equal to 'foo'. The emit pattern is part of the standard CouchDB map/reduce API. Persistent queries After this, your queries will be much faster.
More about map/reduce Next.