forked from chuanxshi/javascript-patterns
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathnamespaced-starter.html
More file actions
75 lines (59 loc) · 1.83 KB
/
namespaced-starter.html
File metadata and controls
75 lines (59 loc) · 1.83 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
<!doctype html>
<html lang="en">
<head>
<title>JavaScript Patterns</title>
<meta charset="utf-8">
</head>
<body>
<script>
/*!
* jQuery namespaced 'Starter' plugin boilerplate
* Author: @dougneiner
* Further changes: @addyosmani
* Licensed under the MIT license
*/
;(function ( $ ) {
if ( ! $.myNamespace ) {
$.myNamespace = {};
}
$.myNamespace.myPluginName = function ( el, myFunctionParam, options ) {
// To avoid scope issues, use 'base' instead of 'this'
// to reference this class from internal events and functions.
var base = this;
// Access to jQuery and DOM versions of element
base.$el = $( el );
base.el = el;
// Add a reverse reference to the DOM object
base.$el.data( "myNamespace.myPluginName" , base );
base.init = function () {
base.myFunctionParam = myFunctionParam;
base.settings = $.extend( {}, $.myNamespace.myPluginName.defaults, options );
// Put your initialization code here
};
// Sample Function, Uncomment to use
// base.functionName = function( paramaters ){
//
// };
// Run initializer
base.init();
};
$.myNamespace.myPluginName.defaults = {
myDefaultValue: ""
};
$.fn.mynamespace_myPluginName = function( myFunctionParam, options ) {
return this.each( function () {
( new $.myNamespace.myPluginName( this, myFunctionParam, options ) );
});
};
} )( jQuery );
// References
/*
Namespacing in JavaScript (by Angus Croll) - http://goo.gl/eul12
Use Your $.fn jQuery Namespace (by Ryan Florence) - http://goo.gl/QQIC6
JavaScript Namespacing (by Peter Michaux) - http://goo.gl/24t8N
Modules and namespaces in JavaScript (by Axel Rauschmayer) - http://goo.gl/6XuqO
Essential jQuery Plugin Patterns (by Addy Osmani) - http://goo.gl/oE0ge
*/
</script>
</body>
</html>