working on it ...

Filters

Explore Public Snippets

Sort by

Found 367 snippets matching: preload

    public by PBMCube modified Jan 10, 2019  94  0  3  1

    Scene Preload an Image

    command format: Example:this.load.image("key", "path"); Description:Use this in the scene.preload function. .png are the default images. You can also set the "base URL"
    // ============
    // Example 3.4: Additional Phaser Properties begins
    // ============
    // remote URL to game assets
    // Cross-origin resource sharing (CORS)
    	this.load.setCORS = 'anonymous';
    // Setting base URL path
    	this.load.setBaseURL('http://makingbrowsergames.com/p3devcourse/_p3demos/imgages/');
    // Preload a gfx asset
    	this.load.image("face", "face.png");
    	

    public by sTiLLiLL modified Aug 24, 2013  2009  0  6  9

    ajaxn - ified image preloader... its gewd!

    ajaxn - ified image preloader... its gewd!: ajaxPreloader.js
    (function() {
                    var f = [];
                    $.ajax({
                            url: "imgz.js",
                            type: "GET",
                            contentType: "json",
                            cache: true,
                            success: function(data) {
                                var j = JSON.parse(data);
                                var $c = $("#container");
                                for (var x = 0; x < j.length; x++) {
                                    var imag = document.createElement("img");
                                    imag.src = j[x].src;
                                    $(imag).css("height", "100%").css("width", "100%");
                                    f[x] = imag;
                                    $c.append(imag);
                                }
                                return f;
                            },
                            error: function(jqXhr, textStatus, error) {
                                alert("ERROR: " + textStatus + ", " + error);
                            }
                        });
                })();
    
    

    public by msdn modified Jan 12, 2015  136  0  5  0

    PreloadAreaFromString: Converts a string to a PreloadArea

    Converts a string to a PreloadArea the string to convert The converted PreloadArea
    /// <summary>
    /// Converts a string to a PreloadArea
    /// </summary>
    /// <param name="preloadArea">the string to convert</param>
    /// <returns>The converted PreloadArea</returns>
    public static PreloadArea PreloadAreaFromString(string preloadArea)
    {
        if (preloadArea.EndsWith("None"))
        {
            return PreloadArea.None;
        }
        else if (preloadArea.EndsWith("Small"))
        {
            return PreloadArea.Small;
        }
        else if (preloadArea.EndsWith("Medium"))
        {
            return PreloadArea.Medium;
        }
        else
        {
            return PreloadArea.Large;
        }
    }

    external by megantaylor modified Jul 18, 2014  8  0  1  0

    Preloading images is useful: Instead of loading an image when the user request it, we preload them in the background so they are ready to be displayed.

    Preloading images is useful: Instead of loading an image when the user request it, we preload them in the background so they are ready to be displayed. : imagePreload.js
    (function($) {
      var cache = [];
      // Arguments are image paths relative to the current page.
      $.preLoadImages = function() {
        var args_len = arguments.length;
        for (var i = args_len; i--;) {
          var cacheImage = document.createElement('img');
          cacheImage.src = arguments[i];
          cache.push(cacheImage);
        }
      }
    
    jQuery.preLoadImages("image1.gif", "/path/to/image2.png");
    
    //http://engineeredweb.com/blog/09/12/preloading-images-jquery-and-javascript
    
    

    external by fizzwu modified Sep 16, 2014  137  1  2  0

    preload associations with find_by_sql

    preload associations with find_by_sql: preload associations with find_by_sql.rb
    # http://cha1tanya.com/2013/10/26/preload-associations-with-find-by-sql.html
    
    # Rails4 way
    
    @users = User.find_by_sql(some_condition)
    ActiveRecord::Associations::Preloader.new.preload(@users, :company)
    
    

    external by Jonjoe Whitfield modified Dec 28, 2014  102  0  2  0

    Build Wordpress from indee base theme and preload with plugins

    Build Wordpress from indee base theme and preload with plugins: Wordpress Automation
    # Get Wordpress
    wget http://wordpress.org/latest.zip
    unzip latest.zip
    rm -rf latest.zip
    
    
    # Get and compile theme
    cd ./wordpress/wp-content/themes
    git clone https://github.com/WeAreIndee/Wordpress-Gulp-Theme.git theme
    
    cd theme
    npm install
    bower install
    #gulp
    
    cd _prototype
    npm install
    bower install
    #gulp
    
    cd ../../
    rm -rf tw*/
    
    
    # Get plugins
    cd ../plugins
    rm -rf hello.php
    rm -rf a*/
    
    wget https://downloads.wordpress.org/plugin/custom-post-type-ui.0.8.5.zip
    wget https://downloads.wordpress.org/plugin/advanced-custom-fields.zip
    wget https://downloads.wordpress.org/plugin/really-simple-twitter-feed-widget.2.5.14.zip
    
    unzip custom-post-type-ui.0.8.5.zip
    unzip advanced-custom-fields.zip
    unzip really-simple-twitter-feed-widget.2.5.14.zip
    
    rm -rf custom-post-type-ui.0.8.5.zip
    rm -rf advanced-custom-fields.zip
    rm -rf really-simple-twitter-feed-widget.2.5.14.zip
    
    

    external by smcan modified Jul 29, 2015  91  0  1  0

    Easy jquery/zepto images preload

    Easy jquery/zepto images preload: gistfile1.txt
    var images = ["path/to/image", "path/to/image", ... , "path/to/image"],
        preloaded = images.length;
          
    _.each(images, function(img) {
        var image = $('<img />').attr('src', img);
        image.on('load', function(){
              preloaded--;
              if (preloaded === 0){
                  console.log("All preloaded!");
              }
        });
    });
    
    

    external by gordonnl modified Feb 22, 2015  80  0  1  0

    Preload module

    Preload module: preload.js
    /*
     *
     * Preload.js is a require module used to asynchronously load external assets.
     * Upon completion a custom event is triggered, passing the
     * loaded assets.
     * Currently supports images, THREE.js geometries and shaders (text).
     * Dependant on jQuery, THREE.js and tiny pubsub https://github.com/cowboy/jquery-tiny-pubsub
     *
     * Use:
     * preloader({
     *     id: 'customName',
     *     update: true,
     *     images: {
     *         imgName: 'src',
     *     },
     *     geometries: {
     *         geoName: 'src',
     *         bufferGeoName: 'src-including-bfr-prefix',
     *     },
     *     shaders: {
     *         shaderName: 'src',
     *     },
     * });
     *
     * $.subscribe('preload-customName', function(e, assets) {
     *     console.log(assets.images.imgName);
     * });
     *
     * $.subscribe('preload-update-customName', function(e, progress) {
     *     console.log(Math.round(progress * 100), 'percent loaded');
     * });
     *
     */
    
    
    
    define([
        'jquery',
        'pubsub',
        'three'
        ],
    function () {
    
        return function(input) {
            // input.id <-- Name of custom event once completed, e.g. preload-custom
            // input.update <-- Boolean regarding whether or not to trigger progressive custom events
            // input.images <-- object of images to load {name: 'src'}
            // input.geometries <-- object of geometries to load {name: 'src'}
            // input.shaders <-- object of shaders to load {name: 'src'}
    
            var output = {};
            var total = 0;
            var loaded = 0;
            var _name;
    
            var tally = function() {
                loaded++;
    
                if (input.update) $.publish(input.id ? 'preload-update-' + input.id : 'preload-update', [loaded / total]);
    
                if (loaded == total) {
    
                    // Once loaded, fire a custom event with all of the loaded assets
                    $.publish(input.id ? 'preload-' + input.id : 'preload', [output]);
                }
            };
    
            // Preload images, if any, populate output.images with final images
            if (input.images) {
                output.images = {};
    
                var loadImage = function(name, src) {
                    total++;
                    var img = new Image();
                    img.src = src;
                    img.onload = function() {
                        output.images[name] = img;
                        tally();
                    };
                    img.onerror = function(e) {
                        console.log('error loading image', name, e);
                        tally();
                    };
                };
                for (_name in input.images) {
                    loadImage(_name, input.images[_name]);
                }
            }
    
            // Preload geometries, if any, populate output.geometries with final geometries
            if (input.geometries) {
                output.geometries = {};
    
                var jsonLoader = new THREE.JSONLoader();
                var bufferGeoloader = new THREE.BufferGeometryLoader();
                var loadGeometry = function(name, src) {
                    total++;
                    
                    // If src has 'bfr' use buffer loader, else, json. e.g 'assets/models/bfrGeoTrack.js'
                    if (src.indexOf('bfr') !== -1) {
                        bufferGeoloader.load(
                            src,
                            function(geometry) {
                                output.geometries[name] = geometry;
                                tally();
                            },
                            function() {},
                            function(xhr) {
                                console.log('error loading geometry', name, xhr);
                                tally();
                            }
                        );
                    } else {
    
                        // JSON loader has no error catch :(
                        jsonLoader.load(
                            src,
                            function(geometry) {
                                output.geometries[name] = geometry;
                                tally();
                            }
                        );
                    }
                };
                for (_name in input.geometries) {
                    loadGeometry(_name, input.geometries[_name]);
                }
            }
    
            // Preload shaders, if any, populate output.shaders with loaded shaders
            if (input.shaders) {
                output.shaders = {};
    
                var loadShader = function(name, src) {
                    total++;
                    $.ajax({
                        url: src,
                        dataType: 'text',
                        context: {
                            name: name
                        },
                        complete: function(e) {
                            output.shaders[this.name] = e.responseText;
                            tally();
                        }
                    });
                };
    
                for (_name in input.shaders) {
                    loadShader(_name, input.shaders[_name]);
                }
            }
        };
    
    });
    
    
    

    external by ??? ??????? modified Feb 22, 2015  57  0  1  0

    Preload HTML5 video with JavaScript

    Preload HTML5 video with JavaScript: load_video.js
    function progressHandler() {
    	if( video.duration ) {
    		var percent = (video.buffered.end(0)/video.duration) * 100;
    		if( percent >= 100 ) {
    			video.currentTime = 0;
    			console.log('video loaded');
    			return true;
    		}
    		video.currentTime++;
    	}
    }
    
    function addSourceToVideo(element, src, type) {
    	var source = document.createElement('source');
    
    	source.src = src;
    	source.type = type;
    
    	element.appendChild(source);
    	video.load();
    }
    
    console.log('video loading');
    addSourceToVideo(video, $(video).data('src'), "video/mp4");
    video.addEventListener('progress', progressHandler, false);
    
    

    external by Cory modified Aug 23, 2016  45  0  1  0

    Recursive function to preload array of PFObjects

    Recursive function to preload array of PFObjects: gistfile1.txt
    /**
     Recusivly pre load an array of PFObjects.
         
     - parameter items:      The items to preload.
     - parameter completion: Invoked once all loading in the background has been completed. If an error occured it will be passed back otherwise `success` will be `true` with a `nil` error parameter.
     */
    func preloadItems(items: [PFObject], completion: (success: Bool, error: NSError?) -> ()) {
            
        func recursiveLoad(index: Int) {
                
            if index == items.count {
                completion(success: true, error: nil)
                return
            }
                
            items[index].fetchInBackgroundWithBlock({ (object, error) in
                    
                if let err = error {
                    completion(success: false, error: err)
                    return
                }
                else {
                    recursiveLoad(index + 1)
                }
            })
        }
            
        recursiveLoad(0)
    }
    
    
    
    • Public Snippets
    • Channels Snippets