diff --git a/lib/routes.js b/lib/routes.js index f9e787ed..ca40f985 100644 --- a/lib/routes.js +++ b/lib/routes.js @@ -169,8 +169,6 @@ module.exports = function (app) { var static = sandbox.helpers.urlForStatic('', req.secure); var referrer = req.get('referer'); - console.log(req.param('page'), pages.indexOf(req.param('page'))); - var page = pages.indexOf(req.param('page')) === -1 ? false : req.param('page') + '.html'; var addons = []; diff --git a/public/css/account.css b/public/css/account.css index b5a4d1d8..27a0dc7e 100644 --- a/public/css/account.css +++ b/public/css/account.css @@ -51,7 +51,7 @@ margin-left: 230px; form input[type="submit"] { /* width:60%; */ margin:10px 20%; - font-family: "Helvetica Neue", "Arial"; +/* font-family: "Helvetica Neue", "Arial"; font-size: 0.75em; background: #f0f0f0; background: linear-gradient(0deg, #f0f0f0, #fefefe); @@ -66,10 +66,10 @@ form input[type="submit"] { box-sizing: border-box; text-align: center; text-decoration: none; - font-weight:600; + font-weight:600;*/ } form input[type="submit"]:hover { - background: linear-gradient(0deg, #e8e8e8, #f8f8f8); + /*background: linear-gradient(0deg, #e8e8e8, #f8f8f8);*/ } form input { font-size: 16px; @@ -138,4 +138,16 @@ form label.mini-desc a { display: inline; font-weight: normal; margin-right: 0; +} + +.loginFeedback { + display: none; + padding: 3px; + background: #EFF3B6; + background: rgba(255, 253, 0, 0.2); + border: 1px solid rgb(219, 225, 45); + margin: 0; + white-space: normal; + line-height: 18px; + margin-bottom: 1em; } \ No newline at end of file diff --git a/public/js/account-settings.js b/public/js/account-settings.js deleted file mode 100644 index 0496ecbf..00000000 --- a/public/js/account-settings.js +++ /dev/null @@ -1,33 +0,0 @@ -;(function(){ - - function getHash(){ - return window.location.hash.slice(1); - } - - var $contents = $('#content article') - var $btns = $('.sidebar-btn').click(function(event){ - $btns.removeClass('selected'); - var hash = $(this).addClass('selected')[0].hash.slice(1); - $contents.hide().filter(function(i, el){ - return el.id === hash - }).show(); - - }); - - // Kick it all off - - if(!window.location.hash) { - window.location.hash = $btns.filter(function(i, el){ - return el.attributes.default; - })[0].hash; - } - - $contents.filter(function(i, el){ - return el.id === getHash(); - }).show(); - - $btns.filter(function(i, el){ - return el.hash === window.location.hash; - }).addClass('selected'); - -})//() diff --git a/public/js/account/account-settings.js b/public/js/account/account-settings.js new file mode 100644 index 00000000..3333ab13 --- /dev/null +++ b/public/js/account/account-settings.js @@ -0,0 +1,39 @@ +(function(){ + 'use strict'; + + /* globals $ */ + + $('form.login').submit(function (event) { + event.preventDefault(); + + var form = $(this); + var name = form.find('input[name=username]').val(); + var key = form.find('input[name=password]').val(); + var email = form.find('input[name=email]').val(); + var $loginFeedback = form.find('.loginFeedback'); + var $csrf = $('#_csrf'); + + $loginFeedback.show().text('Checking...'); + + $.ajax({ + url: form.attr('action'), + data: { + username: name, + key: key, + email: email, + _csrf: $csrf.val() + }, + type: 'POST', + dataType: 'json', + complete: function (jqXHR) { + var data = $.parseJSON(jqXHR.responseText) || {}; + if (jqXHR.status === 200) { + if (data.message) { + $loginFeedback.text(data.message); + } + } + } + }); + }); + +})(); \ No newline at end of file diff --git a/public/js/editor-settings.js b/public/js/account/editor-settings.js similarity index 99% rename from public/js/editor-settings.js rename to public/js/account/editor-settings.js index c9473280..4ae36880 100644 --- a/public/js/editor-settings.js +++ b/public/js/account/editor-settings.js @@ -65,6 +65,7 @@ ]; var addonsKeys = [ + 'activeline', 'closebrackets', 'highlight', 'matchtags', diff --git a/public/js/account/preferences-settings.js b/public/js/account/preferences-settings.js new file mode 100644 index 00000000..0a0ab904 --- /dev/null +++ b/public/js/account/preferences-settings.js @@ -0,0 +1,118 @@ +(function(){ + 'use strict'; + + /* global $ */ + + function getCurrentSettings(){ + return JSON.parse(localStorage.settings || '{}') || { + + }; + } + + $.browser = {}; + // work out the browser platform + var ua = navigator.userAgent; + if (ua.indexOf(' Mac ') !== -1) { + $.browser.platform = 'mac'; + } else if (/windows|win32/.test(ua)) { + $.browser.platform = 'win'; + } else if (/linux/.test(ua)) { + $.browser.platform = 'linux'; + } else { + $.browser.platform = ''; + } + + // Setup variables + var $csrf = $('#_csrf'); + var currentSettings = { + panels: [], + includejs: true, + focusedPanel: 'html', + jshint: true + }; + $.extend(currentSettings, getCurrentSettings()); + var panels = ['html', 'css', 'javascript', 'console', 'live']; + var $panels = {}; + var $includejs = $('#includejs').prop('checked', currentSettings.includejs); + var $focusedPanel = $('#focused-panel').val(currentSettings.focusedPanel); + var hints = ['js']; + var $hints = {}; + + var jshints = { + 'forin': 'About unsafe for..in', + 'eqnull': 'About == null', + 'noempty': 'About empty blocks', + 'eqeqeq': 'About unsafe comparisons', + 'boss': 'About assignments inside if/for/...', + 'undef': 'When variable is undefined', + 'unused': 'When variable is defined but not used', + 'curly': 'When blocks omit {}' + }; + var source = ''; + + for (var i = 0; i < panels.length; i++) { + $panels[panels[i]] = $('#panel-' + panels[i]) + .prop('checked', currentSettings.panels.indexOf(panels[i]) !== -1); + } + + for (var m = 0; m < hints.length; m++) { + $hints[hints[m]] = $('#' + hints[m] + 'hint') + .prop('checked', currentSettings[ hints[m] + 'hint' ]); + } + + for (var prop in jshints) { + if (jshints.hasOwnProperty(prop)) { + source += '
' + + '' + + '
'; + } + } + + // Listeners + $(':checkbox').on('change', saveSettings); + $('select').on('change', saveSettings); + + function saveSettings() { + // Merge all our settings together + var localStorageSettings = JSON.parse(localStorage.settings || '{}'); + + localStorageSettings.panels = []; + for (var i = 0; i < panels.length; i++) { + if ($panels[panels[i]].prop('checked')) { + localStorageSettings.panels.push(panels[i]); + } + } + + for (var m = 0; m < hints.length; m++) { + localStorageSettings[ hints[m] + 'hint' ] = $hints[hints[m]].prop('checked'); + } + + localStorageSettings.includejs = $includejs.prop('checked'); + localStorageSettings.focusedPanel = $focusedPanel.val(); + + localStorage.settings = JSON.stringify(localStorageSettings); + console.log(localStorageSettings); + + // Save on server + $.ajax({ + url: 'editor', + type: 'POST', + dataType: 'json', + data: { + settings: JSON.stringify(localStorageSettings), + _csrf: $csrf.val() + }, + success: function() { + if (console && console.log) { + console.log('Success on saving settings'); + } + }, + error: function(xhr, status) { + if (console && console.log) { + console.log('Error: ' + status); + } + } + }); + } + +})(); \ No newline at end of file diff --git a/public/js/editors/addons.js b/public/js/editors/addons.js index 58f5538c..a723645e 100644 --- a/public/js/editors/addons.js +++ b/public/js/editors/addons.js @@ -9,7 +9,9 @@ emacs: false, trailingspace: false, fold: false, - sublime: false + sublime: false, + tern: false, + activeline: true }; if (!jsbin.settings.addons) { @@ -149,6 +151,17 @@ done: function () { CodeMirror.startTern(); } + }, + activeline: { + url: [ + '/js/vendor/codemirror4/addon/selection/active-line.js' + ], + test: function() { + return CodeMirror.defaults.styleActiveLine !== undefined; + }, + done: function(cm) { + setOption(cm, 'styleActiveLine', true); + } } }; diff --git a/public/js/editors/editors.js b/public/js/editors/editors.js index 6afe04be..e289714a 100644 --- a/public/js/editors/editors.js +++ b/public/js/editors/editors.js @@ -162,8 +162,14 @@ panels.restore = function () { } } - if (state !== null && toopen.length === 0) { - toopen = Object.keys(state); + if (toopen.length === 0) { + if (state !== null) { + toopen = Object.keys(state); + } + else { + // load from personal settings + toopen = jsbin.settings.panels; + } } if (toopen.length === 0) { diff --git a/public/js/editors/panel.js b/public/js/editors/panel.js index e6b522cf..29becdf1 100644 --- a/public/js/editors/panel.js +++ b/public/js/editors/panel.js @@ -93,7 +93,6 @@ var Panel = function (name, settings) { dragDrop: false, // we handle it ourselves mode: editorModes[panelLanguage], lineWrapping: true, - styleActiveLine: true, theme: jsbin.settings.theme || 'jsbin' }; @@ -369,7 +368,7 @@ Panel.prototype = { if (this.settings.init) this.settings.init.call(this); }, _setupEditor: function () { - var focusedPanel = sessionStorage.getItem('panel'), + var focusedPanel = sessionStorage.getItem('panel') || jsbin.settings.focusedPanel, panel = this, editor = panel.editor; diff --git a/scripts.json b/scripts.json index 42a1850a..05d58619 100644 --- a/scripts.json +++ b/scripts.json @@ -15,7 +15,6 @@ "/js/vendor/cm_addons/simple-hint.js", "/js/vendor/cm_addons/javascript-hint.js", "/js/vendor/codemirror4/addon/edit/matchbrackets.js", - "/js/vendor/codemirror4/addon/selection/active-line.js", "/js/vendor/codemirror4/addon/comment/comment.js", "/js/editors/snippets.cm.js", "/js/vendor/json2.js", diff --git a/views/account/editor.html b/views/account/editor.html index 1941d04e..42f5986f 100644 --- a/views/account/editor.html +++ b/views/account/editor.html @@ -35,6 +35,8 @@

Customise your JS Bin editor

+

As soon as you make any changes, they will be automatically saved.

+

Settings

@@ -104,6 +106,12 @@
+
+ + + +
+
@@ -168,7 +176,6 @@ - - + {{#addons}}{{/addons}} diff --git a/views/account/preferences.html b/views/account/preferences.html index 52c881c8..581f19a8 100644 --- a/views/account/preferences.html +++ b/views/account/preferences.html @@ -3,8 +3,9 @@

Default Preferences

-

Configure how JS Bin is set up when you create a new bin, such as your default - HTML content, processors selected, and more.

+

Configure how JS Bin is set up when you create a new bin.
+ As soon as you make any changes, they will be automatically saved.

@@ -13,9 +14,9 @@ Open panels - + - +
@@ -23,49 +24,22 @@
- - -
- -

Processors

-
- - + +
- - + +
- -
- - -
- -

Template

-

The template is the default content that appears in your new bins.

+
-
\ No newline at end of file + + + \ No newline at end of file diff --git a/views/account/profile.html b/views/account/profile.html index c8817597..6b579144 100644 --- a/views/account/profile.html +++ b/views/account/profile.html @@ -2,20 +2,29 @@

Your personal details

-
-

Not working right now, come back soon my love!

-
- - - - -
+
+

+ +
+ + +
+ +
+ + +
+ +
+ + +
+ + + +
- \ No newline at end of file + \ No newline at end of file diff --git a/views/partials/account_sidebar.html b/views/partials/account_sidebar.html index bd817eeb..d2811cc1 100644 --- a/views/partials/account_sidebar.html +++ b/views/partials/account_sidebar.html @@ -1,16 +1,13 @@