forked from dtbaker/dashboard-plus
-
Notifications
You must be signed in to change notification settings - Fork 1
/
bootstrap.js
476 lines (353 loc) · 14.6 KB
/
bootstrap.js
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
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
/*
* Copyright (c) 2014
* ==================================
* powered by revaxarts.com (http://revaxarts.com)
* original filename: bootstrap.js
* filesize: 12643 Bytes
* last modified: Thu, 12 Jun 2014 09:12:30 +0200
*
*/
(function () {
//"use strict"
var version = '1.5',
cookiePrefix = 'dbp_';
if( typeof jQuery != 'undefined' ){
go();
return;
}
yepnope({
load: [
"http://0.envato-static.com/assets/application/vendor-2b538c3f97134712a085fc58f4c396f5.js"
],
complete: go
});
function go(){
var username = $('.global-header-menu__link-text').html();
var loadit = [];
var storage;
if(!username) return false;
window.dashboardplus = window.dashboardplus || {};
window.dashboardplus['base'] = window.dashboardplus['base'] || '//dtbaker.github.io/dashboard-plus/';
window.dashboardplus['user'] = username;
try{
window.dashboardplus['storage'] = $.parseJSON(localStorage.getItem('dashboardplus'));
if(!window.dashboardplus['storage']) {
window.dashboardplus['storage'] = {};
save('firstvisit', true);
if(confirm('Welcome to Dashboard Plus!\nYou have to enable plugins at the settings page!\n\nGo there?')){
location.href = '/user/'+username+'/edit#dashboard_plus';
}
}
}catch (e) {
window.dashboardplus['storage'] = {};
}
window.dashboardplus.set = function(extension, name, value){
var obj = localStorage[extension] ? $.parseJSON(localStorage[extension]) : {};
obj[name] = value;
localStorage.setItem(extension, JSON.stringify(obj));
};
window.dashboardplus.get = function(extension, name){
var obj = localStorage[extension] || false;
if(!obj) return '';
obj = $.parseJSON(obj);
return (obj[name]) ? obj[name] : '';
};
window.dashboardplus.delete = function(extension, name){
if(!name){
localStorage.removeItem(extension);
}else{
var obj = localStorage[extension] ? $.parseJSON(localStorage[extension]) : {};
if(obj[name]){
delete(obj[name]);
localStorage.setItem(extension, JSON.stringify(obj));
}
}
};
window.dashboardplus.setCookie = function(cookieName, value, daysToExpire, path, domain, secure) {
var expiryDate;
cookieName = cookiePrefix + cookieName;
if (daysToExpire) {
expiryDate = new Date();
expiryDate.setTime(expiryDate.getTime() + (daysToExpire * 8.64e7));
}
document.cookie = cookieName + '=' + (value.toString()) +
(daysToExpire ? ';expires=' + expiryDate.toGMTString() : '') +
';path=' + (path ? path : '/') +
(domain ? ';domain=' + domain : '') +
(secure ? ';secure' : '');
return window.dashboardplus.getCookie(cookieName);
};
window.dashboardplus.getCookie = function(cookieName) {
cookieName = cookiePrefix + cookieName;
var cookiePattern = new RegExp('(^|;)[ ]*' + cookieName + '=([^;]*)'),
cookieMatch = cookiePattern.exec(document.cookie);
if(cookieMatch){
return cookieMatch[2];
}
return 0;
};
window.dashboardplus.deleteCookie = function(cookieName) {
return window.dashboardplus.setCookie(cookieName, 0, -1);
};
var fontawesome = $('<link id="dashboard-plus-font" media="all" type="text/css" href="//netdna.bootstrapcdn.com/font-awesome/4.0.3/css/font-awesome.min.css" rel="stylesheet">');
var active_plugins = get('active', {});
var $content = $('#content');
var plugins = {
'statementer': {
'name': 'Statementer',
'desc': 'Advanced Statement Section (graphs etc..)'
},
'statement_merge': {
'name': 'Statement Merge',
'desc': 'Merge author fees into a single row on the statement page'
},
'notification': {
'name': 'Notifications',
'desc': 'Display count of unread item comments'
},
'reminder': {
'name': 'Withdrawal reminder',
'desc': 'never forget to withdraw your earned money!',
'settings':[
{
'id': 'hours',
'label': 'define the hours you would like to get reminded before deadline',
'placeholder': '1, 3, 24, 48, 72'
}
]
},
'editinline': {
'name': 'Edit Inline (currenlty disabled)',
'desc': 'Edit your items directly on the item description page'
},
'envatitor': {
'name': 'Envatitor Embedded',
'desc': 'Advanced editor for the forums',
'font': true
},
'verify': {
'name': 'Purchase Verification',
'desc': 'verify purchasecodes right on your dashboards sidebar'
},
'progressbar': {
'name': 'Upload Progressbar',
'desc': 'Show the progressbar on uploads'
},
'quickcollection': {
'name': 'Quickcollection',
'desc': 'Add items to your bookmarks from the item thumbnail'
},
'gotolivepreview': {
'name': 'GoToLivepreview',
'desc': 'open livepreview right from the item thumbnail (only CC, TF, AD)'
},
'chaching': {
'name': 'Cha-Ching for Envato Authors',
'desc': 'Sales Notification with sound!',
'settings':[
{
'id': 'playsound',
'type': 'checkbox',
'label': 'play sound'
}
]
},
// 'salesrefresher': {
// 'name': 'Sales Refresher',
// 'desc': 'Refresh your salescount without reloading the site (click on your balance to reload)',
// 'settings':[
// {
// 'id': 'autoreload',
// 'type': 'checkbox',
// 'label': 'autoreload every 5 minutes'
// }
// ]
// },
'replypantry': {
'name': 'Reply Pantry',
'desc': 'Store canned text for use in forums and item comments'
},
'compare_earnings': {
'name': 'Compare Earnings',
'desc': 'allows you to compare your earnings with a previous month/year'
},
'_localdevelopment': {
'beta': true,
'name': 'Local Development',
'desc': 'development only'
}
};
//Dashboard Page
if (location.href.match(/^https?:\/\/([\.a-z3]+)\.(net)\/author_dashboard/)) {
enque('envatitor');
enque('verify');
enque('progressbar');
enque('replypantry');
//Earnings Page
}else if (location.href.match(/^https?:\/\/([\.a-z3]+)\.(net)\/user\/(\w+)\/earnings\/(total_sales|item_sales|referrals|support_sales)\/(.*)/)) {
enque('compare_earnings');
//Settings Page
}else if (window.location.href.match(/^https?:\/\/[\.a-z3]+\.net\/user\/.*\/statement/) || location.href.match(/^https?:\/\/([\.a-z3]+)\.(net)\/statement/)) {
enque('statementer');
enque('statement_merge');
//Forums Page
}else if (location.href.match(/^https?:\/\/([\.a-z3]+)\.(net)\/user\/([\w-]+)\/(\w+)/)) {
settingspage();
//Statement Page
}else if (location.href.match(/^https?:\/\/([\.a-z3]+)\.(net)\/forums\//)) {
enque('envatitor');
enque('replypantry');
//Upload Page
}else if (location.href.match(/^https?:\/\/([\.a-z3]+)\.(net)\/upload\//)) {
enque('envatitor');
//item edit page
}else if (location.href.match(/^https?:\/\/([\.a-z3]+)\.(net)\/item\/([a-z0-9-]+)\/edit/)) {
enque('envatitor');
//item discussion page
}else if (location.href.match(/^https?:\/\/([\.a-z3]+)\.(net)\/item\/([a-z0-9-]+)\/discussion/)) {
enque('envatitor');
enque('replypantry');
//item discussion page
}else if (location.href.match(/^https?:\/\/([\.a-z3]+)\.(net)\/item\/([a-z0-9-]+)\/([0-9]+)\/comments/)) {
enque('envatitor');
enque('replypantry');
//item faq page
}else if (location.href.match(/^https?:\/\/([\.a-z3]+)\.(net)\/item\/([a-z0-9-]+)\/([0-9]+)\/faqs/)) {
enque('envatitor');
//item discussion page
}
if (location.href.match(/^https?:\/\/(themeforest|codecanyon|activeden)\.net/)) {
enque('gotolivepreview');
}
if (location.href.match(/^https?:\/\/([\.a-z3]+)\.(net)\/item\/([a-z0-9-]+)/)) {
//enque('editinline');
}
//everywhere;
enque('notification');
enque('quickcollection');
enque('chaching');
// enque('salesrefresher');
enque('reminder');
enque('_localdevelopment');
load(function(){
console.log('Thanks for using Dashboard Plus!');
});
function enque(plugin){
if(!plugin || !active_plugins[plugin] || !plugins[plugin]) return false;
loadit.push(plugin);
if(plugins[plugin].font || plugin == '_localdevelopment'){
fontawesome.appendTo('head');
}
delete active_plugins[plugin];
}
function load(callback){
if(!loadit.length) return false;
loadit.sort();
var url = window.dashboardplus['base']+'plugins/';
var script_count = 0;
for(var item in loadit){
script_count++;
console.log(plugins[loadit[item]].name+' loaded!');
var plugin_url = url + loadit[item] + '.js?v=' + version;
console.log("Loading script: "+script_count + " url: " + plugin_url);
$.ajax({
url: plugin_url,
dataType: "script",
success: function(){
script_count--;
console.log("Left to load: "+script_count);
if(script_count<=0){
// we've loaded all scripts completely... run our callback
callback();
}
},
cache: true
});
}
}
function settingspage(){
var active = (location.hash == '#dashboard_plus') ? ' active' : '';
$content.find('.side-tabs').append('<li><a id="dashboard_plus_link" href="#dashboard_plus" class="'+active+' glyph-plus">Dashboard Plus</a></li><style>.side-tabs a#dashboard_plus_link:before{background-position:-240px -168px;}.side-tabs a#dashboard_plus_link.active:before{background-position:13px -232px;}</style>');
var boxhtml = '<div id="dashboard_plus_tab" class="tab-content'+active+'" style="display:block"><h2 class="underlined">Dashboard Plus</h2><p>Select all features you would like to activate. Please check out the <a href="/forums/thread/introducing-dashboard-plus/71870">forum thread</a> if you have questions</p><p></p><h3 class="underlined">Available Plugins</h3><form id="dashboardplus_form" class="horizontal-form"><fieldset>';
$.each(plugins, function(id, data){
if(!(typeof data.beta != 'undefined' && !(username == 'revaxarts'))){
boxhtml += '<div class="input-group"><label for="dbp_'+id+'">'+data.name+'</label><div class="inputs"><label for="dbp_'+id+'"> <input id="dbp_'+id+'" name="active[]" class="dbp_plugins" type="checkbox" value="'+id+'" '+(active_plugins[id] ? ' checked' : '')+'> '+data.desc+'</label>';
if(data.settings){
$.each(data.settings, function (i, setting){
if(!setting.type) setting.type = 'textfield';
if(!setting.placeholder) setting.placeholder = '';
boxhtml += '<div style="padding-left:20px">';
switch(setting.type){
case 'checkbox':
boxhtml += '<label><input class="dbp_setting" type="checkbox" '+(window.dashboardplus.get(id, setting.id) ? ' checked' : '')+' data-id="'+id+'" data-name="'+setting.id+'"> '+setting.label+'</label>';
break;
case 'textfield':
default:
boxhtml += ''+setting.label+' <input class="dbp_setting" placeholder="'+(setting.placeholder)+'" type="text" value="'+(window.dashboardplus.get(id, setting.id))+'" style="width:100%" data-id="'+id+'" data-name="'+setting.id+'">';
break;
}
boxhtml += '</div>';
});
}
boxhtml += '</div> </div>';
}
});
boxhtml += '</fieldset><div class="form-submit"><a id="dbp_reset_button" href="#dashboard_plus">Reset all settings</a> or <button id="dbp_submit_button" class="btn-icon save" type="submit">Save</button></div></form><a style="font-size:10px" href="https://www.paypal.com/cgi-bin/webscr?cmd=_donations&business=U4V8TKF6WNYZ2&lc=AT&item_name=revaxarts%20Statementer&currency_code=USD&bn=PP%2dDonationsBF%3abtn_donateCC_LG%2egif%3aNonHosted" title="for those who are too enthusiastic about">buy me a beer</a></div>';
$('#dashboard_plus_link').click(function(){
$content.find('.content-s').html(boxhtml);
$content.find('.layout__sidebar').find('a').removeClass('active');
$(this).addClass('active');
$('#dashboardplus_form').on('submit', function(){
var data = {};
var setting = {};
$.each($('.dbp_plugins'), function(){
if($(this).is(':checked')) data[$(this).val()] = true;
});
$.each($('.dbp_setting'), function(){
var id = $(this).data('id');
if(!setting[id]) setting[id] = {};
setting[id][$(this).data('name')] = ($(this).is(':checkbox') ? $(this).is(':checked') : $(this).val());
});
$.each(setting, function(extension, data){
savesettings(extension, data);
});
if(save('active', data)) location.reload();
return false;
});
$('#dbp_reset_button').on('click', function(){
if(confirm('Do you really like ti reset all Dashboard Plus settings?\n\n This is only for the current marketplace!')){
var storage = ['apikey', 'chaching', 'dashboardplus', 'quickcollection', 'ratings__', 'reminder', 'salesrefresher', 'statementer'];
var cookies = ['envatitor_badges', 'envatitor_thumb', 'notification_count', 'notification_lastcheck', 'quickcollection_lastcheck', 'statementer_lastbalance'];
$.each(storage, function(i,e){
console.log(e, i);
localStorage.removeItem(e);
});
$.each(cookies, function(i,e){
console.log(e, i);
window.dashboardplus.deleteCookie(e);
});
location.reload();
}
return false;
});
return false;
});
if(active == ' active') $('#dashboard_plus_link').trigger('click');
}
function savesettings(extension, data){
$.each(data, function(name, value){
window.dashboardplus.set(extension, name, value);
});
}
function save(setting, value){
var settings = window.dashboardplus.storage || {};
settings[setting] = value;
localStorage.setItem('dashboardplus', JSON.stringify(settings));
window.dashboardplus.storage = settings;
return window.dashboardplus.storage[setting] == value;
}
function get(setting, fallback){
return window.dashboardplus.storage[setting] ? window.dashboardplus.storage[setting] : fallback;
}
}
})();