@@ -25,7 +25,12 @@ define([
25
25
'text!/templates/' + BBX . userLang + '/common/UserProfile.html' ,
26
26
'text!/templates/' + BBX . userLang + '/common/MucuaProfile.html'
27
27
] , function ( $ , _ , Backbone , jQueryCookie , HeaderView , HomeMucuaView , BuscadorView , MucuaModel , RepositoryModel , MediaFunctions , ContentTpl , SidebarTpl , UsageBarTpl , UserProfileTpl , MucuaProfileTpl ) {
28
-
28
+
29
+ /**
30
+ * init function of bbx functions
31
+ *
32
+ * @return {None }
33
+ */
29
34
var init = function ( ) {
30
35
__setConfig ( BBX . config ) ;
31
36
BBXFunctions = this ;
@@ -45,6 +50,22 @@ define([
45
50
}
46
51
}
47
52
53
+ /**
54
+ * check if cookies are enabled
55
+ *
56
+ * @return {Bool } if cookies are enabled
57
+ *
58
+ */
59
+ var isCookiesEnabled = function ( ) {
60
+ // TODO: improve cookie detection
61
+ if ( ! navigator . cookieEnabled ) {
62
+ console . log ( "Cookies not enabled, Baobaxia need cookies." ) ;
63
+ return false ;
64
+ } else {
65
+ return true ;
66
+ }
67
+ }
68
+
48
69
/**
49
70
* adds value to cookie
50
71
*
@@ -55,6 +76,10 @@ define([
55
76
var cookieData = { } ,
56
77
serializedCookie = '' ,
57
78
cookie = null ;
79
+
80
+ if ( ! isCookiesEnabled ) {
81
+ return false ;
82
+ }
58
83
59
84
console . log ( 'addToCookie()' ) ;
60
85
if ( $ . cookie ( 'sessionBBX' ) ) {
@@ -82,6 +107,11 @@ define([
82
107
*/
83
108
var getFromCookie = function ( key ) {
84
109
var key = key || '*' ;
110
+
111
+ if ( ! isCookiesEnabled ) {
112
+ return false ;
113
+ }
114
+
85
115
if ( $ . cookie ( 'sessionBBX' ) ) {
86
116
var cookieData = $ . parseJSON ( $ . cookie ( 'sessionBBX' ) ) ;
87
117
if ( key == '*' ) {
@@ -129,11 +159,12 @@ define([
129
159
}
130
160
131
161
/**
132
- * render common for internal pages at baobaxia
162
+ * render common elements for internal pages at baobaxia
133
163
*
164
+ * @el {String} HTML Element identifier
134
165
* @return [jQuery modify #header]
135
166
*/
136
- var renderCommon = function ( name ) {
167
+ var renderCommon = function ( el ) {
137
168
var data = { } ,
138
169
config = BBX . config ,
139
170
tags = [ ] ;
@@ -142,14 +173,14 @@ define([
142
173
data . isLogged = this . isLogged ;
143
174
data . isEditable = false ;
144
175
145
- $ ( 'body' ) . removeClass ( ) . addClass ( name ) ;
176
+ $ ( 'body' ) . removeClass ( ) . addClass ( el ) ;
146
177
if ( config . mucua == config . MYMUCUA ) {
147
178
$ ( 'body' ) . addClass ( 'my-mucua' ) ;
148
179
} else {
149
180
$ ( 'body' ) . addClass ( 'other-mucua' ) ;
150
181
}
151
- data . lastVisitedMucuas = __getLastVisitedMucuas ( config ) ;
152
- console . log ( 'render common: ' + name ) ;
182
+ data . lastVisitedMucuas = __getLastVisitedMucuas ( ) ;
183
+ console . log ( 'render common: ' + el ) ;
153
184
if ( $ ( '#sidebar' ) . html ( ) == "" ||
154
185
( typeof $ ( '#sidebar' ) . html ( ) === "undefined" ) ) {
155
186
$ ( '#footer' ) . before ( _ . template ( SidebarTpl , data ) ) ;
@@ -179,7 +210,7 @@ define([
179
210
/**
180
211
* render usage bar at footer
181
212
*
182
- * @return [jquery modify #footer]
213
+ * @return { None } [jquery modify #footer]
183
214
*/
184
215
var renderUsage = function ( ) {
185
216
console . log ( 'render usage' ) ;
@@ -228,7 +259,13 @@ define([
228
259
}
229
260
}
230
261
}
231
-
262
+
263
+ /**
264
+ * get mucua aditional data resources at API
265
+ *
266
+ * @uuid {String} Mucua UUID
267
+ * @return {None } [jQuery modification]
268
+ */
232
269
var __getMucuaResources = function ( uuid ) {
233
270
var config = __getConfig ( ) ,
234
271
url = config . apiUrl + '/mucua/' + uuid + '/info' ,
@@ -340,10 +377,11 @@ define([
340
377
}
341
378
} , 100 ) ;
342
379
}
343
-
344
380
345
381
/**
382
+ * render elements at sidebar
346
383
*
384
+ * @return {None } [jQuery modification]
347
385
*/
348
386
var renderSidebar = function ( ) {
349
387
var config = __getConfig ( ) ,
@@ -485,10 +523,15 @@ define([
485
523
}
486
524
}
487
525
488
- var __getLastVisitedMucuas = function ( config ) {
526
+ /**
527
+ * get last visited Mucua
528
+ *
529
+ * @return {Object } with list of last visited mucuas
530
+ */
531
+ var __getLastVisitedMucuas = function ( ) {
489
532
// get last visited mucuas
490
-
491
- var visitedMucuas = { 'name' : 'visitedMucuas' ,
533
+ var config = __getConfig ( ) ,
534
+ visitedMucuas = { 'name' : 'visitedMucuas' ,
492
535
'values' : [ ]
493
536
}
494
537
visitedMucuas . values = getFromCookie ( 'visitedMucuas' ) || [ ] ;
@@ -530,7 +573,7 @@ define([
530
573
}
531
574
532
575
addToCookie ( visitedMucuas ) ;
533
-
576
+ console . log ( visitedMucuas ) ;
534
577
return visitedMucuas . values ;
535
578
}
536
579
@@ -611,10 +654,25 @@ define([
611
654
} , 50 ) ;
612
655
}
613
656
657
+
658
+ /**
659
+ * Get config data
660
+ *
661
+ * @return {Object } input object with config data
662
+ */
614
663
var __getConfig = function ( ) {
615
664
return BBX . config ;
616
665
}
617
-
666
+
667
+
668
+ /**
669
+ * Set navigation variables
670
+ *
671
+ * @repository {String} Repository name
672
+ * @mucua {String} Mucua name
673
+ * @subroute {String} Internal url subroute
674
+ * @return {Object } input object with config data
675
+ */
618
676
var setNavigationVars = function ( repository , mucua , subroute ) {
619
677
var subroute = subroute || '' ,
620
678
reMedia = / ^ [ 0 - 9 a - z ] { 8 } - [ 0 - 9 a - z ] { 4 } - [ 0 - 9 a - z ] { 4 } - [ 0 - 9 a - z ] { 4 } - [ 0 - 9 a - z ] { 12 } / , // padrao de uuid
@@ -676,9 +734,11 @@ define([
676
734
}
677
735
}
678
736
737
+ // public functions are defined above
679
738
return {
680
739
init : init ,
681
740
isLogged : isLogged ,
741
+ isCookiesEnabled : isCookiesEnabled ,
682
742
getFromCookie : getFromCookie ,
683
743
addToCookie : addToCookie ,
684
744
getDefaultHome : getDefaultHome ,
0 commit comments