-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.html
More file actions
115 lines (97 loc) · 3.94 KB
/
index.html
File metadata and controls
115 lines (97 loc) · 3.94 KB
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
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>jQuery-Plugin-Template-for-qUnit-testing</title>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js" type="text/javascript"></script>
<link href="http://code.jquery.com/qunit/qunit-1.11.0.css" rel="stylesheet" type="text/css" />
<script src="http://code.jquery.com/qunit/qunit-1.11.0.js" type="text/javascript"></script>
<script>
(function ($) {
// methods
var log = null,
methods = {
firstMethod: function () {
return "rightString";
},
toLowerCase: function (str) {
return str && str.toLowerCase ? str.toLowerCase() : str;
}
};
// debug log
log = function (msg) {
if (!$.m7plugin.debug) return;
if (!console) return;
if (!console.log) return;
// console.log("LOG(), Arguments", arguments, msg)
if (arguments.length > 1) {
console.log(arguments);
} else {
console.log(msg);
}
};
function init(debug) {
// init plugin
$.m7plugin = {
debug: debug,
id: "pluginDemo",
version: "0.0.1",
copyright: "Copyright (c) 2005-2013 Simon Tregunna",
uri: "http://method7.co.uk/",
licensed: {
MIT: "http://www.opensource.org/licenses/mit-license.php",
GPL: "http://www.gnu.org/licenses/gpl.html"
}
};
// ? debug
if ($.m7plugin.debug) {
window.qUnitMethods = methods;
}
};
// plugin
$.fn.extend({
m7plugin: function (options) {
var $this = $(this);
return this.each(function () {
var element = $(this),
defaults = {
someVair: "somevalue"
},
settings = $.extend(defaults, options);
// setup plugin
init(settings.debug);
// plugin code here
log("m7plugin - private method: ", methods.toLowerCase("TOLOERCASE"));
// store a reference in the extended plugin
var toLower = methods.toLowerCase;
log("m7plugin - extended: ", toLower("TOLOERCASELOCAL"));
});
}
});
})(jQuery);
$(window).load(function () {
//console.log("public methods - toLowerCase: ", window.qUnitMethods.toLowerCase("TOLOERCASE"));
$("body").m7plugin({
debug: true
});
/*********************************************/
/***************** qUnit tests ***************/
/*********************************************/
module("M7-PLUGIN TEMPLATE");
test("expose methods test", function () {
//QUnit.stop();
expect(3);
//day and month replacment
ok(typeof qUnitMethods !== "undefined", "make function firstMethod() public");
deepEqual(qUnitMethods.firstMethod(), "rightString", "firstMethod() return expected string");
deepEqual(qUnitMethods.toLowerCase("TOLOERCASE"), "toloercase", "toLowerCase() return expected string");
//QUnit.start();
});
});
</script>
</head>
<body>
<div id="qunit"></div>
<div id="qunit-fixture"></div>
</body>
</html>