working on it ...

Filters

Explore Public Snippets

Sort by

Found 116k snippets

    public by szmerek modified Sunday at 9:40:13 PM  33  1  3  0

    OnClick without setting an attribute of the link

    //<div id="dog" >Woow woow</div>
    
    
        (function() {
            document.getElementById("dog").onclick = function() { 
                alert('fuf fuf'); 
            };
        })();																		

    public by szmerek modified Sunday at 3:44:27 PM  19  0  2  0

    Remove part of a string before specified character

    //remove string before '&' if want to include character '&' then 'indexOf("&") + 0'
    var str = "black&white";
    str = str.substring(str.indexOf("&") + 1);
    
    //or use regex
    var str = "black&white";
    str = /&(.+)/.exec(str)[1];
    
    // or use .split() and .pop() 
    var str = "black&white";
    str = str.split("&").pop();						

    public by szmerek modified Sunday at 3:39:57 PM  19  0  2  0

    Check whether a string matches a regex

    //RegExp allows to inject variable values into the regex string
    var str = "sample1";
    var re = new RegExp("^([a-z0-9]{5,})$");
    if (re.test(str)) {
        console.log("valid");
    } else {
        console.log("invalid");
    }					

    public by szmerek modified Sunday at 3:38:43 PM  33  0  3  0

    Hide element(s) by class

    Some examples for hiding the class.
    //Ex 
    //<div class="appBanner">appbanner</div> 
    
    document.getElementsByClassName('appBanner')[0].style.visibility = 'hidden';
    
    //change the style rules of all elements matching the class
    
    [].forEach.call(document.querySelectorAll('.appBanner'), function (el) {
      el.style.visibility = 'hidden';
    });
    
    //If for...of is available then use
    
    for (let el of document.querySelectorAll('.appBanner')) el.style.visibility = 'hidden';
    
    //And the other one
    
    Array.filter( document.getElementsByClassName('appBanner'), function(elem){ elem.style.visibility = 'hidden'; });
    
    //and the last one
    
    var appBanners = document.getElementsByClassName('appBanner'), i;
    
    for (i = 0; i < appBanners.length; i += 1) {
        appBanners[i].style.display = 'none';
    }																								

    public by sunole modified Aug 5, 2017  40  0  1  0

    test javascript one

    // Enter here the actual content of the snippet.			
    var aaaa =5;

    public by ElectroSoft modified Jul 15, 2017  106  0  4  0

    Prueba de Ajax

    Prueba de Axaj en javascript nativo.
    function ajax()
    {
        var elements = document.getElementsByClassName("formVal");
        var formData = new FormData(); 
        for(var i=0; i<elements.length; i++)
        {
            formData.append(elements[i].name, elements[i].value);
        }
        var xmlHttp = new XMLHttpRequest();
            xmlHttp.onreadystatechange = function()
            {
                if(xmlHttp.readyState == 4 && xmlHttp.status == 200)
                {
                    alert(xmlHttp.responseText);
                }
            }
            xmlHttp.open("post", "prueba.php"); 
            xmlHttp.send(formData); 
    }

    public by slavka1979 modified May 26, 2017  129  1  4  0

    Promise.all for Rejections and Resolves

    Always call then, even when one promise rejects
    // https://davidwalsh.name/promises-results
    Promise.all([
        // Resolves
        Promise.resolve(1), 
        // Rejects after 2 seconds
        new Promise((resolve, reject) => setTimeout(() => reject(1), 2000))
    ].map(p => p.catch(() => undefined))).then(() => console.log('done!'));

    public by vladimirov1 modified May 18, 2017  63  0  1  0

    print crosfilter results in console

    print crosfilter results in console: print_filter.js
    /**
     * Created by user on 18/05/17.
     */
    			// Super useful for debug in web console
    			function print_filter(filter){
    				var f=eval(filter);
    				if (typeof(f.length) != "undefined") {}else{}
    				if (typeof(f.top) != "undefined") {f=f.top(Infinity);}else{}
    				if (typeof(f.dimension) != "undefined") {f=f.dimension(function(d) { return "";}).top(Infinity);}else{}
    				console.log("DC DEBUG: "+filter+"("+f.length+") = "+JSON.stringify(f).replace("[","[\n\t").replace(/}\,/g,"},\n\t").replace("]","\n]"));
    			}
    
    

    public by vadimtkachenko modified May 15, 2017  162  0  4  0

    javascript

    =)))
    <html>
    <title>
    dddrew
    </title>
    <body>
    <script>
    
    
    
    
    
    
    </script>
    </body>
    </html>

    public by toledano modified Mar 6, 2017  207  0  3  0

    gulpfile.js para cmi_tema

    gulpfile.js para cmi_tema: gulpfile.js
    /**
     * Created by toledano on 06/11/15.
     */
    
    // inicializa gulp
    var gulp = require('gulp');
    
    // incluye los plugin
    var jshint = require('gulp-jshint');
    var concat = require('gulp-concat');
    var debug = require('gulp-strip-debug');
    var uglify = require('gulp-uglify');
    var sass = require('gulp-ruby-sass');
    var notify = require('gulp-notify');
    
    // Configuración
    var config = {
      sourcesDir: "./sources",
      sassPath:   "./sources/sass",
      nodeDir:    "./node_modules",
    }
    
    // tarea fontawesome
    gulp.task('icons', function() {
      gulp.src([
        config.nodeDir + '/font-awesome/fonts/**.*',
        config.nodeDir + '/bootstrap-sass/assets/fonts/**/*'
      ])
        .pipe(gulp.dest('./assets/fonts'));
    });
    
    // tarea bootstrap
    gulp.task('sass', function() {
      sass(config.sassPath + '/cmi.scss', {
        style: 'expanded',   // nested, expanded, compact, compressed
        loadPath: [
          config.sassPath,
          config.nodeDir + '/bootstrap-sass/assets/stylesheets',
          config.nodeDir + '/font-awesome/scss'
        ]
      })
      .on("error", notify.onError(function (error) {
        return "Equivocación: " + error.message;
      }))
      .pipe(gulp.dest('./assets/css'));
    });
    
    // Se define la tarea `scripts`
    gulp.task('scripts', function() {
      gulp.src([
        config.nodeDir    + '/jquery/dist/jquery.js',
        config.nodeDir    + '/bootstrap-sass/assets/javascripts/bootstrap.js',
        config.sourcesDir + '/js/**/*',
      ])
      // .pipe(jshint())
      // .pipe(jshint.reporter('default'))
      .pipe(concat('cmi.js'))
      .pipe(debug())
      .pipe(uglify())
      .pipe(gulp.dest('./assets/js/'));
    });
    
    // la tarea watch
    gulp.task('watch', function() {
      gulp.watch(config.sassPath + '/**/*.scss', ['sass']);
      gulp.watch(config.sourcesDir + '/**/*.js', ['scripts'])
    });
    
    // la tarea `default`
    gulp.task('default', ['scripts','icons', 'sass']);
    
    
                
    • Public Snippets
    • Channels Snippets