Skip to content

Instantly share code, notes, and snippets.

@Shwartz
Shwartz / elPosition.js
Last active January 10, 2017 14:54
JavaScript: Find element position by looping from element up to body tag
// Original source: https://www.kirupa.com/html5/get_element_position_using_javascript.htm
// Helper function to get an element's exact position
function getPosition(el) {
var xPos = 0;
var yPos = 0;
while (el) {
if (el.tagName == "BODY") {
// deal with browser quirks with body/window/document and page scroll
var xScroll = el.scrollLeft || document.documentElement.scrollLeft;
@Shwartz
Shwartz / gulp.js
Last active January 10, 2017 14:49
Noje.js Gulp rename files
gulp.task('rename', function () {
var fs = require('fs');
var fileList = '';
fs.readdir('sass/test', function(err, files) {
files.forEach(function (file) {
console.log('file: ', file);
fs.rename('sass/test/' + file, 'sass/test/_' + file, function (err) {
if (err) console.log('ERR: ' + err);
})
@Shwartz
Shwartz / gulp.js
Last active January 10, 2017 14:50
gulp webpack example with flag to run different configs
gulp.task('webpack', function () {
console.log('TASK:WEBPACK');
/*
* run in gulp: gulp webpack --target=prod
* to create prod JS
* */
if (gutil.env.target == 'prod') {
webpackConfig.plugins = [
new webpack.optimize.DedupePlugin(),
@Shwartz
Shwartz / gulp.js
Last active January 10, 2017 14:51
gulp task to create index file with a list of all files - TOC
/*
* Utility to create index file with a list of all files - TOC
* */
gulp.task('create-toc', function () {
var fs = require('fs');
var fileList = '';
fs.readdir('pages/cats', function(err, files) {
files.forEach(function (file) {
fileList += '<li><a href="'+ file +'">'+ file +'</a></li>';