Created
March 16, 2009 02:12
-
-
Save gerald-kim/79651 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/**_______________________________________ | |
* | |
* nfx :: simple effects in few bytes | |
* --------------------------------------- | |
* | |
* @author Andrea Giammarchi | |
* @site http://www.devpro.it/nfx/ | |
* @version 0.4 | |
* @requires anything * | |
* * old browsers (IE <= 5) should require JSL | |
* @credits Matteo Galli (aka Ratatuia) for Safari debug, | |
* Boyan Djumakov, for debug and reports (http://webnos.blogspot.com/) | |
* --------------------------------------- | |
* | |
* Copyright (c) 2006 Andrea Giammarchi | |
* | |
* Permission is hereby granted, free of charge, | |
* to any person obtaining a copy of this software and associated | |
* documentation files (the "Software"), | |
* to deal in the Software without restriction, | |
* including without limitation the rights to use, copy, modify, merge, | |
* publish, distribute, sublicense, and/or sell copies of the Software, | |
* and to permit persons to whom the Software is furnished to do so, | |
* subject to the following conditions: | |
* | |
* The above copyright notice and this permission notice shall be included | |
* in all copies or substantial portions of the Software. | |
* | |
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, | |
* INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | |
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. | |
* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, | |
* DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, | |
* ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE | |
* OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. | |
* _______________________________________ | |
*/ | |
nfx = new function(){ | |
// public methods | |
/** | |
* public method, | |
* nfx.drag(element:Object[, start:Function[, end:Function[, callback:Function[, position:Object]]]]):Void | |
* @param Object X/HTML Element to make draggable | |
* @param Function callback to call with element as scope on drag init | |
* @param Function callback to call with element as scope on drag end | |
* @param Function callback to call with element as scope during drag | |
* @param Object object with 4 properties: | |
* $x, $y, x$, y$ | |
* Each propery should be an Int32 or null but must be present. | |
* @example | |
* nfx.drag(document.getElementById("some-div")); // base | |
* nfx.drag(someDiv, initCallback); // base with an init callback | |
* nfx.drag(someDiv, null, endCallback); // base with an end callback | |
* nfx.drag(someDiv, null, null, null, {$y:10, y$:10, $x:null, x$:null}); | |
* // blocked Y position | |
*/ | |
this.drag = function(elementName){ | |
element = document.getElementById( elementName ); | |
click_element = document.getElementById( elementName + '_bar' ); | |
click_element.style.cursor = 'move'; | |
var tmp = $element(element).nfx.drag; | |
nfx.$event(click_element, "onmousedown", function(evt){ | |
tmp.start = true; | |
tmp.onmousedown = d.onmousedown; | |
tmp.onmouseup = d.onmouseup; | |
d.onmouseup = element.onmouseup; | |
return false; | |
}); | |
nfx.$event(click_element, "onmouseup", function(evt){ | |
tmp.start = false; | |
d.onmousedown = tmp.onmousedown; | |
d.onmouseup = tmp.onmouseup; | |
return false; | |
}); | |
nfx.$event(d, "onmousemove", function(evt){ | |
var x = evt.clientX, | |
y = evt.clientY, | |
size = {x: x - tmp.x, y: y - tmp.y}; | |
if(tmp.start) { | |
nfx.position(element, size); | |
} | |
else{ | |
tmp.x = x - element.offsetLeft; | |
tmp.y = y - element.offsetTop; | |
}; | |
return false; | |
}); | |
}; | |
this.position = function(element, position){ | |
var style = $element(element).style; | |
style.position = "absolute"; | |
style.left = position.x + "px"; | |
style.top = position.y + "px"; | |
}; | |
this.$event = function(element, tmp, callback){ | |
var value = element[tmp]; | |
element[tmp] = function(evt){ | |
if(!evt) | |
evt = w.event; | |
if(value) | |
value.call(this, evt); | |
return callback.call(this, evt); | |
}; | |
}; | |
this.$position = function(element){ | |
var position = {x:element.offsetLeft, y:element.offsetTop}; | |
while(element = element.offsetParent){ | |
position.x += element.offsetLeft; | |
position.y += element.offsetTop; | |
}; | |
return position; | |
}; | |
this.$size = function(element){ | |
return {width:element.offsetWidth, height:element.offsetHeight}; | |
}; | |
this.size$ = function(element, size){ | |
var style = element.style; | |
style.width = size.width + "px"; | |
style.height = size.height + "px"; | |
}; | |
function $element(element){ | |
if(!element.nfx) | |
element.nfx = {color:0, drag:{}, fade:0, move:0, scroll:0, size:0}; | |
return element; | |
}; | |
function $end(x, y, speed){ | |
return x < y ? min(x + speed, y) : max(x - speed, y); | |
}; | |
function $setInterval(element, interval, speed, start, position, style, tmp, callback){ | |
clearInterval(element.nfx[interval]); | |
element.nfx[interval] = setInterval(function(){ | |
start[style[0]] += (position[style[0]] - start[style[0]]) * speed; | |
start[style[1]] += (position[style[1]] - start[style[1]]) * speed; | |
nfx[tmp](element, start); | |
if(round(start[style[0]]) == position[style[0]] && round(start[style[1]]) == position[style[1]]){ | |
nfx[tmp](element, position); | |
$callback(element, interval, callback); | |
} | |
}, 1); | |
}; | |
var w = window, | |
d = document, | |
max = Math.max, | |
min = Math.min, | |
round = Math.round; | |
}; | |
nfx.drag( 'nbookmark' ); | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function naverbookmark_open() { | |
bookmarkDiv = document.getElementById( 'nbookmark_layer' ); | |
var isInternetExplorer = navigator.appName.indexOf("Microsoft") != -1; | |
var title = document.title; | |
if ( !isInternetExplorer ) { | |
var title = document.getSelection().length>0?document.getSelection().substring(0,200):document.title; | |
} | |
var scrOfY = 0; | |
if( typeof( window.pageYOffset ) == 'number' ) { | |
scrOfY = window.pageYOffset; | |
} else if( document.body && ( document.body.scrollLeft || document.body.scrollTop ) ) { | |
scrOfY = document.body.scrollTop; | |
} else if( document.documentElement && ( document.documentElement.scrollLeft || document.documentElement.scrollTop ) ) { | |
scrOfY = document.documentElement.scrollTop; | |
} | |
postUrl = "http://bookmark.naver.com/post?ns=1&ui=iframe&close=false&url=" + encodeURIComponent(document.location) + "&title=" + encodeURIComponent( title ); | |
postUrl = postUrl.replace( /"/g, '\\\"' ); | |
html = '<div id="nbookmark" style="width:513px; background:url(http://bookmarkimgs.naver.com/img/bg_gr.gif);position:absolute; top:'+ ( scrOfY + 200 ) +'px; left:105px;z-index:9999999">' | |
html+= '<div style="position:relative; top:-2px; left:-1px;">' | |
html+= ' <table width="512" height="318" cellspacing="0" cellpadding="0" style="background-color:#8BC557; border:1px solid #777777;">' | |
html+= '<tr><td align="center" style="padding:9px 0 9px 0">' | |
html+= ' <table cellspacing="0" cellpadding="0" border="0">' | |
html+= ' <tr><td height="43"><div id="nbookmark_bar"><img src="http://bookmarkimgs.naver.com/img/pop_logo02_1.gif" alt="" width="463" height="43" border="0"></div></td>' | |
html+= ' <td><img src="http://bookmarkimgs.naver.com/img/pop_logo02_2.gif" alt="" width="29" height="43" usemap="#nbookmark_go" border="0"></td></tr>' | |
html+= ' <tr><td colspan="2" align="center" style="background:url(http://bookmarkimgs.naver.com/img/pop_rnd01.gif) left bottom; padding:10px 0 1px 0;">' | |
html+= '<iframe name="papermain" src="' + postUrl + '" width="450" height="260" frameborder="0" scrolling="no"></iframe></td></tr>' | |
html+= ' </table>' | |
html+= ' </td></tr></table></div></div>' | |
html+= '<map name="nbookmark_go"><area alt="close" coords="1,12,26,32" href="javascript:naverbookmark_close()"></map>' | |
if ( null == bookmarkDiv ) { | |
bookmarkDiv = document.createElement( 'DIV' ); | |
bookmarkDiv.id = 'nbookmark_layer'; | |
bookmarkDiv.style.top = '0'; | |
bookmarkDiv.style.left= '0'; | |
bookmarkDiv.style.zIndex = '99999999'; | |
document.body.appendChild( bookmarkDiv ); | |
} else { | |
bookmarkDiv.style.top = scrOfY + ''; | |
bookmarkDiv.style.display = 'inline'; | |
} | |
bookmarkDiv.innerHTML = html; | |
scriptElement = document.getElementsByTagName('HEAD')[0].appendChild( document.createElement('script') ); | |
scriptElement.type = 'text/javascript'; | |
scriptElement.src = 'http://bookmark.naver.com/api/bookmarklet_drag.js'; | |
} | |
function naverbookmark_close() { | |
bookmarkDiv = document.getElementById( 'nbookmark_layer' ); | |
if( null != bookmarkDiv ) { | |
bookmarkDiv.style.display='none'; | |
} | |
} | |
naverbookmark_open(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
javascript:void((function(){if(document.getElementsByTagName('body')[0]!=undefined&&document.links.length%3E0){s=document.createElement('script');s.setAttribute('src','http://bookmark.naver.com/api/bookmarklet.js');document.body.appendChild(s);%20}else{setTimeout('nbw.focus()',500);nbw=window.open('http://bookmark.naver.com/post?ns=1&ui=popup&url='+encodeURIComponent(document.location)+'&title='+encodeURIComponent(document.title),'naver_bookmark','width=520,height=365,resize=no');}})()) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment