Skip to content

Instantly share code, notes, and snippets.

View pradeepn's full-sized avatar

Pradeep Nagendiran pradeepn

  • Chennai, IN
View GitHub Profile
@pradeepn
pradeepn / bootstrap.nestedtaburlaccess
Created May 16, 2013 06:21
Bootstrap Tab Activation From Url. 1. Works for all kinds of bootstrap tabs and nested tabs 2. In order to work for nested tabs add class nested to the data-toggle="tab" a tag for all child tabs
var handleUrlTabActivation = function () {
var hash = document.location.hash;
if(hash!=null && hash != ""){
hash = hash.split('#')[1];
}
console.log(hash);
var prefix = "tab-";
var hpieces = hash.split('/');
for (var i = 0; i < hpieces.length; i++) {
var domelid = hpieces[i].replace(prefix, '');
@pradeepn
pradeepn / TimeZoneOffsetCookie
Created May 16, 2013 06:32
TimeZoneOffsetCooke: Useful when working with global website. Store the client UTC time difference in the cookie. Adjust the datetime with the stored time difference from cookie while displaying or manipulating with date and time. The above system works only if you store all the date time in UTC.
var setTimezoneCookie = function () {
var timezone_cookie = "timezoneoffset";
var offset = new Date().getTimezoneOffset();//Require datejs for this method.http://www.datejs.com/
if (!$.cookie(timezone_cookie)) {
// check if the browser supports cookie
var test_cookie = 'test cookie';
@pradeepn
pradeepn / FilterConfig.cs
Created August 7, 2013 11:20
MVC AntiForgery Token for all jquery post
public class FilterConfig
{
public static void RegisterGlobalFilters(GlobalFilterCollection filters)
{
filters.Add(new HandleErrorAttribute());
filters.Add(new GlobalValidateAntiForgeryToken());
//Instead of putting [ValidateAntiForgeryToken] Use this for all request
}
}
@pradeepn
pradeepn / ajaxbutton.js
Last active December 21, 2015 13:59
Globally add Loading text to the button that post ajax and reset after the request is complete for bootstrap
$(function(){
$(document).on('ajaxSend', function () {
if (settings.context != undefined && settings.context.hasClass('btn')) {
settings.context.button('loading');
}
});
$(document).on('ajaxComplete', function () {
if (settings.context != undefined && settings.context.hasClass('btn')) {
settings.context.button('reset');
@pradeepn
pradeepn / jQuery Ajax Error Handling
Created September 17, 2013 12:14
Global jQuery Ajax Error Handling
//http://www.unseenrevolution.com/jquery-ajax-error-handling-function/
$(function() {
$.ajaxSetup({
error: function(jqXHR, exception) {
if (jqXHR.status === 0) {
alert('Not connect.\n Verify Network.');
} else if (jqXHR.status == 404) {
alert('Requested page not found. [404]');
} else if (jqXHR.status == 500) {
alert('Internal Server Error [500].');
@pradeepn
pradeepn / JSONToCSV.js
Last active August 29, 2015 14:14
JSON to CSV string
/**
* Return a CSV string from an array of json object
*
* @method JSONtoCSV
* @param {Object} jsonArray an array of json object
* @param {String} [delimiter=;] delimiter
* @param {String} [dateFormat=ISO] dateFormat if a date is detected
* @return {String} Returns the CSV string
**/
function _JSONtoCSV(jsonArray, delimiter, dateFormat) {
@pradeepn
pradeepn / ClientCsvDownload.js
Created February 6, 2015 06:57
Client File Download
//$.borwser plugin
//$.fileDownload plugin
downloadCsv: function (filename, array, dilem) {
var csvString = _JSONtoCSV(array, dilem);
console.log(csvString);
if ($.browser.msie == true) {//HTML5 Download attribute not available in ie
$.fileDownload('/downloadcsv', { httpMethod: "POST", data: { CsvString: csvString, FileName: filename} });
}
else {
var a = document.createElement('a');
@pradeepn
pradeepn / GenerateUUID.js
Last active August 29, 2015 14:14
Generate UUID
function _generateUUID() {
var d = new Date().getTime();
var uuid = 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function (c) {
var r = (d + Math.random() * 16) % 16 | 0;
d = Math.floor(d / 16);
return (c == 'x' ? r : (r & 0x7 | 0x8)).toString(16);
});
return uuid;
}
@pradeepn
pradeepn / WebsocketClient.js
Last active August 29, 2015 14:14
Websocket Client Implementation
//JS Client For Websockets Server
//For C# Use Fleck & NetSockets
//https://github.com/statianzo/Fleck
//https://netsockets.codeplex.com/Wikipage?ProjectName=netsockets
var ws;
$(document).ready(function () {
// test if the browser supports web sockets
if ("WebSocket" in window) {
debug("Browser supports web sockets!", 'success');
@pradeepn
pradeepn / SampleAsyncController.cs
Created February 15, 2016 08:14
Async Controler
//.NET 4.0
//Synchronous Controller:
public class TestController : Controller
{
public ActionResult Index()
{
return View();
}
}