Skip to content

Instantly share code, notes, and snippets.

@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
*/
?>
@sivagao
sivagao / ga_tracking.js
Created July 18, 2013 22:57
using google analytics to track|log your page action|event. http://think2loud.com/105-use-jquery-with-google-analytics-to-track-clicks-on-outgoing-links-from-your-site/ todo: understand what ga do in default..
var gaJsHost = (("https:" == document.location.protocol) ? "https://ssl." : "http://www.");
document.write(unescape("%3Cscript src='" + gaJsHost + "google-analytics.com/ga.js'type='text/javascript'%3E%3C/script%3E"));
var pageTracker = _gat._getTracker("YOUR ACCOUNT NUMBER HERE"); pageTracker._trackPageview();
$(document).ready(function(){
$('a[data*="track"]').click(function(){
pageTracker._trackPageview('click_link/'+$(this).attr('href'));
});
});
.stack { position: fixed; bottom: 28px; right: 40px; }
.stack > img { position: relative; cursor: pointer; padding-top: 35px; z-index: 2; }
.stack ul { list-style: none; position: absolute; top: 5px; cursor: pointer; z-index: 1; }
.stack ul li { position: absolute; }
.stack ul li img { border: 0; }
.stack ul li span { display: none; }
.stack .openStack li span {
font-family: "Lucida Grande", Lucida, Verdana, sans-serif;
display:block;
height: 14px;