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
unless Array::indexOf | |
Array::indexOf = (search_element, from_index) -> | |
throw new TypeError '"this" is null or not defined' unless this? | |
length = @length >>> 0 # Hack to convert object.length to a UInt32 | |
from_index = +from_index or 0 | |
from_index = 0 if Math.abs(from_index) is Infinity | |
if from_index < 0 | |
from_index += length |
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
simulateClick = (elm) -> | |
evt = document.createEvent 'MouseEvents' | |
evt.initMouseEvent( | |
# type, canBubble, cancelable, view, | |
'click', true, true, window | |
# detail, screenX, screenY, clientX, clientY, | |
0, 0, 0, 0, 0 | |
# ctrlKey, altKey, shiftKey, metaKey, | |
false, false, false, false | |
# button, relatedTarget |
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
ajax = (url, callback = ->) -> | |
xhr = new XMLHttpRequest() | |
xhr.onreadystatechange = -> | |
if xhr.readyState is 4 | |
if xhr.status in [200, 304] | |
callback xhr.responseText | |
xhr.open 'GET', url, true | |
xhr.send() |
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
getClassNameRe = (classname) -> | |
/// | |
(^|\s) # beginning of string or whitespace | |
#{classname} | |
(\s|$) # end of string or whitespace | |
/// | |
hasClassName = (element, classname) -> | |
getClassNameRe(classname).test element.className |
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
isArray = Array.isArray or (obj) -> Object::toString.call obj is '[object Array]' |
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
var rootElm = document.getElementById('content'); | |
var paragraphs = rootElm.getElementsByTagName('p'); | |
for (i = 0; i < paragraphs.length; i++) { | |
rootElm.removeChild(paragraphs[i]); | |
} | |
/* | |
OTÁZKY | |
- Čo chcel autor týmto kódom dosiahnuť? |
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
addEvent = (object, event, callback = ->) -> | |
if object.addEventListener | |
object.addEventListener event, callback, false | |
else if object.attachEvent | |
object.attachEvent "on#{event}", callback | |
removeEvent = (object, event, callback = ->) -> | |
if object.removeEventListener | |
object.removeEventListener event, callback, false | |
else if object.detachEvent |
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
/* | |
Has two optional options parameters: | |
- length - 8 characters by default | |
- characters - upper- and lowercase characters and numbers by default | |
*/ | |
function getRandomString(options, callback) { | |
options = options || {}; | |
options.length = options.length || 8; | |
options.characters = options.characters || '0123456789ABCDEFGHIJKLMNOPQRSTUVWXTZabcdefghiklmnopqrstuvwxyz'; |
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
mergeUrlParams = (params = {}) -> ("#{key}=#{val}" for key, val of params).join '&' |
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
<!DOCTYPE html> | |
<html> | |
<head> | |
<meta charset="utf-8"> | |
<title></title> | |
</head> | |
<body> | |
<div> | |
<p id="myElement">First paragraph.</p> |
OlderNewer