Skip to content

Instantly share code, notes, and snippets.

@laurentperroteau
laurentperroteau / avoidConsole.js
Last active August 29, 2015 13:56
Avoid "console" errors in browsers that lack a console
/* * *
* Avoid `console` errors in browsers that lack a console
* @extract of https://github.com/h5bp/mobile-boilerplate
*/
(function(){var method;var noop=function(){};var methods=['assert','clear','count','debug','dir','dirxml','error','exception','group','groupCollapsed','groupEnd','info','log','markTimeline','profile','profileEnd','table','time','timeEnd','timeStamp','trace','warn'];var length=methods.length;var console=(window.console=window.console||{});while(length--){method=methods[length];if(!console[method]){console[method]=noop;}}}());
@laurentperroteau
laurentperroteau / preprocessorRoot.scss
Last active August 29, 2015 13:56
Use "root" for preprocessor
// SASS/SCSS, less or stylus
.children-class {
color: red;
.parent-class & {
color: green;
}
}
=> compile in CSS
.children-class { color: red }
@laurentperroteau
laurentperroteau / google-map.js
Last active August 29, 2015 14:06
Google map exemple : get Json list of place, can display itinary to my place depend type of transport and can display list of place with custom infobox
// GOOGLE MAPS
// ----------------------------
/*jshint sub:true*/
/*jshint indent:4 */
var MyMap = {
data: {
mapItinerary: document.getElementById('map-itinary'),
@laurentperroteau
laurentperroteau / preventCopyPaste.js
Last active August 29, 2015 14:06
Prevent copy/paste on imput (need jQuery)
forbiddenCopy: function() {
$copy = $('.forbidden-copy');
$copy.on('copy paste cut', function(e) {
e.preventDefault();
return false;
});
}
@laurentperroteau
laurentperroteau / centerBackground.js
Last active August 29, 2015 14:06
Center backgroud with JavaScript (need jQuery)
centerBackground: function () {
if( !mobile )
{
var $back = $('#back-img img');
var backSize = tablet ? 750 : 1490;
if( backSize >= Master.data.w )
{
var decalage = ( Master.data.w - backSize) / 2;
@laurentperroteau
laurentperroteau / cutString.js
Created September 4, 2014 15:07
Cut string after x characters and add "..."
newString = oldString.substr(0,35) + ' [...] ';
@laurentperroteau
laurentperroteau / listToDropdown.js
Created September 4, 2014 15:24
Transform list in dropdown
/**
* List to dropdown
* ===================================
*/
o.listToDropdown = function () {
if(!o.device('m') || !$('.list-to-dropdown').length )
return false;
// Create the dropdown base
$("<select />").appendTo(".list-to-dropdown .element-select");
@laurentperroteau
laurentperroteau / order-list-dom.js
Created September 14, 2014 08:55
Order DOM list with data attribut with jQuery
// Fonction utilisé dans orderDataDOM
orderDOM: function(order, toOrder, dataName){
toOrder.sort(function (a, b)
{
a = parseInt( $( a ).data (dataName ), 10 );
b = parseInt( $( b ).data( dataName ), 10 );
if( order == 'asc' )
{
@laurentperroteau
laurentperroteau / Gruntfile.js
Last active August 29, 2015 14:06
Grunt exemple file : include SASS, Compass, StyleGuide, cssLint, jsHint and uglify
/* ----------------- */
/* ::: G R U N T ::: */
/* ----------------- */
module.exports = function(grunt) {
// Project configuration.
grunt.initConfig({
pkg: grunt.file.readJSON('package.json'),
@laurentperroteau
laurentperroteau / consoleLog.sublime-snippet
Created October 14, 2014 09:21
Sublime Text Snippets
<snippet>
<content><![CDATA[console.log( ${1} );]]></content>
<tabTrigger>console</tabTrigger>
<scope>source.js</scope>
<description>Console.log</description>
</snippet>