Skip to content

Instantly share code, notes, and snippets.

View patrixd's full-sized avatar

Patricia Juárez Muñoz patrixd

View GitHub Profile
@patrixd
patrixd / AppConfig.as
Last active December 17, 2015 09:19
Basic example using Robotlegs2 and Starling. Note: to use Inject in Robotlegs, the class that use them must exist in the context. It was weird to me because I came of Parsley. In Parsley you only declare what to inject you do not declare who inject them too. This example also has an splash in pure actionscript.
package {
// imports ...
public class AppConfig implements IConfig
{
[Inject]
public var context:IContext;
[Inject]
public var commandMap:ISignalCommandMap;
@patrixd
patrixd / jquery.event.touch.doubleTab.js
Last active March 27, 2016 22:04
If you don't use jquery mobile because you think that you don't need all the features, I usually add plugins like the next one. In this case is doubleclick for touchable devices
// Example: this.$stage.doubleTab.on(this.$stage, this.onContainerClicked, 200, "touchstart", this.options.delegatedTagSel);
// this.$stage.doubleTab.off(this.$stage, "touchstart");
$.fn.doubleTab = (function() {
var timer, data, eventType = "touchend";
var timeout = 600;
var $itemClicked = null;
var onDoubleClickSTART = function(e) {
data = e.data;
data.$container.off(data.eventType, onDoubleClickSTART);
@patrixd
patrixd / bindAll.js
Last active December 31, 2015 18:22
BindAll from underscore that allows 1 argument to bind all the functions from the prototype, or if there are more arguments they will be the only binded
//bindAll from underscore that allows 1 argument to bind all the functions from the prototype,
//or if there are more arguments they will be the only binded
_.originalBindAll = _.bindAll;
_.bindAll = function (that) {
var funcs = Array.prototype.slice.call(arguments, 1),
validKeys = [], fn;
if (funcs.length == 0) {
for (var i in that) {
fn = that[i];
if (fn && typeof fn == "function" && (!fn.prototype || _.keys(fn.prototype).length == 0))
@patrixd
patrixd / extendViewOptions.js
Last active December 31, 2015 19:59
Before of the last }).call(this); from Backbone.js or Backbone.js.min add the next to allow to work with options like in the previous versions before it was removed since version 1.1Previously the options argument were attached as this.options automatically.
var BackboneView = Backbone.View;
Backbone.View = BackboneView.extend({
constructor: function (options) {
this._configure(options || {});
BackboneView.prototype.constructor.apply(this, arguments);
},
_configure: function (options) {
if (this.options) options = _.extend({}, _.result(this, 'options'), options);
//_.extend(this, _.pick(options, viewOptions));
this.options = options;
@patrixd
patrixd / gchart.js
Last active January 1, 2016 12:49
An example of a Google Chart in an app using RequireJS and BackboneJS
var listData = ["LABEL C", "LABEL D", "LABEL E"];
listData = listData.concat(
_.map(this.model.toJSON(), function (item) {
return [item.PropertyName, parseFloat(item.PropertyC), parseFloat(item.PropertyD), parseFloat(item.PropertyE)];
}, this)
);
data = google.visualization.arrayToDataTable(listData);
// Create and draw the visualization.
@patrixd
patrixd / example.html
Created October 28, 2014 07:51
Custom native select with CSS3, cross-browser support
<div class="selectContainerWithBtn">
<select>
<option value="1">Option 1</option>
<option value="2">Option 2</option>
<option value="3">Option 3</option>
<option value="4">Option 4</option>
</select>
</div>
@patrixd
patrixd / loadScript.js
Last active August 29, 2015 14:10
Basic loader - Loads a script only once
loadedScript = {};
loadingScript = {};
pendingScriptSuccess = {};
function loadScript (url, success, async) {
if(loadedScript[url]) {
success();
return;
}
@patrixd
patrixd / jquery.mousewheel.example.coffee
Last active August 29, 2015 14:10
MouseWheel Event Crossbrowser
# The better is to use the next: https://github.com/jquery/jquery-mousewheel
$('body').on('mousewheel', onMouseWheel);
onMouseWheel = (e) ->
scrollDistance = e.deltaY * e.deltaFactor
wHeight = $(window).innerHeight()
newScrollTop = scrollDistance * -1 + $('body').scrollTop()
#Example of use, automatic scrolldown when the next slide is in the middle it scrolls down automatically
clearTimeout(window._scrollTimer)
@patrixd
patrixd / misins.css.styl
Created November 23, 2014 15:44
My Mixins for Stylus. Link style, background linear gradient, vendor, center styles, disable selection and more
@import 'nib'
background-before-layer(opacity, startPoint, startColor, startInterval, endColor, endInterval)
content " "
background-linear-gradient(startPoint, startColor, startInterval, endColor, endInterval)
position absolute
width 100%
height 100%
if opacity
@patrixd
patrixd / pointerEvents.js
Last active March 27, 2016 22:00
Touch and Mouse events. For compatibility with any kind of device. Touch, Click and both. https://hacks.mozilla.org/2013/04/detecting-touch-its-the-why-not-the-how/ http://www.html5rocks.com/en/mobile/touchandmouse/
$.fn.pointerEvent = (function () {
var $el = $(this),
_eventData = "",
_touchEventName,
_bindEvent = function (nameListener, mouseEvent, data, callback) {
if ($el.length === 0)
return;
_touchEventName = _getTouchEventName(mouseEvent);
if (_.isFunction(data)) {
callback = data;