Skip to content

Instantly share code, notes, and snippets.

View dhunmoon's full-sized avatar

Atul Chaudhary dhunmoon

View GitHub Profile
@dhunmoon
dhunmoon / jsEscapeEvent.js
Created February 2, 2017 15:18
JS: Escape Key Event
$(document).keyup(function(e) {
if (e.keyCode == 27) { // escape key maps to keycode `27`
// <DO YOUR WORK HERE>
}
});
@dhunmoon
dhunmoon / jsCheckLeapYear.js
Last active February 2, 2017 15:10
JS: Check Leap Year
if(month == 2){//Means if it is month of feborary
if(nyear %4 == 0 && ( nyear %400 != 0 || nyear %100 !== 0 ){//Leap year statement
return true
}
}else{
return false;
}
@dhunmoon
dhunmoon / jsGetDayName.js
Created February 2, 2017 09:36
JS: Get Day Name
//Get Day Name like SUN,MON instead of 0,1,2
var days = ['Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday'];
var d = new Date(<YOUR-DATE>);//Pass a Date here
var dayName = days[d.getDay()];//d.getDay() function returns the day name as 0,1,2,3 here 0 = Sunday
@dhunmoon
dhunmoon / jsSleep.js
Last active February 2, 2017 09:30
JS: Sleep
//Not Supported in IE Older Versions only found to be working in modern Browsers
function sleep(ms) {
return new Promise(resolve => setTimeout(resolve, ms));
}
async function demo() {
console.log('Taking a break...');
await sleep(2000);
console.log('Two second later');
}
@dhunmoon
dhunmoon / jsNavActive.js
Created February 1, 2017 16:01
JS: Make Navigation Active Javascript
$(function () {
setNavigation();
});
function setNavigation() {
var path = window.location.pathname;
path = path.replace(/\/$/, "");
path = decodeURIComponent(path);
$(".nav a").each(function () {
@dhunmoon
dhunmoon / jsActiveXSQLConnection.js
Created February 1, 2017 06:02
JS:ActiveXObject SQL Connection
var connection = new ActiveXObject("ADODB.Connection") ;
var connectionstring="Data Source=<server>;Initial Catalog=<catalog>;User ID=<user>;Password=<password>;Provider=SQLOLEDB";
connection.Open(connectionstring);
var rs = new ActiveXObject("ADODB.Recordset");
rs.Open("SELECT * FROM table", connection);
rs.MoveFirst
while(!rs.eof)
@dhunmoon
dhunmoon / jsMD5.js
Created June 17, 2016 05:22
JS:MD5 Function
var MD5 = function (string) {
function RotateLeft(lValue, iShiftBits) {
return (lValue<<iShiftBits) | (lValue>>>(32-iShiftBits));
}
function AddUnsigned(lX,lY) {
var lX4,lY4,lX8,lY8,lResult;
lX8 = (lX & 0x80000000);
lY8 = (lY & 0x80000000);
@dhunmoon
dhunmoon / EditModeJavascript.html
Created May 5, 2016 08:54
How to Verify if the Page is in Edit Mode using JavaScript in Page Layout SharePoint 2013
<PublishingWebControls:EditModePanel ID="EditModelPanel1"
runat="server" PageDisplayMode="Edit">
<h1>You are in EDIT mode</h1>
<!-- Place you're javascript for execute only in edit mode -->
</PublishingWebControls:EditModePanel>
<PublishingWebControls:EditModePanel ID="EditModelPanel2"
runat="server" PageDisplayMode="Display">
<h1>You are in DISPLAY mode</h1>
<!-- Place you're javascript for execute only in display mode -->
@dhunmoon
dhunmoon / EditModeJavascript.js
Created May 5, 2016 08:53
How to Verify if the Page is in Edit Mode using JavaScript in SharePoint 2013
//For Publishing Page
//SharePoint default input called MSOLayout_InDesignMode is there. If the value is 1, then page is in edit mode else it is in display mode.
//Hide Copy Code
var inDesignMode = document.forms[MSOWebPartPageFormName].MSOLayout_InDesignMode.value;
if (inDesignMode == "1"){
// page is in edit mode
}
else{
@dhunmoon
dhunmoon / IE_Conditional_statements.html
Created May 4, 2016 08:07
IE Conditional Statements
<!--[if IE]>
According to the conditional comment this is IE<br />
<![endif]-->
<!--[if IE 6]>
According to the conditional comment this is IE 6<br />
<![endif]-->
<!--[if IE 7]>
According to the conditional comment this is IE 7<br />
<![endif]-->
<!--[if IE 8]>