Skip to content

Instantly share code, notes, and snippets.

View javanigus's full-sized avatar

Abdullah Yahya javanigus

View GitHub Profile
@javanigus
javanigus / fade-slide-scroll.js
Created November 7, 2016 19:29
Fade out and slide element upwards as user scroll down
(function ($) {
"use strict";
// as user scrolls down / up, fade and move banner text
$(document).on("ready", function () {
var reFadeAndTranslate, deReFadeAndTranslate, \$bannerText;
\$bannerText = $("div.banner-text");
reFadeAndTranslate = function () {
@javanigus
javanigus / marketoCustomFormValues.js
Created April 26, 2017 00:44
Change Some Marketo Hidden Field Values Depending on Another Field's Value
// http://developers.marketo.com/javascript-api/forms/
/* Using Forms 2.0 from Landing Pages
While all of the forms examples use embedded forms, the same APIs are available on Marketo Landing Pages as well.
Usually, you’ll want to add a script that gets some reference to the form object. To do this, first add your form to the landing page, then add a new HTML block to your landing page. Then you can add a script block to the page as follows */
MktoForms2.whenReady(function (form) {
var selectedPackage, Marketing_Asset_Id_Current__c, last_mkt_asset, Company_Size_Range__c_account, formTrialPackageType;
@javanigus
javanigus / translate.js
Last active October 13, 2017 23:15
Nested JavaScript Loops Containing Async Functions That are Forced to Run Synchronously
var translate = require('google-translate-api');
var fs = require('fs');
var async = require('async');
// array of filenames
// each file contains a JSON object
var filenames = [
"0001-school-life-buying-textbooks.js",
"0002-school-life-class-registration.js",
"0003-school-life-too-many-full-classes.js"
@javanigus
javanigus / gist:172aa54a48c18c1b6e04d8bfb35f78bd
Created December 11, 2017 23:30
jQuery handle event of dynamically-created element
$("body").append("<div class='a'></div>");
$(document).on("click", "div.a", function (event) {
// do something when the div is clicked
});
@javanigus
javanigus / gist:1d9d0a4a8fe5845822e86fb9fc2dc160
Created December 11, 2017 23:33
Native JavaScript Handle Event of Dynamically-Created HTML Element
document.querySelector('div.a').addEventListener('click', function(event) {
if (event.target.className === 'a') {
// do something
}
});
@javanigus
javanigus / gist:f041d4c92fb5b576512fd9402c0b8b62
Created December 11, 2017 23:42
Native JavaScript Detach and Attach an HTML Element
// get the div
var div = document.querySelector('div.a');
// detach the div
div = div.parentNode.removeChild(div);
// attach the div somewhere else
var footer = document.querySelector('.footer');
footer.insertAdjacentHTML('afterend', div.outerHTML);
@javanigus
javanigus / for-loop.js
Last active January 11, 2018 21:29
Example JavaScript For Loop
// INPUT
let numbers = [1, 2, 3, 4];
// MULTIPLY EACH ARRAY ITEM BY 2
for (let i=0; i<numbers.length; i++) {
results.push(numbers[i]*2);
}
// OUTPUT
// [2, 4, 6, 8]
@javanigus
javanigus / foreach1.js
Last active January 11, 2018 21:30
Example JavaScript forEach Loop
// INPUT
let numbers = [1, 2, 3, 4];
let results = [];
// MULTIPLY EACH ARRAY ITEM BY 2
numbers.forEach(function (currentValue, index, arr) {
results.push(currentValue*2);
});
// OUTPUT
@javanigus
javanigus / map1.js
Created January 11, 2018 21:31
Example JavaScript Map Function
// INPUT
let numbers = [1, 2, 3, 4];
let results = [];
// MULTIPLY EACH ARRAY ITEM BY 2
function multiplyBy2(currentValue, index, arr) {
return currentValue*2;
}
results = numbers.map(multiplyBy2);
@javanigus
javanigus / map2.js
Created January 11, 2018 21:33
Example JavaScript Map Function
// INPUT
let numbers = [1, 2, 3, 4];
let results = [];
// MULTIPLY EACH ARRAY ITEM BY 2
results = numbers.map(function (currentValue, index, arr) {
return currentValue*2;
});
// OUTPUT