working on it ...

Filters

Explore Public Snippets

Sort by

Found 5,285 snippets matching: browser

    public by cghersi  204467  0  6  2

    Embed a browser into SWT Dialog and manage the firing of popups from links in the displayed page

    This is how to manage an embedded browser. Note: unfortunately this seems not working on some versions of Mac OS X.
    try {
    	Browser browser = new Browser(this, SWT.NONE);
    	browser.setJavascriptEnabled(true);
    	browser.setUrl("www.myurl.com");
    	browser.addOpenWindowListener(new OpenWindowListener() {
    		public void open(WindowEvent event) {
    			log.debug("Opening browser:" + event);
    			new Thread( new Runnable() {
    	            public void run() {
    	            	log.debug("some stuff t do here...");
    	            }
    			}).start();
    			
    			final Shell shell = new Shell(event.display);
    		    shell.setText("My Browser page");
    		    shell.setLayout(new FillLayout());
    		    event.browser = new Browser(shell, SWT.NONE);
    		    shell.open();
    		    
    		    event.browser.addCloseWindowListener(new CloseWindowListener() {
    				@Override
    				public void close(WindowEvent event) {
    					log.debug("closing");
    					shell.setVisible(false);
    				}
    			});
    		}
    	});
    } catch (Throwable t) {
    	//on some architecture seems that SWT Browser is not working...
    	log.warn("Cannot display SWT Browser");
    }

    public by LongBeard  173281  5  3  0

    Cross Browser Transparency

    Cross Browser Transparency: crossTransparency.css
    .transparent {
        filter: alpha(opacity=50); /* internet explorer */
        -khtml-opacity: 0.5;      /* khtml, old safari */
        -moz-opacity: 0.5;       /* mozilla, netscape */
        opacity: 0.5;           /* fx, safari, opera */
    }
    
    

    public by sTiLL-iLL  235415  1  7  15

    ES5 Array funKtion polly-fillerz...

    just in case your browser sucks
    
    // filler for Array.prototype.bind()
    
    if (!Function.prototype.bind) {
      Function.prototype.bind = function(that) {
        if (typeof this !== 'function') {
          throw new TypeError('obj is not callable');
        }
        var a_Argz = Array.prototype.slice.call(arguments, 1), noop = function() {},
            bFnky = this, bnd  = function() {
              return bFnky.apply(this instanceof noop && that? this: that,
                     a_Argz.concat(Array.prototype.slice.call(arguments)));
            };
    
        noop.prototype = this.prototype;
        bnd.prototype = new noop();
        return bnd;
      };
    }
    
    // different approach for isArray()...
    
    function isArray (list) {
      
    }
    
    if (!Array.isArray) {
      Array.isArray = function(argz) {
        return Object.prototype.toString.call(argz) === '[object Array]';
      };
    }
    
    function isArray (list) {
      if (Array.isArray) {
        return Array.isArray(list);
      }
    }
    
    function isArray (list) {
      if (Array.isArray) {
        return Array.isArray(list);
      }
      return Object.prototype.toString.call(list) === '[object Array]';
    }
    
    
    var isArray;
    var isArray = (function () {
      
    })();
    
    var isArray = (function () {
      if (Array.isArray) {
        return Array.isArray;
      }
    })();
    
    var isArray = (function () {
      if (Array.isArray) {
        return Array.isArray;
      }
      return function (list) {
        return Object.prototype.toString.call(list) === '[object Array]';
      };
    })();
    
    function (list) {
      return Object.prototype.toString.call(list) === '[object Array]';
    }                        

    public by Github  76046  0  3  0

    Created using browser-solidity: Realtime Ethereum Contract Compiler and Runtime. Load this file by pasting this gists URL or ID at https://chriseth.github.io/browser-solidity/#version=soljson-latest.js&optimize=undefined&gist=

    Created using browser-solidity: Realtime Ethereum Contract Compiler and Runtime. Load this file by pasting this gists URL or ID at https://chriseth.github.io/browser-solidity/#version=soljson-latest.js&optimize=undefined&gist=: Untitled
    contract Ballot {
    
        struct Voter {
            uint weight;
            bool voted;
            uint8 vote;
            address delegate;
        }
        struct Proposal {
            uint voteCount;
        }
    
        address chairperson;
        mapping(address => Voter) voters;
        Proposal[] proposals;
    
        // Create a new ballot with $(_numProposals) different proposals.
        function Ballot(uint8 _numProposals) {
            chairperson = msg.sender;
            voters[chairperson].weight = 1;
            proposals.length = _numProposals;
        }
    
        // Give $(voter) the right to vote on this ballot.
        // May only be called by $(chairperson).
        function giveRightToVote(address voter) {
            if (msg.sender != chairperson || voters[voter].voted) return;
            voters[voter].weight = 1;
        }
    
        // Delegate your vote to the voter $(to).
        function delegate(address to) {
            Voter sender = voters[msg.sender]; // assigns reference
            if (sender.voted) return;
            while (voters[to].delegate != address(0) && voters[to].delegate != msg.sender)
                to = voters[to].delegate;
            if (to == msg.sender) return;
            sender.voted = true;
            sender.delegate = to;
            Voter delegate = voters[to];
            if (delegate.voted)
                proposals[delegate.vote].voteCount += sender.weight;
            else
                delegate.weight += sender.weight;
        }
    
        // Give a single vote to proposal $(proposal).
        function vote(uint8 proposal) {
            Voter sender = voters[msg.sender];
            if (sender.voted || proposal >= proposals.length) return;
            sender.voted = true;
            sender.vote = proposal;
            proposals[proposal].voteCount += sender.weight;
        }
    
        function winningProposal() constant returns (uint8 winningProposal) {
            uint256 winningVoteCount = 0;
            for (uint8 proposal = 0; proposal < proposals.length; proposal++)
                if (proposals[proposal].voteCount > winningVoteCount) {
                    winningVoteCount = proposals[proposal].voteCount;
                    winningProposal = proposal;
                }
        }
    }
    
    
    

    public by sTiLL-iLL  3934  2  9  36

    my event-emitter.... for your browser

    SignalEmitter.js super fast async events, with an API like nodejs' EventEmitter
    // Eventually I'll get it
    
    var SignalEmitter = (function () {
    	var _sigCache = [],
    		_singleRecieve_retval = {};
    	function _isArry(obj) {
    		return (obj.constructor === Array);
    	}
    	function _receiverObjects(eventName) {
    		var recvrLst = _allReceivers(eventName), rspns;	
    		if (_isArry(recvrLst)) {
    			rspns = {};
    			rspns[eventName] = recvrLst;
    		}	
    		return rspns || recvrLst;
    	}
    	function _sigRecv(eventName, func) {
    		if (!_sigCache) {
    			_sigCache = [];
    		}
    		if (!_sigCache[eventName]) {
    			_sigCache[eventName] = func;
    		} 
    		else if (_isArry(_sigCache[eventName])) {
    			_sigCache[eventName].push(func);
    		} 
    		else {
    			_sigCache[eventName] = [_sigCache[eventName], func];
    		}	
    		return this;
    	}
    	function _allReceivers(eventName) {
    		if (!_sigCache) {
    			_sigCache = [];
    		}
    		if (!_sigCache[eventName]) {
    			_sigCache[eventName] = [];
    		}
    		if (!_isArry(_sigCache[eventName])) {
    			_sigCache[eventName] = [_sigCache[eventName]];
    		}
    		return _sigCache[eventName];
    	}	
    	function _emitSignal(eventName, args) {
    		var recvrLst = _receiverObjects(eventName),
    			k, recvr, i, rspns;
    		for (k in recvrLst ) {
    			if (recvrLst.hasOwnProperty(k)) {
    				i = recvrLst[k].length;		
    				while (i--) {
    					recvr = recvrLst[k][i];
    					if (recvr._signalOnce === true) {
    						_removeReceiver(eventName, recvr);
    					}	
    					rspns = recvr.call(this, args || []);
    					if (rspns === _getOnce_RetVal()) {
    						_removeReceiver(eventName, recvr);
    					}
    				}
    			}
    		}
    		return this;
    	}
    	function _signalOnce(eventName, func) {
    		var slf = this;
    		function onit () {
    			slf._removeReceiver(eventName, _sigRecv);
    			func.apply(this, args);
    		}
    		_sigRecv.receiver = func;
    		this.onit(eventName, _sigRecv);	
    		return this;
    	}
    	function _getOnce_RetVal() {
    		if (_singleRecieve_retval) {
    			return _singleRecieve_retval;
    		}
    		else {
    			return true;
    		}
    	}
    	function _setOnce_RetVal(val) {
    		_singleRecieve_retval = val;
    		return this;
    	}
    	function _removeReceiver(eventName, func) {
    		if (_sigCache && _sigCache[eventName]) {
    			var sigLst = _sigCache[eventName];	
    			if (_isArry(sigLst)) {
    				var idx = -1;
    				for (var i = 0, l = sigLst.length; i < l; i++) {
    					if (sigLst[i] === func || (sigLst[i].receiver && sigLst[i].receiver === func)) {
    						idx = i;
    						break;
    					}
    				}
    				
    				if (idx < 0) {
    					return this;
    				}
    				
    				sigLst.splice(idx, 1);
    				if (!sigLst.length) {
    					delete _sigCache[eventName];
    				}
    			} 
    			else if (sigLst === func || (sigLst.receiver && sigLst.receiver === func)) {
    				delete _sigCache[eventName];
    			}
    		}
    		return this;
    	}
    	
    	var receive = function(eventName, func) {
    		return _sigRecv(eventName, function(evnt){
    			func(evnt);
    		});
    	},
    	dropReceiver = function(eventName, func) {
    		return _removeReceiver(eventName, function(evt){
    			func(evt);
    		});
    	},
    	dropReceivers = function (eventName) {
    		if (!eventName) {
    			_sigCache = {};
    			return this;
    		}
    		if (_sigCache && _sigCache[eventName]) {
    			_sigCache[eventName] = null;
    		}
    		return this;
    	},   
    	receivers = function (eventName) {
    		return _allReceivers(eventName);
    	},	
    	assignTo = function(eventName, func) {
    		return _sigRecv(eventName, function(evnt){
    			func(evnt);
    		});
    	},
    	castSingle = function(eventName, func) {
    		return _signalOnce(eventName, function(evt) {
    			func(evt);
    		});
    	},
    	sgCast = function(eventName, args) {
    		return _emitSignal(eventName, args);
    	};
    	return {
    		emit: sgCast,
    		on: assignTo,
    		receive: receive,
    		once: castSingle,
    		dropReceiver: dropReceiver,
    		off: dropReceiver,
    		addReceiver: assignTo,
    		getReceivers: receivers,
    		dropReceivers: dropReceivers
    	};
    })();
    
    exports.SignalEmitter = SignalEmitter;
    

    public by micurs  3915  8  8  1

    Change the address in the browser without reloading

    In HTML5 it is possible to change part of the address in the address browser without reloading the page. This helps building single page site with elements of the UI addressable using a consistent URL. See an example here: http://www.usatoday.com/ . By clicking on any article box a popup within the same page shows the content, and the URL in the
    // This add a new state to the browser history and replace the path
    window.history.pushState( stateObj, 'content title', '/new-path');
    
    // This replace the current state to the browser history and replace the path
    window.history.replaceState(stateObj, 'content title', '/new-path');
    

    public by sTiLL-iLL  2070  1  7  16

    use Cheez to slow rapid-firing callbacks and animations

    //'Cheez' slows callbacks, kinda like underscore's unbounce
     
    function Cheez(restFor, instant, fnc) {
        var tmOt,
        slam = function() {
            var args = arguments,
            slf = this,
            
            nxter = function() {
                tmOt = null;
                if (!instant){
                  fnc.apply(slf, args);
                }
            };
            
            var goNow = instant && !tmOt;
            clearTimeout(tmOt);
            tmOt = setTimeout(nxter, restFor);
            
            if (goNow){
              fnc.apply(slf, args);
            }
        };
        
       return slam;
    }
     
    // every 350 ms
    window.addEventListener('resize',
        Cheez(function(evt) {
          // somethin....
        },
    350));

    public by zonaro  4386  34  7  1

    Console Hacking - Get all Images of webpage using Jquery

    Just paste it on your webbrowser console and every image will be opened in a new tab (turn off your pop up blocker)
    var imgs = $("img").map(function () { return this.src; });
    for (var i = 0; i < imgs.length; i++) { 
       window.open( imgs[i]); 
    }

    public by mporru @ Amazon_AWS_PHP_API  2699  18  5  0

    Amazon AWS - PHP: Download file to browser

    This snippet demonstrates how to download a file stored in your S3 Bucket to your browser. In order to use this service you must enable Amazon Simple Storage Service (Amazon S3) in your account.
    <?php
    require_once('sdk.class.php');
    $s3 = new AmazonS3();
    
    $fileName = 'LighthouseNew.jpg';
    $bucketName = 'myBucketName';
    
    $obj = $s3->get_object($bucketName, $fileName);
    header("Content-Type: application/force-download");
    header("Content-Disposition: attachment; filename=$fileName;");
    
    echo $obj->body;
    ?>

    public by JKCPR  3257  8  5  2

    Debug PHP using XdeBug in Browser console...nice

    Parses PHP debugging log messages via JSON into browser console.
    <?php
    /**
     * Send debug code to the Javascript console
     */ 
    function debug_to_console($data) {
        if(is_array($data) || is_object($data))
    	{
    		echo("<script>console.log('PHP: ".json_encode($data)."');</script>");
    	} else {
    		echo("<script>console.log('PHP: ".$data."');</script>");
    	}
    }
    ?>         
    • Public Snippets
    • Channels Snippets