1 |
|
2 |
|
3 |
|
4 |
|
5 |
|
6 |
|
7 |
|
8 |
|
9 |
|
10 |
|
11 |
|
12 |
|
13 |
|
14 |
|
15 |
|
16 |
|
17 |
|
18 | let Yox = require("./lib/yox");
|
19 | let jQuery = require("jquery");
|
20 | let _ = require("lodash");
|
21 | let Store = require("./lib/store");
|
22 | let Router = require("./lib/yox-router");
|
23 |
|
24 | let dayjs = require("./lib/dayjs").dayjs;
|
25 | let pkg = require("../package.json");
|
26 |
|
27 |
|
28 | Yox.prototype.getSlot = function (name) {
|
29 | return this.get(`$slot_${name}`);
|
30 | };
|
31 |
|
32 | Yox.prototype.hasSlot = function (name) {
|
33 | return typeof this.getSlot(name) !== "undefined";
|
34 | };
|
35 |
|
36 | Yox.prototype.$store = function (name) {
|
37 | return typeof this.getSlot(name) !== "undefined";
|
38 | };
|
39 |
|
40 |
|
41 | Yox.prototype.$http = function (options) {
|
42 | return jQuery.ajax(options);
|
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 | let FireBird = (function () {
|
108 | function FireBird(options) {
|
109 | return new Yox(options);
|
110 | }
|
111 |
|
112 | return FireBird;
|
113 | })();
|
114 |
|
115 | FireBird.prototype = Yox.prototype;
|
116 |
|
117 | _.each(Yox, (func, name) => {
|
118 | FireBird[name] = func;
|
119 | });
|
120 |
|
121 |
|
122 | FireBird.log = (msg) => {
|
123 | console.log(`[FireBird info]: ${msg}`);
|
124 | };
|
125 | FireBird.warn = (msg) => {
|
126 | console.warn(`[FireBird warn]: ${msg}`);
|
127 | };
|
128 | FireBird.error = (msg) => {
|
129 | console.error(`[FireBird error]: ${msg}`);
|
130 | };
|
131 |
|
132 |
|
133 | FireBird.components = {};
|
134 |
|
135 | FireBird.classes = {};
|
136 |
|
137 | FireBird.namespace = function () {
|
138 | var a = arguments, o, i = 0, j, d, arg;
|
139 | for (; i < a.length; i++) {
|
140 | o = this;
|
141 | arg = a[i];
|
142 | if (arg.indexOf(".") > -1) {
|
143 | d = arg.split(".");
|
144 | for (j = (d[0] == 'FireBird') ? 1 : 0; j < d.length; j++) {
|
145 | o[d[j]] = o[d[j]] || {};
|
146 | o = o[d[j]];
|
147 | }
|
148 | } else {
|
149 | o[arg] = o[arg] || {};
|
150 | o = o[arg];
|
151 | }
|
152 | }
|
153 | return o;
|
154 | };
|
155 |
|
156 | FireBird.create = (name, options) => {
|
157 | return new FireBird($.extend(true, {}, FireBird.components[name], options));
|
158 | };
|
159 |
|
160 | FireBird.addMember = function (name, member) {
|
161 | Yox.prototype[name] = member;
|
162 | return this;
|
163 | };
|
164 |
|
165 |
|
166 | FireBird.component = (name, options) => {
|
167 | if (typeof name === "string") {
|
168 | if (typeof options === "function") {
|
169 |
|
170 | } else {
|
171 | options.$$name = name;
|
172 | if (options.extend) {
|
173 |
|
174 | if (typeof options.extend === "string") {
|
175 | options.extend = FireBird.components[options.extend] || null;
|
176 | }
|
177 |
|
178 | options = $.extend(true, {}, options.extend, options, {
|
179 | "$$parent": options.extend.$$name
|
180 | });
|
181 | }
|
182 | }
|
183 |
|
184 | Yox.component(name, options);
|
185 | FireBird.log(`组件 ${name} 已注册`);
|
186 | FireBird.components[name] = options;
|
187 |
|
188 | FireBird.namespace(name);
|
189 | return options;
|
190 | }
|
191 | if (typeof name === "object") {
|
192 | _.each(name, (options, comp) => {
|
193 | FireBird.component(comp, options);
|
194 | });
|
195 | }
|
196 | };
|
197 |
|
198 | FireBird.partials = {};
|
199 |
|
200 | FireBird.partial = (name, template) => {
|
201 | if (typeof name === "string") {
|
202 | Yox.partial(name, template);
|
203 | FireBird.log(`模版 ${name} 已注册`);
|
204 | FireBird.partials[name] = template;
|
205 | return template;
|
206 | }
|
207 | if (typeof name === "object") {
|
208 | _.each(name, (template, partial) => {
|
209 | FireBird.partial(partial, template);
|
210 | });
|
211 | }
|
212 | };
|
213 |
|
214 |
|
215 |
|
216 |
|
217 |
|
218 |
|
219 |
|
220 |
|
221 |
|
222 |
|
223 |
|
224 |
|
225 | FireBird.css = (cssObject = {}) => {
|
226 | let classes = [];
|
227 | _.each(cssObject, (value, cssName) => {
|
228 | if (value === true) {
|
229 | classes.push(cssName);
|
230 | }
|
231 | });
|
232 | return classes.join(" ");
|
233 | };
|
234 |
|
235 |
|
236 | FireBird.style = (styleObject = {}) => {
|
237 | let style = [];
|
238 |
|
239 | _.each(styleObject, (v, k) => {
|
240 | switch (k) {
|
241 | case "width":
|
242 | case "height":
|
243 | case "min-height":
|
244 | case "min-width":
|
245 | case "top":
|
246 | case "left":
|
247 | case "bottom":
|
248 | case "right":
|
249 | case "line-height":
|
250 | if (_.isNumber(v)) {
|
251 | style.push(`${k}: ${v}px`);
|
252 | } else {
|
253 | style.push(`${k}: ${v}`);
|
254 | }
|
255 | break;
|
256 | default:
|
257 | style.push(`${k}: ${v}`);
|
258 | }
|
259 |
|
260 | });
|
261 |
|
262 | return style.join("; ");
|
263 | };
|
264 |
|
265 | FireBird.oneOf = (value, defaults, array = []) => {
|
266 | if (!FireBird.array.has(array, value)) {
|
267 | return defaults;
|
268 | }
|
269 | return value;
|
270 | };
|
271 |
|
272 | FireBird.filter("css", FireBird.css);
|
273 |
|
274 | FireBird.filter("style", FireBird.style);
|
275 |
|
276 | FireBird.filter("oneOf", FireBird.oneOf);
|
277 |
|
278 | FireBird.compile = Yox.compile;
|
279 |
|
280 | FireBird.filter("_defaults", function (val, def) {
|
281 | return typeof val === "undefined" ? (typeof def === "undefined" ? "" : def) : val;
|
282 | });
|
283 |
|
284 | FireBird.filter("Function", function (val, def) {
|
285 | return (new Function(
|
286 | "//this data from FireBird Filter 'Function' Wrapper; \n return " + (typeof val === "undefined" ? (typeof def === "undefined" ? "" : def) : val)))();
|
287 | });
|
288 |
|
289 | FireBird.filter("JSON_parse", function (val, def) {
|
290 | return JSON.parse(typeof val === "undefined" ? (typeof def === "undefined" ? "" : def) : val);
|
291 | });
|
292 |
|
293 | FireBird.filter("JSON_stringify", function (val, def, replacer, space) {
|
294 | return JSON.stringify(typeof val === "undefined" ? (typeof def === "undefined" ? "" : def) : val, replacer, space);
|
295 | });
|
296 |
|
297 | FireBird.filter("dayjs_fromNow", function (withoutSuffix) {
|
298 | return dayjs.fromNow(withoutSuffix);
|
299 | });
|
300 | FireBird.filter("dayjs_from", function (val, withoutSuffix) {
|
301 | return dayjs.from(val, withoutSuffix);
|
302 | });
|
303 | FireBird.filter("dayjs_toNow", function (withoutSuffix) {
|
304 | return dayjs.toNow(withoutSuffix);
|
305 | });
|
306 | FireBird.filter("dayjs_to", function (val, withoutSuffix) {
|
307 | return dayjs.to(val, withoutSuffix);
|
308 | });
|
309 |
|
310 | FireBird.directive = Yox.directive;
|
311 |
|
312 |
|
313 | FireBird.filter(_);
|
314 |
|
315 | Store.install(FireBird);
|
316 | Router.install(FireBird);
|
317 |
|
318 | FireBird.component("PageApp", {
|
319 | template: "<div></div>",
|
320 | data() {
|
321 | return {};
|
322 | }
|
323 | });
|
324 |
|
325 | FireBird.App = function () {
|
326 | console.log("FireBird.App")
|
327 | };
|
328 |
|
329 | global.FireBird = FireBird;
|
330 |
|
331 | let version = pkg.version;
|
332 | console.log(" _______________________________________________________________________");
|
333 | console.log("| |");
|
334 | console.log("| ######## #### ######## ######## ######## #### ######## ######## |");
|
335 | console.log("| ## ## ## ## ## ## ## ## ## ## ## ## |");
|
336 | console.log("| ## ## ## ## ## ## ## ## ## ## ## ## |");
|
337 | console.log("| ###### ## ######## ###### ######## ## ######## ## ## |");
|
338 | console.log("| ## ## ## ## ## ## ## ## ## ## ## ## |");
|
339 | console.log("| ## ## ## ## ## ## ## ## ## ## ## ## |");
|
340 | console.log("| ## #### ## ## ######## ######## #### ## ## ######## |");
|
341 | console.log("| |");
|
342 | console.log(`|${_.pad("", 71)}|`);
|
343 | console.log(`|${_.pad("Version: " + version, 71)}|`);
|
344 | console.log(`|${_.pad("Date: {{build-date}}", 71)}|`);
|
345 | console.log(`|${_.pad("Author: lincong1987@gmail.com", 71)}|`);
|
346 |
|
347 | console.log("|_______________________________________________________________________|");
|
348 |
|
349 |
|
350 |
|
351 |
|
352 |
|
353 |
|
354 |
|
355 |
|
356 |
|
357 |
|
358 |
|
359 |
|
360 |
|
361 |
|
362 |
|
363 |
|
364 |
|
365 |
|
366 |
|
367 |
|
368 |
|
369 |
|
370 |
|
371 |
|
372 |
|
373 |
|
374 |
|
375 | let $ = jQuery, lodash = _;
|
376 |
|
377 | module.exports = {
|
378 | FireBird,
|
379 | Store: Store.Store,
|
380 | Router,
|
381 | jQuery,
|
382 | $,
|
383 | _,
|
384 | lodash,
|
385 | dayjs,
|
386 | version
|
387 | };
|