Category Archives: Javascript

javascript, js

RequireJS + Zurb Foundation

“use strict”; require.config({ baseUrl: ‘static’, paths: { jquery: ‘bower_components/jquery/dist/jquery’, foundation: ‘bower_components/foundation/js/foundation’, }, shim: { ‘foundation’: { deps: [‘jquery’] }, } }); require([‘foundation’], function(f){ $(function(){ alert(1); }); });

Javascript Snippet: Play next video

There is a requirement from one of my project to insert video ads before the actual video gets played. There are ways to do it, one is to use JWPlayer and OVA plugin, or the other way is to write your own javascript to control the playback. In the following demo, shows how you can… Read More »

How to extend JQuery UI plugin

The existing dialog plugin doesn’t have an option to close dialog on clicking modal overlay, how to add an option to provide the functionality? (function($){ var _init = $.ui.dialog.prototype._init; $.ui.dialog.prototype._init = function(){ var self = this; _init.apply(this,arguments); $(‘.ui-widget-overlay’).live(‘click’, function(){ if (self.options[‘overlay_close’]){ self.destroy(); } }); } })($);

Google Map v3 OverlayView Code Sample

Today I was writing some google map javascripts and had to implement the icons via OverlayView class, so I think I might share it in case anyone need some sample code. //”gmap” is an instance of the google map //creating the class to exntend the google map OverlayView class function MapLocationIcon(id,lat,lng,title,icon_class){ this.lat = lat; this.lng… Read More »

A tip for event function within a loop, function closure

When I was writing some javascript at work a while ago, I encountered a problem, see below: for (var i=0; i<10; i++){ $(‘#element’+i).click(function(){ alert(i); }); } When I click the element, it always returned 9, because the event function is not included into the context until it is triggered, therefore, while the click function is… Read More »