- accordion(1)
- active-trail(1)
- ajax(1)
- angular(1)
- apache(3)
- bash(4)
- block(2)
- browsers(1)
- button styles(1)
- checkboxes(1)
- code key(1)
- compress(1)
- console(4)
- css(1)
- ctools(1)
- date(1)
- db_query(2)
- db_select(2)
- debian(1)
- dom function(1)
- drag and drop(1)
- drupal 6(3)
- drupal 7(3)
- drupal functions(6)
- drupal_goto()(1)
- drupal_mail(1)
- errors(1)
- eslint(1)
- fancybox(1)
- fedora(1)
- firefox(2)
- firefox addons(1)
- firefox profiles(1)
- form(1)
- form api(5)
- format_date(1)
- git(1)
- hooks(2)
- hook_mail(1)
- hook_theme(1)
- hotkey(1)
- httpd(1)
- husky(1)
- ie(2)
- javascript(2)
- jquery(7)
- jquery plugin(2)
- jquery regex(1)
- js templates(1)
- kb(1)
- like button(1)
- link(1)
- linux(4)
- linux commands(2)
- list(1)
- list styles(1)
- markup(1)
- menu(3)
- mobile(1)
- modal(2)
- module develop(2)
- modules(1)
- monorepo(1)
- mootools(1)
- mysql(2)
- node_save(1)
- opacity(1)
- opensuse(5)
- opera mini(1)
- padStart(1)
- page.tpl.php(1)
- password hash(1)
- patch(1)
- pdf(1)
- python(1)
- radiobuttons(1)
- reg_ex(2)
- sass(1)
- scripts(1)
- search form(1)
- selenium(1)
- share button(1)
- sms(1)
- ssh(2)
- styles(4)
- switch case(1)
- table style(1)
- tar(1)
- taxonomy(1)
- taxonomy menu(1)
- templates(1)
- theme(4)
- toggle(2)
- touchpad(1)
- tray(1)
- trigger(1)
- typescript(2)
- typescript-eslint(1)
- ubuntu(3)
- usefull function(1)
- views(1)
- virtual hosts(2)
- virtualbox(2)
- vmware(1)
- webdriver(1)
- youtube(1)
- кроссбраузерность(1)
Javascript Шаблоны
Циклы:
For
var i, myArray =[];
for(i = myArray.length; i--;) {
myArray[i];
}
for(i = myArray.length; i--;) {
myArray[i];
}
While
var myArray,
i = myArray.length;
while(i--) {
myArray[i];
}
i = myArray.length;
while(i--) {
myArray[i];
}
Комментарии:
Application:
/**
* My JS application
*
* @module
*/
MyApp = {};
* My JS application
*
* @module
*/
MyApp = {};
Class:
/**
* A math utility
* @namespace MyApp
* @class my_stuff
*/
MyApp.math_stuff = {};
* A math utility
* @namespace MyApp
* @class my_stuff
*/
MyApp.math_stuff = {};
Method:
/**
* Sums two numbers
*
* @method sum
* @param {Number} a First number
* @param {Number} b The second number
* @return {Number} The sum of the two inputs
*/
sum : function (a, b) {
return a + b;
}
* Sums two numbers
*
* @method sum
* @param {Number} a First number
* @param {Number} b The second number
* @return {Number} The sum of the two inputs
*/
sum : function (a, b) {
return a + b;
}
Конструктор
/**
* Constructs Person object
* @class Person
* @constructor
* @namespace MyApp
* @param {String} first First name
* @param {String} last Last name
*/
MyApp.Person = function (first, last) {
/**
* Name of the person
* @property last_name
* @type String
*/
this.first_name = first;
/**
* Last (family) name of person
* @property last_name
* @type String
*/
this.last_name = last;
}
}
* Constructs Person object
* @class Person
* @constructor
* @namespace MyApp
* @param {String} first First name
* @param {String} last Last name
*/
MyApp.Person = function (first, last) {
/**
* Name of the person
* @property last_name
* @type String
*/
this.first_name = first;
/**
* Last (family) name of person
* @property last_name
* @type String
*/
this.last_name = last;
}
}
Обратный вызов
// измененный вариант функции findNodesO,
// принимающий функцию обратного вызова
var findNodes = function (callback) {
var i = 100000,
nodes = [],
found;
// проверить, является ли объект callback функцией
if (typeof callback !== "function") {
callback = false;
}
while (i) {
i -= 1;
// здесь находится сложная логика выбора узлов...
// теперь вызвать функцию callback:
if (callback) {
callback(found);
}
nodes.push(found);
}
return nodes;
};
// принимающий функцию обратного вызова
var findNodes = function (callback) {
var i = 100000,
nodes = [],
found;
// проверить, является ли объект callback функцией
if (typeof callback !== "function") {
callback = false;
}
while (i) {
i -= 1;
// здесь находится сложная логика выбора узлов...
// теперь вызвать функцию callback:
if (callback) {
callback(found);
}
nodes.push(found);
}
return nodes;
};
Модуль
MYAPP = {};
MYAPP.utilits = {};
MYAPP.utilits.array = (function(){
//
var app = 5,
app2 = 6;
return {
inArray : function (a, b) {
return app + '1';
},
isArray : function (a, b) {
return app2 +'2';
}
}
}());
MYAPP.utilits.array2 = (function(){
//
var app = 5,
app2 = 6;
inArray = function (a, b) {
return app + '1';
},
isArray = function (a, b) {
return app2 +'2';
};
return {
isArray : isArray,
inArray : inArray
};
}())
MYAPP.utilits = {};
MYAPP.utilits.array = (function(){
//
var app = 5,
app2 = 6;
return {
inArray : function (a, b) {
return app + '1';
},
isArray : function (a, b) {
return app2 +'2';
}
}
}());
MYAPP.utilits.array2 = (function(){
//
var app = 5,
app2 = 6;
inArray = function (a, b) {
return app + '1';
},
isArray = function (a, b) {
return app2 +'2';
};
return {
isArray : isArray,
inArray : inArray
};
}())
Константы
var constant = (function(){
var constants = {},
ownProp = Object.prototype.hasOwnProperty,
allowed = {
string : 1,
number : 1,
boolean : 1
},
prefix = (Math.random() + "_").slice(2);
return {
set : function (name, value) {
if(this.isDefined(name)) {
return false;
}
if(!ownProp.call(allowed, typeof value)) {
return false;
}
constants[prefix + name] = value;
return true;
},
isDefine : function (name) {
return ownProp.call(constants, prefix + name);
},
get : function (name) {
if(this.isDefine (name)) {
return constants[prefix + name];
}
return null;
}
}
})
var constants = {},
ownProp = Object.prototype.hasOwnProperty,
allowed = {
string : 1,
number : 1,
boolean : 1
},
prefix = (Math.random() + "_").slice(2);
return {
set : function (name, value) {
if(this.isDefined(name)) {
return false;
}
if(!ownProp.call(allowed, typeof value)) {
return false;
}
constants[prefix + name] = value;
return true;
},
isDefine : function (name) {
return ownProp.call(constants, prefix + name);
},
get : function (name) {
if(this.isDefine (name)) {
return constants[prefix + name];
}
return null;
}
}
})