Skip to content

Commit 42c562d

Browse files
committed
Implemented most of the tools use core.js. This branch is now in unfunctional state.
1 parent 04ad044 commit 42c562d

File tree

20 files changed

+179
-692
lines changed

20 files changed

+179
-692
lines changed

src/accordion/accordion.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
vertical: false
1515
};
1616

17-
function Accordion(root, conf) {
17+
function Tool(root, conf) {
1818

1919
var panes = root.children(conf.panes),
2020
currentIndex = conf.initialIndex,
@@ -109,7 +109,7 @@
109109
}
110110

111111
$.fn.accordion = function(conf) {
112-
return $.tools.create(this, Accordion, CONF, conf);
112+
return $.tools.create(this, "accordion", Tool, CONF, conf);
113113
};
114114

115115
})(jQuery);

src/core.js

Lines changed: 50 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -3,35 +3,69 @@
33
$.tools = {
44
version: '@VERSION',
55

6-
create: function(root, fn, globals, conf) {
6+
create: function(elem, name, fn, globals, conf, events, isInput) {
77

8-
var args = arguments,
9-
name = fn.name.toLowerCase(),
10-
api = root.data(name);
8+
var api = elem.data(name);
119

1210
if (api) {
1311
api.destroy();
1412

1513
} else {
16-
17-
if (!globals.conf) { globals = { conf: globals }; }
18-
19-
$.tools[name] = globals;
20-
14+
// configuration
15+
if (!globals.conf) { globals = { conf: globals }; }
16+
$.tools[name] = globals;
2117
conf = $.extend(true, {}, globals.conf, conf);
18+
19+
// :overlay, :date
20+
$.expr[':'][name] = $.expr[':'][name] || function(el) {
21+
return !!$(el).data(name);
22+
};
23+
}
24+
25+
var ret;
26+
27+
elem.each(function() {
28+
29+
api = new fn($(this), conf);
2230

23-
$.extend(fn.prototype, {
31+
$.extend(api, {
2432
getConf: function() {
2533
return conf;
2634
}
27-
});
28-
}
35+
});
36+
37+
// events
38+
$.each(events.split(","), function(i, name) {
39+
40+
if (name != 'change') { name = "on" + name; }
41+
42+
// configuration
43+
if ($.isFunction(conf[name])) {
44+
$(api).bind(name, conf[name]);
45+
}
46+
47+
// API
48+
api[name] = function(fn) {
49+
if (fn) { $(api).bind(name, fn); }
50+
return api;
51+
};
52+
});
53+
54+
$(this).data(name, api).data("api", api);
55+
56+
if (isInput) {
57+
var input = api.getInput().data(name, api).data("api", api);
58+
ret = ret ? ret.add(input) : input;
59+
}
60+
});
2961

30-
return root.each(function() {
31-
api = new fn($(this), conf);
32-
$(this).data(name, api);
33-
});
62+
return ret ? ret : elem;
3463
}
3564
};
65+
66+
// jQuery.tool(":overlay").load();
67+
$.tool = function(query) {
68+
return $(query).data("api");
69+
};
3670

3771
})(jQuery);

src/dateinput/dateinput.js

Lines changed: 17 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -10,22 +10,14 @@
1010
* Date: @DATE
1111
*/
1212
(function($) {
13-
14-
/* TODO:
15-
preserve today highlighted
16-
*/
17-
18-
$.tools = $.tools || {version: '@VERSION'};
1913

20-
var instances = [],
21-
tool,
22-
23-
// h=72, j=74, k=75, l=76, down=40, left=37, up=38, right=39
24-
KEYS = [75, 76, 38, 39, 74, 72, 40, 37],
25-
LABELS = {};
26-
27-
tool = $.tools.dateinput = {
28-
14+
$.expr[':'].date = function(el) {
15+
var type = el.getAttribute("type");
16+
return type && type == 'date' || !!$(el).data("dateinput");
17+
};
18+
19+
// h=72, j=74, k=75, l=76, down=40, left=37, up=38, right=39
20+
var KEYS = [75, 76, 38, 39, 74, 72, 40, 37], LABELS = {}, instances = [], GLOBAL = {
2921
conf: {
3022
format: 'mm/dd/yy',
3123
selectors: false,
@@ -73,11 +65,10 @@
7365
labels[key] = val.split(",");
7466
});
7567
LABELS[language] = labels;
76-
}
77-
68+
}
7869
};
7970

80-
tool.localize("en", {
71+
GLOBAL.localize("en", {
8172
months: 'January,February,March,April,May,June,July,August,September,October,November,December',
8273
shortMonths: 'Jan,Feb,Mar,Apr,May,Jun,Jul,Aug,Sep,Oct,Nov,Dec',
8374
days: 'Sunday,Monday,Tuesday,Wednesday,Thursday,Friday,Saturday',
@@ -170,7 +161,7 @@
170161
//}}}
171162

172163

173-
function Dateinput(input, conf) {
164+
function Tool(input, conf) {
174165

175166
// variables
176167
var self = this,
@@ -647,10 +638,6 @@
647638
return self;
648639
},
649640

650-
getConf: function() {
651-
return conf;
652-
},
653-
654641
getInput: function() {
655642
return input;
656643
},
@@ -669,22 +656,6 @@
669656

670657
});
671658

672-
// callbacks
673-
$.each(['onBeforeShow','onShow','change','onHide'], function(i, name) {
674-
675-
// configuration
676-
if ($.isFunction(conf[name])) {
677-
$(self).bind(name, conf[name]);
678-
}
679-
680-
// API methods
681-
self[name] = function(fn) {
682-
if (fn) { $(self).bind(name, fn); }
683-
return self;
684-
};
685-
});
686-
687-
688659
// show dateinput & assign keyboard shortcuts
689660
input.bind("focus click", self.show).keydown(function(e) {
690661

@@ -706,39 +677,24 @@
706677
select(value, conf);
707678
}
708679

680+
instances.push(self);
681+
709682
}
710683

711-
$.expr[':'].date = function(el) {
712-
var type = el.getAttribute("type");
713-
return type && type == 'date' || !!$(el).data("dateinput");
714-
};
715684

716-
717-
$.fn.dateinput = function(conf) {
718-
719-
// already instantiated
720-
if (this.data("dateinput")) { return this; }
721-
722-
// configuration
723-
conf = $.extend(true, {}, tool.conf, conf);
685+
$.fn.dateinput = function(conf) {
724686

687+
conf = $.extend(true, {}, GLOBAL.conf, conf);
688+
725689
// CSS prefix
726690
$.each(conf.css, function(key, val) {
727691
if (!val && key != 'prefix') {
728692
conf.css[key] = (conf.css.prefix || '') + (val || key);
729693
}
730694
});
731-
732-
var els;
733695

734-
this.each(function() {
735-
var el = new Dateinput($(this), conf);
736-
instances.push(el);
737-
var input = el.getInput().data("dateinput", el);
738-
els = els ? els.add(input) : input;
739-
});
740-
741-
return els ? els : this;
696+
return $.tools.create(this, "dateinput", Tool, GLOBAL, conf, "BeforeShow,Show,change,onHide", true);
697+
742698
};
743699

744700

0 commit comments

Comments
 (0)