Skip to content

Instantly share code, notes, and snippets.

@jansanchez
Last active August 29, 2015 13:56
Show Gist options
  • Save jansanchez/8867881 to your computer and use it in GitHub Desktop.
Save jansanchez/8867881 to your computer and use it in GitHub Desktop.
modulo.js yOSON
/**
Descripción del modulo yOSON
@class nombre_del_modulo
@main nombre_archivo_js_actual
@author Nombre del Autor
*/
yOSON.AppCore.addModule('nombre_del_modulo', function (Sb) {
/**
Main settings of the module(these can be overridden)
@property st
@type Object
@default "{}"
*/
var st = {
container: '#frmSearch',
txtKeyword: '#txtKeyword',
btnSearch: '#btnSearch',
limit: 1,
HTMLtpl: null,
flag: true,
tpl: '#tplTags'
},
/**
Object to store the dom of this module
@property dom
@type Object
@default "{}"
*/
dom = {},
/**
Function to store the DOM to start the module (only runs once)
@method catchDom
@return {null}
*/
catchDom = function () {
dom.container = $(st.container);
dom.txtKeyword = $(st.txtKeyword, dom.container);
dom.btnSearch = $(st.btnSearch, dom.container);
},
/**
Función para suscribir los eventos del modulo (solo se ejecuta una vez)
@method suscribeEvents
@return {null}
*/
suscribeEvents = function () {
dom.txtKeyword.on('keypress', events.search);
dom.btnSearch.on('click', events.search);
},
/**
Object to store the events functions of this module
@property events
@type Object
@default "{}"
*/
events = {
/**
Función para realizar la busqueda
@method search
@return {null}
*/
search : function (e) {
var collection = [];
if (e.which === 13 || e.which === 1) {
e.preventDefault();
if (dom.txtKeyword.val() !== '') {
collection = $.parseJSON(Cookie.read('search'));
if (collection !== null) {
Cookie.create('search', JSON.stringify(collection));
}
}
}
}
},
/**
Object to store the common functions of this module
@property functions
@type Object
@default "{}"
*/
functions = {
},
/**
Initialize the module
@event initialize
@param {Object} oP Le pasamos un objeto con los valores que reemplazaremos por st
@return {null}
*/
initialize = function (oP) {
$.extend(st, oP);
catchDom();
suscribeEvents();
};
/*Fin de la parte privada*/
/*Inicio de la parte publica, que es lo que retornamos, en este caso retornamos un objeto*/
/**
Init the module
@event init
@return {null}
*/
return {
init: initialize
};
}, ['ruta_del_archivo_de_dependencia.js']);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment