Skip to content

Instantly share code, notes, and snippets.

@sivagao
sivagao / changelog.md
Created July 19, 2013 06:34
jQuery changes log since version 1.4

http://blog.jquery.com/2011/01/31/jquery-15-released/ ajax rewrite: a call to jQuery.ajax (or jQuery.get, jQuery.post, etc.) now returns a jqXHR object that provides consistency to the XMLHttpRequest object across platforms much more extensible – allowing you to attach all sort of data handlers, filters, and transports.

deferred objects: to work with return values that may not be immediately present (such as the return result from an asynchronous Ajax request).

@sivagao
sivagao / mediator.js
Last active December 19, 2015 23:49
javascript & jQuery patterns text from book jQuery patterns<essential javascript design patterns for beginners> <javascript patterns><javascript design patterns><Learning.JavaScript.Design.Patterns>
/*
applications are made up of separate objects, which need a way to communicate among themselves.
when objects know too much about each other, and communicate directly.. means, too tight coupling.
in this pattern
independent objects(colleagues) dont communicate directly. but through a mediator object
*/
function Player(name){
@sivagao
sivagao / textReplace.js
Created July 19, 2013 05:37
text replacement with javascript. for example add <span class="searhterm"> for search result.
/*
Progress:
Essentially, the right way to do it is…
Iterate over all text nodes.
Find the substring in text nodes.
Split it at the offset.
Insert a span element in between the split.
*/
matchText(document.getElementsByTagName('artcle')[0], new RegExp("\\b" + saerchTerm + "\\b",'g'), function(){
@sivagao
sivagao / gist:6035195
Created July 19, 2013 04:17
Different between jQuery and Zepto Zepto markets itself as a minimalist JavaScript library for modern browsers with a largely jQuery-compatible API. So just how close is Zepto’s
Selectors
Zepto implements only a subset of jQuery’s proprietary selectors. It’s definitely something to be mindful of.
clone()
Zepto’s clone() doesn’t support passing in an argument to clone event handlers.
data()
Unlike jQuery, Zepto doesn’t attempt to do any type inferring from the value stored in the data-* attribute.
offset()
@sivagao
sivagao / git.submodule
Created July 19, 2013 04:09
git submodule使用 http://josephj.com/entry.php?id=342 剛剛從 SVN 或 CVS 等 Client-Server 架構的版本控制系統切換到 Git 時,可能會有這個想法:「能不能只取得一部分的程式碼、而非整個 Repository?」因為在 SVN/CVS 可以針對 Repository 中的某個目錄 checkout,不需要是整個 Repository、甚至還可以用 SVN Externals 達到不同角色 (視覺、前端、後端)checkout 不同 File Layout Git Submodule 可以輕易地將別人的 git 掛入到你目前 git 的任何位置。
Example
目前本機有一個 josephj.git、在 /home/josephj/www 下,而我需要將 javascript platform 放到 /home/josephj/www/static/
cd /home/josephi/www
git submodule add <git addr> static/platform
论坛
在父亲项目下, 删除目录(template/weekxx, static/)
// Back in the old days, classes were manipulated on elements simply with the className property.
// This led to an awful lot of string manipulation for manipulating the class attribute.
Thankfully, the classList property has popped up recently.
var supportsClassList = ({}).toString.call(document.body.classList) == '[object DOMTokenList]';
the fallback implementation
var getClasses = function(element){
return element.className.split(/\s+/);
}
<div id="loadplace<?php echo $msg_id; ?>"></div>
<div id="flash<?php echo $msg_id; ?>"></div>
<div class='panel' id="slidepanel<?php echo $msg_id; ?>">
<form action="" method="post" name="<?php echo $msg_id; ?>">
<textarea id="textboxcontent<?php echo $msg_id; ?>" ></textarea><br />
<input type="submit" value=" Comment_Submit " class="comment_submit" id="<?php echo $msg_id; ?>" />
</form>
</div>
@sivagao
sivagao / $.fn.isvisible.js
Created July 19, 2013 01:25
Slide In (as you scroll down) Boxes @ nexus 7 Google+ app http://css-tricks.com/slide-in-as-you-scroll-down-boxes/
(function($) {
/**
* @author Sam Sehnert
* @desc A small plugin that checks whether elements are within
* the user visible viewport of a web browser.
* only accounts for vertical position, not horizontal.
*/
$('#content a').each(function () {
$('<div class="fader" />').css('opacity', 0).prependTo(this);
}).hover(function () {
$('img', this).stop().animate({
marginLeft : 5
}, 250);
$('.fader', this).stop().animate({
opacity : 0.15
});
<?php
/*
* Simple but powerful flatfile database
* See http://lukeplant.me.uk/resources/flatfile/ for documentation and examples
*/
?>