-
Notifications
You must be signed in to change notification settings - Fork 22
/
externals.yate.js
117 lines (95 loc) · 2.82 KB
/
externals.yate.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
;(function(yr) {
/* Делает extend двух и более объектов объектов
*
* @param {Boolean} deep extend или нет
* @param {Object} Родительский объект
* @param {Object} объект который расширяет
*
* @return {Object} Новый объект
* */
function extend(deep) {
var exts = Array.prototype.slice.call(arguments, 1);
var newObj = {}
for (var i = 0, c = exts.length; i < c; i++) {
var ext = exts[i];
extendHelper(deep, newObj, ext)
}
return newObj;
}
function extendHelper(deep, destination, source) {
for (var prop in source) {
var sp = source[prop]
var dp = destination[prop]
if (deep && destination == sp) {
continue;
}
if (deep && typeof sp == 'object' && dp) {
extendHelper(deep, dp, sp);
} else if (sp != undefined) {
destination[prop] = source[prop];
}
}
return destination;
}
// http://underscorejs.org/#pluck
function pluck(list, popertyName) {
var result = [];
for (var i = 0, c = list.length; i < c; i++) {
var item = list[i];
var value = item && item[popertyName];
if (value) {
result.push(value)
}
}
return result;
}
yr.externals['_nb-extend'] = function(parent, node) {
if (node && node[0]) {
if (typeof node == 'string') {
parent[0].data.content = node;
} else {
var dataParent = parent[0].data;
var dataNode = node[0].data;
var dataNew = extend(false, dataParent, dataNode);
parent[0].data = dataNew;
}
}
return parent;
}
yr.externals['_nb-deep-extend'] = function(parent, node) {
if (node && node[0]) {
if (typeof node == 'string') {
parent[0].data.content = node;
} else {
var dataParent = parent[0].data;
var dataNode = node[0].data;
var dataNew = extend(true, dataParent, dataNode);
parent[0].data = dataNew;
}
}
return parent;
}
yr.externals['_nb-wrap'] = function(name, options) {
var data = {};
if (options && options.length) {
data[name] = options.length == 1
? options[0].data
: pluck(options, 'data')
}
return [{
data: data,
name: '',
parent: null,
doc: options[0].doc
}];
}
yr.externals['_nb-uniq'] = (function(){
var uniq = 0;
return function() {
return uniq++;
}
})()
yr.externals['_nb-warn'] = function(message){
console.log('%c' + message, 'color:#ffcc00');
};
})(typeof yr === 'undefined' && typeof require === 'function' ? require('yate/lib/runtime.js') : yr);