1- // Module/Plugin core
1+ // Module/Plugin core
22// Note: the wrapper code you see around the module is what enables
33// us to support multiple module formats and specifications by
44// mapping the arguments defined to what a specific format expects
77//
88// Note that dependencies can just as easily be declared if required
99// and should work as demonstrated earlier with the AMD module examples.
10-
11- ( function ( name , definition ) {
12- var theModule = definition ( ) ,
13- // this is considered "safe":
14- hasDefine = typeof define === 'function' && define . amd ,
15- // hasDefine = typeof define === 'function',
16- hasExports = typeof module !== 'undefined' && module . exports ;
17-
18- if ( hasDefine ) { // AMD Module
19- define ( theModule ) ;
20- } else if ( hasExports ) { // Node.js Module
21- module . exports = theModule ;
22- } else { // Assign to common namespaces or simply the global object (window)
23- ( this . jQuery || this . ender || this . $ || this ) [ name ] = theModule ;
24- }
25- } ) ( 'core' , function ( ) {
26- var module = this ;
27- module . plugins = [ ] ;
28- module . highlightColor = "yellow" ;
29- module . errorColor = "red" ;
30-
31- // define the core module here and return the public API
32-
33- // This is the highlight method used by the core highlightAll()
34- // method and all of the plugins highlighting elements different
35- // colors
36- module . highlight = function ( el , strColor ) {
37- if ( this . jQuery ) {
38- jQuery ( el ) . css ( 'background' , strColor ) ;
10+ ( function ( name , definition ) {
11+ var theModule = definition ( ) , // this is considered "safe":
12+ hasDefine = typeof define === 'function' && define . amd , // hasDefine = typeof define === 'function',
13+ hasExports = typeof module !== 'undefined' && module . exports ;
14+ if ( hasDefine ) { // AMD Module
15+ define ( theModule ) ;
16+ } else if ( hasExports ) { // Node.js Module
17+ module . exports = theModule ;
18+ } else { // Assign to common namespaces or simply the global object (window)
19+ ( this . jQuery || this . ender || this . $ || this ) [ name ] = theModule ;
20+ console . log ( ( window . jQuery ) [ name ] ) ;
3921 }
40- }
41- return {
42- highlightAll :function ( ) {
43- module . highlight ( 'div' , module . highlightColor ) ;
44- }
45- } ;
46-
47- } ) ;
22+ } ) ( 'app' , function ( ) {
23+
24+ var core = this ;
25+
26+ var defaults = { // default settings
27+ name : '123'
28+ } ;
29+
30+ var opts = { } ; // extend options
31+
32+ var $document = $ ( document ) ,
33+ $window = $ ( window ) ,
34+ $html = $ ( 'html' ) ;
35+
36+ core . plugins = [ ] ;
37+
38+ var base = {
39+ eventnames : {
40+ scroll : 'myScroll' ,
41+ resize : 'myResize'
42+ } ,
43+ scrollTop : 0 ,
44+ highlightColor : 'yellow' ,
45+ errorColor : 'red'
46+ } ;
47+
48+ core . base = base ; // set public base
49+
50+ // private
51+ var setHandler = function ( ) {
52+ var _onScroll = function ( ) {
53+ base . scrollTop = $document . scrollTop ( ) ;
54+ $document . trigger ( base . eventnames . scroll ) ;
55+ } ;
56+ $document . on ( 'scroll resize' , _onScroll ) ;
57+ } ;
58+
59+ // define the core base here and return the public API
60+ core . init = function ( options ) {
61+ opts = $ . extend ( { } , defaults , options ) ;
62+ console . log ( opts ) ;
63+ setHandler ( ) ;
64+ } ;
65+
66+ // This is the highlight method used by the core highlightAll()
67+ // method and all of the plugins highlighting elements different
68+ // colors
69+ core . highlight = function ( el , strColor ) {
70+ $ ( el ) . css ( 'background' , strColor ) ;
71+ } ;
72+
73+ return {
74+ init : function ( options ) {
75+ core . init ( options ) ;
76+ } ,
77+ highlight : function ( ) {
78+ core . highlight ( el , strColor ) ;
79+ }
80+ } ;
81+
82+ } ) ;
0 commit comments