Skip to content

Commit

Permalink
Welcome, El Raptor.
Browse files Browse the repository at this point in the history
Adding the source files.
  • Loading branch information
Caio Tarifa committed Aug 26, 2015
0 parents commit af209ea
Show file tree
Hide file tree
Showing 7 changed files with 192 additions and 0 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
### OSX ###
.DS_Store
79 changes: 79 additions & 0 deletions readme.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
# Vanilla Raptorize

This is a lightweight port from the original [Zurb Raptorize](http://zurb.com/playground/jquery-raptorize) made with modern technologies.

## Usage

First of all, you'll need instance that:

```javascript
var myRaptor = Raptorize();
```

Then, when you want to see El Raptor on your screen, just call him like this:

```javascript
myRaptor.go();
```

## Configurations

These are our defaults:

```javascript
{
audioPath: ['assets/sounds/raptor.mp3', 'assets/sounds/raptor.ogg'],
imagePath: 'assets/images/raptor.png',

className: 'raptor',
animationTime: 2000
}
```

You can override any option:

```javascript
var myRaptor = Raptorize({
className: 'el-raptor',
animationTime: 500
});
```

## Examples

### Click Event

```javascript
var myRaptor = Raptorize();

// Without jQuery
document.querySelector('my-selector').addEventListener('click', myRaptor.go);

// With jQuery
$('my-selector').on('click', myRaptor.go);

```

### Konami Code

```javascript
var myRaptor, konamiIndex, konamiCode;

myRaptor = Raptorize();
konamiIndex = 0;
konamiCode = [38, 38, 40, 40, 37, 39, 37, 39, 66, 65, 13];

window.addEventListener('keydown', function(event) {
if (event.keyCode === konamiCode[konamiIndex]) {
konamiIndex++;
if (konamiIndex == konamiCode.length) { myRaptor.go(); }
} else {
konamiIndex = 0;
}
});

```

---

That's all, folks.
Binary file added source/assets/images/raptor.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added source/assets/sounds/raptor.mp3
Binary file not shown.
Binary file added source/assets/sounds/raptor.ogg
Binary file not shown.
29 changes: 29 additions & 0 deletions source/vanilla-raptorize.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
@keyframes raptorGO {
25% {
transform: translateY(0);
}
35% {
right: 0;
transform: translateY(25%);
}
75% {
opacity: 1;
}
100% {
opacity: 0;
right: 100%;
transform: translateY(25%);
}
}

.raptor {
display: none;
bottom: 0;
position: fixed;
transform: translateY(100%);
right: 0;
}

.raptor-go {
animation: raptorGO 2500ms;
}
82 changes: 82 additions & 0 deletions source/vanilla-raptorize.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
var Raptorize = (function(extended) {
'use strict';

var body, defaults, options,
audioTemplate, sourceAudioTemplate, imageTemplate,
audio, image;

body = document.body;
options = {};

//--- OPTIONS ---//
defaults = {
audioPath: ['assets/sounds/raptor.mp3', 'assets/sounds/raptor.ogg'],
imagePath: 'assets/images/raptor.png',

className: 'raptor',
animationTime: 2000
};

extend(options, defaults, extended);

//--- SETUP ---//
audioTemplate = document.createElement('audio');
audioTemplate.className = options.className + '-source';

for (var source in options.audioPath) {
sourceAudioTemplate = document.createElement('source');
sourceAudioTemplate.src = options.audioPath[source];
audioTemplate.appendChild(sourceAudioTemplate);
}

imageTemplate = document.createElement('img');
imageTemplate.className = options.className;
imageTemplate.src = options.imagePath;

audio = body.appendChild(audioTemplate);
image = body.appendChild(imageTemplate);

image.style.display = 'none';

//--- THE HILARITY ---//
function go() {
setTimeout(function () {
audio.play();
}, (options.animationTime / 3));

image.style.display = 'block';
image.classList.add(options.className + '-go');

setTimeout(function () {
image.classList.remove(options.className + '-go');
}, options.animationTime);
}

//--- EXTEND (COMMON) ---//
// Use Object.assign() for EcmaScript 6.
function extend(out) {
out = out || {};

for (var i = 1; i < arguments.length; i++) {
if (!arguments[i]) { continue; }
for (var key in arguments[i]) {
if (arguments[i].hasOwnProperty(key)) { out[key] = arguments[i][key]; }
}
}

return out;
}

return { go: go }
});



//--- USAGE ---//
var myRaptor = Raptorize({
audioPath: ['//zurb.com/playground/uploads/upload/upload/230/raptor-sound.mp3',
'//zurb.com/playground/uploads/upload/upload/231/raptor-sound.ogg'],
imagePath: '//zurb.com/playground/uploads/upload/upload/224/raptor.png',
});

setTimeout(myRaptor.go, 3000);

0 comments on commit af209ea

Please sign in to comment.