Allows you to assign an event handler to an element.
function addEvent(obj, eventName, callback){
if (obj.addEventListener){
obj.addEventListener(eventName, callback, false);
} else if (obj.attachEvent){
/* | |
cleaner than hard-coding the desired font size | |
refs: http://api.jquery.com/css/ | |
some use case: | |
all these websites that use *huge* font sizes, | |
painful to read even on a 1920x1080 screen. | |
*/ | |
$('.article-content').css('font-size', '-=2'); |
// More elaborate code can be found here: | |
// https://github.com/jquery/jquery/blob/master/src/manipulation.js | |
function prepend(target, elem) { | |
target.insertBefore(elem, target.firstChild); | |
} | |
function append(target, elem) { | |
target.appendChild(elem); | |
} |
<?php | |
namespace App; | |
use Illuminate\Database\Eloquent\Model; | |
class User extends Model | |
{ | |
/** | |
* Scope a query to return a random users Model. |
<?php | |
trait OrderByRandomTrait | |
{ | |
/** | |
* Scope to order by random. | |
* | |
* @param \Illuminate\Database\Query\Builder $query | |
* @return \Illuminate\Database\Query\Builder | |
*/ | |
public function scopeOrderByRandom($query) |
/* | |
1. post a link in chat. (ex. https://github.com/) | |
2. post anything with 3 or more "w"s in a row. (ex. www, wowww,wwwwwwwwww) | |
3. use {/geturl} and you'll get the word with the 3 "w" in it and not the url. | |
Fix: Validate url. | |
*/ | |
var url:String = "http://www.google.com"; | |
var regex:RegExp = /^http(s)?:\/\/((\d+\.\d+\.\d+\.\d+)|(([\w-]+\.)+([a-z,A-Z][\w-]*)))(:[1-9][0-9]*)?(\/([\w-.\/:%+@&=]+[\w- .\/?:%+@&=]*)?)?(#(.*))?$/i; | |
trace(regex.test(url)); // returns true if valid url is found |
getSize : function () { | |
if (isBody(this)) | |
return this.getWindow().getSize(); | |
return { | |
x : this.offsetWidth || styleNumber(this, 'width'), | |
y : this.offsetHeight || styleNumber(this, 'height') | |
}; | |
} |