Skip to content

Instantly share code, notes, and snippets.

View PeterRao's full-sized avatar

Undefined PeterRao

  • 北京
View GitHub Profile
@PeterRao
PeterRao / .jshintrc
Created March 3, 2014 03:04
JSHint 文件
{
// JSHint Default Configuration File (as on JSHint website)
// See http://jshint.com/docs/ for more details
"maxerr" : 100, // {int} Maximum error before stopping
// Enforcing
"bitwise" : true, // true: Prohibit bitwise operators (&, |, ^, etc.)
"camelcase" : true, // true: Identifiers must be in camelCase
"curly" : true, // true: Require {} for every new block or scope
@PeterRao
PeterRao / first.js
Created March 27, 2014 10:46 — forked from sofish/first.js
// 大家写在评论中吧,代码高亮可以这样写:
// ```js
// your code
// ```
// update: Fri Aug 31 08:39:21
// copyright: https://gist.github.com/3549352
// 加个性能测试:http://jsperf.com/get-dom-s-first-element
var util = {};

This Is Absolutely Tiring

Every time I start a node module, or a new JS project, I'm confronted with this same question: how do I structure it to allow it to be used in the browser or nodejs, without requiring a build step, and without getting in the way of my development?

While developing, I typically create some type of [browser-based environment][]; Firebug and Web Inspector are still miles ahead of anything else we've got. Ideally I want to be able to add a file via a script tag, and have that be the only requirement.

As @visionmedia [points out][], this is [ridiculous][].

This gist is meant to compile all of the various ways I've seen of guarding against/for a variety of module systems. Fork it and add your own, I'll try to bring them into this one.

@PeterRao
PeterRao / judgeINIframe
Last active August 29, 2015 14:05
How to judge whether 1 JS in iframe(http://www.programering.com/a/MDOwMzMwATg.html)
//One way
if (self.frameElement && self.frameElement.tagName == "IFRAME") {
alert('In iframe');
}
//Methods two
if (window.frames.length != parent.frames.length) {
alert('In iframe');
}
//Fang Shisan
if (self != top) {
@PeterRao
PeterRao / urlparser.js
Last active August 29, 2015 14:11 — forked from sofish/urlparser.js
var parser = function(url) {
var a = document.createElement('a');
a.href = url;
var search = function(search) {
if(!search) return {};
var ret = {};
search = search.slice(1).split('&');
for(var i = 0, arr; i < search.length; i++) {
/*
* Remove the gap between images and the bottom of their containers: h5bp.com/i/440
*/
img {
vertical-align: middle;
}
@PeterRao
PeterRao / page_status.js
Created October 15, 2013 04:36
查看jqmpage事件代码
$(document).on('pagebeforecreate', '[data-role="page"]', function(){
console && console.log($(this).attr('id') + " - pagebeforecreate!!");
});
$(document).on('pagecreate', '[data-role="page"]', function(){
console && console.log($(this).attr('id') + " - pagecreate!!");
});
$(document).on('pageinit', '[data-role="page"]', function(){
console && console.log($(this).attr('id') + " - pageinit!!");
/**
* Clearfix helper
* Used to contain floats: h5bp.com/q
*/
.clearfix:before, .clearfix:after {
content: "";
display: table;
}
.clearfix:after {
@PeterRao
PeterRao / 去除首尾空格
Last active December 26, 2015 04:59
正则表达式去除首尾空格
var trim = function(s){
return s.replace(/(^\s*)|(\s*$)/g, "");
};
@PeterRao
PeterRao / 0_reuse_code.js
Created December 14, 2013 10:13
Here are some things you can do with Gists in GistBox.
// Use Gists to store code you would like to remember later on
console.log(window); // log the "window" object to the console