From 47fa72c20286644450cb1c6589ce05f2ca6b5c21 Mon Sep 17 00:00:00 2001 From: Giulia Alfonsi Date: Mon, 31 Mar 2014 14:05:29 +0100 Subject: [PATCH 01/16] Added active line as addon. --- public/js/editor-settings.js | 1 + public/js/editors/addons.js | 14 +++++++++++++- public/js/editors/panel.js | 1 - scripts.json | 1 - views/account/editor.html | 7 ++++++- 5 files changed, 20 insertions(+), 4 deletions(-) diff --git a/public/js/editor-settings.js b/public/js/editor-settings.js index 3d35aa0d..e499e4e9 100644 --- a/public/js/editor-settings.js +++ b/public/js/editor-settings.js @@ -64,6 +64,7 @@ ]; var addonsKeys = [ + 'activeline', 'closebrackets', 'highlight', 'matchtags', diff --git a/public/js/editors/addons.js b/public/js/editors/addons.js index d2f8609a..ea9eb87f 100644 --- a/public/js/editors/addons.js +++ b/public/js/editors/addons.js @@ -9,7 +9,8 @@ emacs: false, trailingspace: false, fold: false, - sublime: false + sublime: false, + activeline: false }; if (!jsbin.settings.addons) { @@ -154,6 +155,17 @@ done: function (cm) { // } + }, + 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/panel.js b/public/js/editors/panel.js index e6b522cf..aabc8b5c 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' }; diff --git a/scripts.json b/scripts.json index 57bf0a76..e9407762 100644 --- a/scripts.json +++ b/scripts.json @@ -16,7 +16,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 73afe608..e08405bc 100644 --- a/views/account/editor.html +++ b/views/account/editor.html @@ -104,6 +104,12 @@ +
+ + + +
+
@@ -168,7 +174,6 @@ - From a42dbe95cd8a8e911e436375901efcfa132170f4 Mon Sep 17 00:00:00 2001 From: Giulia Alfonsi Date: Mon, 31 Mar 2014 15:47:13 +0100 Subject: [PATCH 02/16] Saving preferences --- public/js/preferences-settings.js | 69 +++++++++++++++++++++++++++++ views/account/preferences.html | 11 +++-- views/partials/account_sidebar.html | 2 +- 3 files changed, 77 insertions(+), 5 deletions(-) create mode 100644 public/js/preferences-settings.js diff --git a/public/js/preferences-settings.js b/public/js/preferences-settings.js new file mode 100644 index 00000000..9e0bd16d --- /dev/null +++ b/public/js/preferences-settings.js @@ -0,0 +1,69 @@ +(function(){ + 'use strict'; + + /* global $ */ + + function getCurrentSettings(){ + return JSON.parse(localStorage.settings || '{}') || { + + }; + } + + // Setup variables + var $csrf = $('#_csrf'); + var currentSettings = { + panels: [], + includejs: false, + focusedPanel: 'html' + }; + $.extend(currentSettings, getCurrentSettings()); + var panels = ['html', 'css', 'js', 'console', 'live']; + var $panels = {}; + var $includejs = $('#includejs').prop('checked', currentSettings.includejs); + var $focusedPanel = $('#focused-panel').val(currentSettings.focusedPanel); + + for (var i = 0; i < panels.length; i++) { + $panels[panels[i]] = $('#panel-' + panels[i]) + .prop('checked', currentSettings.panels.indexOf(panels[i]) !== -1); + } + + // 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]); + } + } + + 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() { + // console.log('success'); + }, + error: function() { + // console.log('there was an error saving'); + } + }); + } + +})(); \ No newline at end of file diff --git a/views/account/preferences.html b/views/account/preferences.html index 52c881c8..0fee8bbc 100644 --- a/views/account/preferences.html +++ b/views/account/preferences.html @@ -15,7 +15,7 @@ - +
@@ -29,8 +29,8 @@
- - + +

Processors

@@ -67,5 +67,8 @@

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/partials/account_sidebar.html b/views/partials/account_sidebar.html index 67d84a20..955f81ff 100644 --- a/views/partials/account_sidebar.html +++ b/views/partials/account_sidebar.html @@ -2,7 +2,7 @@ @@ -23,7 +23,7 @@ From e52c76cc85ea782a46a71870a608ce7772f8af0d Mon Sep 17 00:00:00 2001 From: Giulia Alfonsi Date: Wed, 9 Apr 2014 10:56:21 +0100 Subject: [PATCH 07/16] Load focused panel from user settings --- public/js/editors/panel.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/public/js/editors/panel.js b/public/js/editors/panel.js index aabc8b5c..29becdf1 100644 --- a/public/js/editors/panel.js +++ b/public/js/editors/panel.js @@ -368,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; From a029c4f2bb9ffe9274101f9bf039d80ba95071e9 Mon Sep 17 00:00:00 2001 From: Giulia Alfonsi Date: Wed, 9 Apr 2014 16:16:49 +0100 Subject: [PATCH 08/16] jshint options --- public/css/account.css | 3 +- public/js/chrome/errors.js | 2 +- public/js/preferences-settings.js | 91 ++++++++++++++++++++++++++++++- views/account/preferences.html | 60 ++++++++++++++++++++ 4 files changed, 151 insertions(+), 5 deletions(-) diff --git a/public/css/account.css b/public/css/account.css index b5a4d1d8..7d6163b6 100644 --- a/public/css/account.css +++ b/public/css/account.css @@ -93,7 +93,8 @@ select { min-width: 120px; } -form > div { +form > div, +#jshintOptions div { min-height: 32px; /* clear: left; */ overflow: hidden; diff --git a/public/js/chrome/errors.js b/public/js/chrome/errors.js index d2905ca3..eb52af0e 100644 --- a/public/js/chrome/errors.js +++ b/public/js/chrome/errors.js @@ -2,7 +2,7 @@ var jshint = function () { var source = editors.javascript.editor.getCode(); - var ok = JSHINT(source); + var ok = JSHINT(source, jsbin.settings.jshintOption); return ok ? true : JSHINT.data(); }; diff --git a/public/js/preferences-settings.js b/public/js/preferences-settings.js index 5ca29e11..f16b7b85 100644 --- a/public/js/preferences-settings.js +++ b/public/js/preferences-settings.js @@ -1,7 +1,7 @@ (function(){ 'use strict'; - /* global $ */ + /* global $, CodeMirror, jshint */ function getCurrentSettings(){ return JSON.parse(localStorage.settings || '{}') || { @@ -9,24 +9,95 @@ }; } + window.jsbin = { + 'settings': { + 'jshintOption': null + } + }; + + window.editors = { + 'javascript': { + 'editor': null, + 'visible': true + } + }; + + $.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: false, - focusedPanel: 'html' + includejs: true, + focusedPanel: 'html', + jshint: true, + jshintOptions: {} }; $.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', 'css']; + 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 $jshints = {}; + 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 += '
' + + '' + + '
'; + } + } + $('#jshintOptions').append(source); + for (var prop in jshints) { + if (jshints.hasOwnProperty(prop)) { + $jshints[prop] = $('#' + prop).prop('checked', currentSettings.jshintOptions[ prop ]); + } + } + + var $textarea = $('#editor-settings-example'); + editors.javascript.editor = CodeMirror.fromTextArea($textarea.get(0), $.extend({ + mode: 'text/javascript' + }, currentSettings.editor)); + + editors.javascript.editor.getCode = function () { + return editors.javascript.editor.getValue(); + }; + // Listeners $(':checkbox').on('change', saveSettings); $('select').on('change', saveSettings); @@ -42,12 +113,26 @@ } } + 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(); + localStorageSettings.jshintOptions = {}; + for (var prop in jshints) { + if (jshints.hasOwnProperty(prop)) { + localStorageSettings.jshintOptions[ prop ] = $jshints[prop].prop('checked'); + } + } + localStorage.settings = JSON.stringify(localStorageSettings); console.log(localStorageSettings); + window.jsbin.settings.jshintOption = localStorageSettings.jshintOptions; + jshint(); + // Save on server $.ajax({ url: 'editor', diff --git a/views/account/preferences.html b/views/account/preferences.html index 646225a5..c381c23f 100644 --- a/views/account/preferences.html +++ b/views/account/preferences.html @@ -1,4 +1,35 @@ {{> account_sidebar}} + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +

Default Preferences

@@ -33,6 +64,29 @@ +

JSHint

+
+ + +
+ +

Settings

+
+ +

Preview

+ + +

CSSLint

+
+ + +
+

Processors

@@ -71,4 +125,10 @@ + + + + + + \ No newline at end of file From 4451c8212a9858047d248d190f1d402f43a81ffb Mon Sep 17 00:00:00 2001 From: Giulia Alfonsi Date: Wed, 9 Apr 2014 18:29:31 +0100 Subject: [PATCH 09/16] Started adding template settings --- public/js/chrome/navigation.js | 20 +++++++++++++++++++- views/account/preferences.html | 32 -------------------------------- views/index.html | 2 +- 3 files changed, 20 insertions(+), 34 deletions(-) diff --git a/public/js/chrome/navigation.js b/public/js/chrome/navigation.js index d3b55338..67a8e21f 100644 --- a/public/js/chrome/navigation.js +++ b/public/js/chrome/navigation.js @@ -17,7 +17,25 @@ var $startingpoint = $('a.startingpoint').click(function (event) { content: 'Saving templates isn\'t supported in this browser I\'m afraid. Sorry' }); } - return false; + + $.ajax({ + type: 'post', + url: this.href, + data: { url: jsbin.getURL() }, + success: function () { + $document.trigger('tip', { + type: 'notification', + content: 'Starting template updated and saved', + autohide: 3000 + }); + }, + error: function (xhr) { + $document.trigger('tip', { + type: 'error', + content: 'There was a problem creating the template. Can you try again or file a new issue?' + }); + } + }); }); // if (localStorage && localStorage['saved-html']) { diff --git a/views/account/preferences.html b/views/account/preferences.html index c381c23f..dac63674 100644 --- a/views/account/preferences.html +++ b/views/account/preferences.html @@ -87,38 +87,6 @@ var longVariableNameToDemonstrateLineWrappingInCodeMirror = 'line wrapping i
-

Processors

-
- - -
- -
- - -
- -
- - -
-

Template

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

diff --git a/views/index.html b/views/index.html index 66c0b2f0..6e467cfe 100644 --- a/views/index.html +++ b/views/index.html @@ -51,7 +51,7 @@ {{/feature}} Export as gist Download - Save as template + Save as template How to embed From d287f10973f875385d0a72dea3249890ca77abb5 Mon Sep 17 00:00:00 2001 From: Giulia Alfonsi Date: Thu, 10 Apr 2014 09:38:56 +0100 Subject: [PATCH 10/16] Still not working --- lib/db/mysql.js | 2 +- lib/db/sql_templates.json | 2 +- lib/handlers/user.js | 13 +++++++++++++ lib/models/user.js | 8 ++++++-- lib/routes.js | 15 +++++++++++++++ 5 files changed, 36 insertions(+), 4 deletions(-) diff --git a/lib/db/mysql.js b/lib/db/mysql.js index d023f30e..02a31b39 100644 --- a/lib/db/mysql.js +++ b/lib/db/mysql.js @@ -532,7 +532,7 @@ module.exports = utils.inherit(Object, { updateOwnersData: updateMultipleFields(templates.updateOwnersData, templates.ownersColumns), saveBookmark: function (params, fn) { var sql = templates.saveBookmark; - this.connection.query(sql, [params.name, params.url, params.revision, params.type, new Date()], fn); + this.connection.query(sql, [params.name, params.url, params.revision, params.type, params.description, new Date()], fn); }, getBookmark: function (params, fn) { var sql = templates.getBookmark; diff --git a/lib/db/sql_templates.json b/lib/db/sql_templates.json index 9262039f..8d123884 100644 --- a/lib/db/sql_templates.json +++ b/lib/db/sql_templates.json @@ -45,7 +45,7 @@ "setBinVisibility": "UPDATE `owners` SET `visibility`=? WHERE `name`=? AND `url`=?", "getBinMetadata": "SELECT * FROM `owners` AS `o`, `ownership` AS `os` WHERE o.name=os.name AND o.url=? AND o.revision=?", "setProAccount": "UPDATE ownership SET `pro`=?, `updated`=? WHERE `name`=?", - "saveBookmark": "INSERT INTO owner_bookmarks (`name`, `url`, `revision`, `type`, `created`) VALUES (?,?,?,?,?)", + "saveBookmark": "INSERT INTO owner_bookmarks (`name`, `url`, `revision`, `type`, `description`, `created`) VALUES (?,?,?,?,?,?)", "getBookmark": "SELECT * FROM owner_bookmarks WHERE `name`=? AND `type`=? ORDER BY `created` DESC", "sandboxColumns": [ "created", diff --git a/lib/handlers/user.js b/lib/handlers/user.js index ae1575c0..9a42f68c 100644 --- a/lib/handlers/user.js +++ b/lib/handlers/user.js @@ -57,6 +57,19 @@ module.exports = Observable.extend({ } }, + saveTemplateURL: function (req, res) { + userModel.saveBookmark(req.session.user, req.bin, 'template', function (err) { + if (err) { + return res.send(500, err); + } + res.send({ ok: true }); + }, 'default'); + }, + + loadTemplateURL: function (req, res, next) { + + }, + validateRegister: function (req, res, next) { var username = req.param('username'); var email = req.param('email'); diff --git a/lib/models/user.js b/lib/models/user.js index 467af549..d0ff1dcd 100644 --- a/lib/models/user.js +++ b/lib/models/user.js @@ -220,12 +220,16 @@ module.exports = Observable.extend({ }; this.store.updateOwners(params, fn); }, - saveBookmark: function (user, bin, type, fn) { + saveBookmark: function (user, bin, type, fn, description) { + if (!description) { + description = ''; + } var params = { name: user.name, url: bin.url, revision: bin.revision, - type: type + type: type, + description: description }; this.store.saveBookmark(params, fn); }, diff --git a/lib/routes.js b/lib/routes.js index b48513a6..7db2792b 100644 --- a/lib/routes.js +++ b/lib/routes.js @@ -351,6 +351,21 @@ module.exports = function (app) { next(); }, binHandler.createRevisionOrClone); + // Save as template + app.get('/save-as-template', binParamFromReferer, binHandler.loadBin, userHandler.saveVanityURL); + app.post('/save-as-template', function (req, res, next) { + reBin.lastIndex = 0; // reset position + + // only allow cloning via url if it came from jsbin + var match = req.body.url.match(reBin) || []; + if (match.length) { + req.params.bin = match[1]; + req.params.rev = match[2]; + } + + next(); + }, binHandler.loadBin, userHandler.saveVanityURL); + // Bin based urls From e94c31d59393d9cb4ff4fcb07e5bf74b6f0d4b63 Mon Sep 17 00:00:00 2001 From: Giulia Alfonsi Date: Thu, 10 Apr 2014 11:51:58 +0100 Subject: [PATCH 11/16] Removed/hidden some unused stuff --- public/js/preferences-settings.js | 70 +++++++++++++++---------------- views/account/preferences.html | 57 +------------------------ 2 files changed, 36 insertions(+), 91 deletions(-) diff --git a/public/js/preferences-settings.js b/public/js/preferences-settings.js index f16b7b85..8e35cfe4 100644 --- a/public/js/preferences-settings.js +++ b/public/js/preferences-settings.js @@ -9,18 +9,18 @@ }; } - window.jsbin = { - 'settings': { - 'jshintOption': null - } - }; + // window.jsbin = { + // 'settings': { + // 'jshintOption': null + // } + // }; - window.editors = { - 'javascript': { - 'editor': null, - 'visible': true - } - }; + // window.editors = { + // 'javascript': { + // 'editor': null, + // 'visible': true + // } + // }; $.browser = {}; // work out the browser platform @@ -41,15 +41,15 @@ panels: [], includejs: true, focusedPanel: 'html', - jshint: true, - jshintOptions: {} + jshint: true//, + // jshintOptions: {} }; $.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', 'css']; + var hints = ['js']; var $hints = {}; var jshints = { @@ -82,21 +82,21 @@ ''; } } - $('#jshintOptions').append(source); - for (var prop in jshints) { - if (jshints.hasOwnProperty(prop)) { - $jshints[prop] = $('#' + prop).prop('checked', currentSettings.jshintOptions[ prop ]); - } - } + // $('#jshintOptions').append(source); + // for (var prop in jshints) { + // if (jshints.hasOwnProperty(prop)) { + // $jshints[prop] = $('#' + prop).prop('checked', currentSettings.jshintOptions[ prop ]); + // } + // } - var $textarea = $('#editor-settings-example'); - editors.javascript.editor = CodeMirror.fromTextArea($textarea.get(0), $.extend({ - mode: 'text/javascript' - }, currentSettings.editor)); + // var $textarea = $('#editor-settings-example'); + // editors.javascript.editor = CodeMirror.fromTextArea($textarea.get(0), $.extend({ + // mode: 'text/javascript' + // }, currentSettings.editor)); - editors.javascript.editor.getCode = function () { - return editors.javascript.editor.getValue(); - }; + // editors.javascript.editor.getCode = function () { + // return editors.javascript.editor.getValue(); + // }; // Listeners $(':checkbox').on('change', saveSettings); @@ -120,18 +120,18 @@ localStorageSettings.includejs = $includejs.prop('checked'); localStorageSettings.focusedPanel = $focusedPanel.val(); - localStorageSettings.jshintOptions = {}; - for (var prop in jshints) { - if (jshints.hasOwnProperty(prop)) { - localStorageSettings.jshintOptions[ prop ] = $jshints[prop].prop('checked'); - } - } + // localStorageSettings.jshintOptions = {}; + // for (var prop in jshints) { + // if (jshints.hasOwnProperty(prop)) { + // localStorageSettings.jshintOptions[ prop ] = $jshints[prop].prop('checked'); + // } + // } localStorage.settings = JSON.stringify(localStorageSettings); console.log(localStorageSettings); - window.jsbin.settings.jshintOption = localStorageSettings.jshintOptions; - jshint(); + // window.jsbin.settings.jshintOption = localStorageSettings.jshintOptions; + // jshint(); // Save on server $.ajax({ diff --git a/views/account/preferences.html b/views/account/preferences.html index dac63674..f8636c51 100644 --- a/views/account/preferences.html +++ b/views/account/preferences.html @@ -1,35 +1,4 @@ {{> account_sidebar}} - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

Default Preferences

@@ -64,39 +33,15 @@ -

JSHint

- +
-

Settings

-
- -

Preview

- - -

CSSLint

-
- - -
-

Template

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

- - - - - - \ No newline at end of file From 25288529388b06cdc970f6890238e213e170e167 Mon Sep 17 00:00:00 2001 From: Giulia Alfonsi Date: Thu, 10 Apr 2014 14:47:48 +0100 Subject: [PATCH 12/16] Profile panel --- lib/handlers/user.js | 13 +++++++ lib/routes.js | 4 +- public/css/account.css | 12 ++++++ public/js/account-settings.js | 60 ++++++++++++++++------------- views/account/preferences.html | 7 +--- views/account/profile.html | 35 ++++++++++------- views/partials/account_sidebar.html | 3 ++ 7 files changed, 87 insertions(+), 47 deletions(-) diff --git a/lib/handlers/user.js b/lib/handlers/user.js index 9a42f68c..b74b303d 100644 --- a/lib/handlers/user.js +++ b/lib/handlers/user.js @@ -67,7 +67,20 @@ module.exports = Observable.extend({ }, loadTemplateURL: function (req, res, next) { + // userModel.getBookmark(user, 'template', function (err, data) { + // if (err || data.length === 0) { + // if (err) { + // console.error(err); + // } + // return res.redirect(req.app.get('url full')); + // } + // req.params.rev = data[0].revision; + // req.params.bin = data[0].url; + + // req.params.quiet = 'quiet'; + // next(); + // }); }, validateRegister: function (req, res, next) { diff --git a/lib/routes.js b/lib/routes.js index 7db2792b..233b26c3 100644 --- a/lib/routes.js +++ b/lib/routes.js @@ -352,7 +352,7 @@ module.exports = function (app) { }, binHandler.createRevisionOrClone); // Save as template - app.get('/save-as-template', binParamFromReferer, binHandler.loadBin, userHandler.saveVanityURL); + app.get('/save-as-template', binParamFromReferer, binHandler.loadBin, userHandler.saveTemplateURL); app.post('/save-as-template', function (req, res, next) { reBin.lastIndex = 0; // reset position @@ -364,7 +364,7 @@ module.exports = function (app) { } next(); - }, binHandler.loadBin, userHandler.saveVanityURL); + }, binHandler.loadBin, userHandler.saveTemplateURL); // Bin based urls diff --git a/public/css/account.css b/public/css/account.css index 7d6163b6..edb0a7ab 100644 --- a/public/css/account.css +++ b/public/css/account.css @@ -139,4 +139,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 index 0496ecbf..3333ab13 100644 --- a/public/js/account-settings.js +++ b/public/js/account-settings.js @@ -1,33 +1,39 @@ -;(function(){ +(function(){ + 'use strict'; - function getHash(){ - return window.location.hash.slice(1); - } + /* globals $ */ - 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(); + $('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'); - // Kick it all off + $loginFeedback.show().text('Checking...'); - if(!window.location.hash) { - window.location.hash = $btns.filter(function(i, el){ - return el.attributes.default; - })[0].hash; - } + $.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); + } + } + } + }); + }); - $contents.filter(function(i, el){ - return el.id === getHash(); - }).show(); - - $btns.filter(function(i, el){ - return el.hash === window.location.hash; - }).addClass('selected'); - -})//() +})(); \ No newline at end of file diff --git a/views/account/preferences.html b/views/account/preferences.html index f8636c51..7358d6b4 100644 --- a/views/account/preferences.html +++ b/views/account/preferences.html @@ -3,8 +3,8 @@

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.

@@ -37,9 +37,6 @@ - -

Template

-

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

diff --git a/views/account/profile.html b/views/account/profile.html index c8817597..fa25fd4b 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 955f81ff..0e47b9db 100644 --- a/views/partials/account_sidebar.html +++ b/views/partials/account_sidebar.html @@ -4,6 +4,9 @@ Profile Preferences Editor settings + {{#feature request "github"}}{{#unless user.github_token}} + Link your Github account + {{/unless}}{{/feature}} Logout From f389f295883a67aff66f6d75cda412d62e6a967b Mon Sep 17 00:00:00 2001 From: Giulia Alfonsi Date: Thu, 10 Apr 2014 15:04:00 +0100 Subject: [PATCH 13/16] Removed features not used at the moment --- lib/db/mysql.js | 2 +- lib/db/sql_templates.json | 2 +- lib/handlers/user.js | 26 --------------- lib/models/user.js | 8 ++--- lib/routes.js | 15 --------- public/css/account.css | 3 +- public/js/chrome/errors.js | 2 +- public/js/chrome/navigation.js | 20 +----------- public/js/preferences-settings.js | 54 ++++++------------------------- views/index.html | 2 +- 10 files changed, 17 insertions(+), 117 deletions(-) diff --git a/lib/db/mysql.js b/lib/db/mysql.js index e57055af..cbc5fa75 100644 --- a/lib/db/mysql.js +++ b/lib/db/mysql.js @@ -541,7 +541,7 @@ module.exports = utils.inherit(Object, { updateOwnersData: updateMultipleFields(templates.updateOwnersData, templates.ownersColumns), saveBookmark: function (params, fn) { var sql = templates.saveBookmark; - this.connection.query(sql, [params.name, params.url, params.revision, params.type, params.description, new Date()], fn); + this.connection.query(sql, [params.name, params.url, params.revision, params.type, new Date()], fn); }, getBookmark: function (params, fn) { var sql = templates.getBookmark; diff --git a/lib/db/sql_templates.json b/lib/db/sql_templates.json index 53e7e5fe..49124065 100644 --- a/lib/db/sql_templates.json +++ b/lib/db/sql_templates.json @@ -46,7 +46,7 @@ "setBinVisibility": "UPDATE `owners` SET `visibility`=? WHERE `name`=? AND `url`=?", "getBinMetadata": "SELECT * FROM `owners` AS `o`, `ownership` AS `os` WHERE o.name=os.name AND o.url=? AND o.revision=?", "setProAccount": "UPDATE ownership SET `pro`=?, `updated`=? WHERE `name`=?", - "saveBookmark": "INSERT INTO owner_bookmarks (`name`, `url`, `revision`, `type`, `description`, `created`) VALUES (?,?,?,?,?,?)", + "saveBookmark": "INSERT INTO owner_bookmarks (`name`, `url`, `revision`, `type`, `created`) VALUES (?,?,?,?,?)", "getBookmark": "SELECT * FROM owner_bookmarks WHERE `name`=? AND `type`=? ORDER BY `created` DESC", "sandboxColumns": [ "created", diff --git a/lib/handlers/user.js b/lib/handlers/user.js index b74b303d..ae1575c0 100644 --- a/lib/handlers/user.js +++ b/lib/handlers/user.js @@ -57,32 +57,6 @@ module.exports = Observable.extend({ } }, - saveTemplateURL: function (req, res) { - userModel.saveBookmark(req.session.user, req.bin, 'template', function (err) { - if (err) { - return res.send(500, err); - } - res.send({ ok: true }); - }, 'default'); - }, - - loadTemplateURL: function (req, res, next) { - // userModel.getBookmark(user, 'template', function (err, data) { - // if (err || data.length === 0) { - // if (err) { - // console.error(err); - // } - // return res.redirect(req.app.get('url full')); - // } - - // req.params.rev = data[0].revision; - // req.params.bin = data[0].url; - - // req.params.quiet = 'quiet'; - // next(); - // }); - }, - validateRegister: function (req, res, next) { var username = req.param('username'); var email = req.param('email'); diff --git a/lib/models/user.js b/lib/models/user.js index d0ff1dcd..467af549 100644 --- a/lib/models/user.js +++ b/lib/models/user.js @@ -220,16 +220,12 @@ module.exports = Observable.extend({ }; this.store.updateOwners(params, fn); }, - saveBookmark: function (user, bin, type, fn, description) { - if (!description) { - description = ''; - } + saveBookmark: function (user, bin, type, fn) { var params = { name: user.name, url: bin.url, revision: bin.revision, - type: type, - description: description + type: type }; this.store.saveBookmark(params, fn); }, diff --git a/lib/routes.js b/lib/routes.js index 2554f724..ca40f985 100644 --- a/lib/routes.js +++ b/lib/routes.js @@ -355,21 +355,6 @@ module.exports = function (app) { next(); }, binHandler.createRevisionOrClone); - // Save as template - app.get('/save-as-template', binParamFromReferer, binHandler.loadBin, userHandler.saveTemplateURL); - app.post('/save-as-template', function (req, res, next) { - reBin.lastIndex = 0; // reset position - - // only allow cloning via url if it came from jsbin - var match = req.body.url.match(reBin) || []; - if (match.length) { - req.params.bin = match[1]; - req.params.rev = match[2]; - } - - next(); - }, binHandler.loadBin, userHandler.saveTemplateURL); - // Bin based urls diff --git a/public/css/account.css b/public/css/account.css index edb0a7ab..ffb1214f 100644 --- a/public/css/account.css +++ b/public/css/account.css @@ -93,8 +93,7 @@ select { min-width: 120px; } -form > div, -#jshintOptions div { +form > div { min-height: 32px; /* clear: left; */ overflow: hidden; diff --git a/public/js/chrome/errors.js b/public/js/chrome/errors.js index eb52af0e..d2905ca3 100644 --- a/public/js/chrome/errors.js +++ b/public/js/chrome/errors.js @@ -2,7 +2,7 @@ var jshint = function () { var source = editors.javascript.editor.getCode(); - var ok = JSHINT(source, jsbin.settings.jshintOption); + var ok = JSHINT(source); return ok ? true : JSHINT.data(); }; diff --git a/public/js/chrome/navigation.js b/public/js/chrome/navigation.js index 67a8e21f..d3b55338 100644 --- a/public/js/chrome/navigation.js +++ b/public/js/chrome/navigation.js @@ -17,25 +17,7 @@ var $startingpoint = $('a.startingpoint').click(function (event) { content: 'Saving templates isn\'t supported in this browser I\'m afraid. Sorry' }); } - - $.ajax({ - type: 'post', - url: this.href, - data: { url: jsbin.getURL() }, - success: function () { - $document.trigger('tip', { - type: 'notification', - content: 'Starting template updated and saved', - autohide: 3000 - }); - }, - error: function (xhr) { - $document.trigger('tip', { - type: 'error', - content: 'There was a problem creating the template. Can you try again or file a new issue?' - }); - } - }); + return false; }); // if (localStorage && localStorage['saved-html']) { diff --git a/public/js/preferences-settings.js b/public/js/preferences-settings.js index 8e35cfe4..0a0ab904 100644 --- a/public/js/preferences-settings.js +++ b/public/js/preferences-settings.js @@ -1,7 +1,7 @@ (function(){ 'use strict'; - /* global $, CodeMirror, jshint */ + /* global $ */ function getCurrentSettings(){ return JSON.parse(localStorage.settings || '{}') || { @@ -9,19 +9,6 @@ }; } - // window.jsbin = { - // 'settings': { - // 'jshintOption': null - // } - // }; - - // window.editors = { - // 'javascript': { - // 'editor': null, - // 'visible': true - // } - // }; - $.browser = {}; // work out the browser platform var ua = navigator.userAgent; @@ -41,8 +28,7 @@ panels: [], includejs: true, focusedPanel: 'html', - jshint: true//, - // jshintOptions: {} + jshint: true }; $.extend(currentSettings, getCurrentSettings()); var panels = ['html', 'css', 'javascript', 'console', 'live']; @@ -62,7 +48,6 @@ 'unused': 'When variable is defined but not used', 'curly': 'When blocks omit {}' }; - var $jshints = {}; var source = ''; for (var i = 0; i < panels.length; i++) { @@ -82,21 +67,6 @@ ''; } } - // $('#jshintOptions').append(source); - // for (var prop in jshints) { - // if (jshints.hasOwnProperty(prop)) { - // $jshints[prop] = $('#' + prop).prop('checked', currentSettings.jshintOptions[ prop ]); - // } - // } - - // var $textarea = $('#editor-settings-example'); - // editors.javascript.editor = CodeMirror.fromTextArea($textarea.get(0), $.extend({ - // mode: 'text/javascript' - // }, currentSettings.editor)); - - // editors.javascript.editor.getCode = function () { - // return editors.javascript.editor.getValue(); - // }; // Listeners $(':checkbox').on('change', saveSettings); @@ -120,19 +90,9 @@ localStorageSettings.includejs = $includejs.prop('checked'); localStorageSettings.focusedPanel = $focusedPanel.val(); - // localStorageSettings.jshintOptions = {}; - // for (var prop in jshints) { - // if (jshints.hasOwnProperty(prop)) { - // localStorageSettings.jshintOptions[ prop ] = $jshints[prop].prop('checked'); - // } - // } - localStorage.settings = JSON.stringify(localStorageSettings); console.log(localStorageSettings); - // window.jsbin.settings.jshintOption = localStorageSettings.jshintOptions; - // jshint(); - // Save on server $.ajax({ url: 'editor', @@ -143,10 +103,14 @@ _csrf: $csrf.val() }, success: function() { - // console.log('success'); + if (console && console.log) { + console.log('Success on saving settings'); + } }, - error: function() { - // console.log('there was an error saving'); + error: function(xhr, status) { + if (console && console.log) { + console.log('Error: ' + status); + } } }); } diff --git a/views/index.html b/views/index.html index fd00d266..5e4dbddc 100644 --- a/views/index.html +++ b/views/index.html @@ -51,7 +51,7 @@ {{/feature}} Export as gist Download - Save as template + Save as template How to embed From 12459136537f2b63f82897ecd6b03096be28fede Mon Sep 17 00:00:00 2001 From: Giulia Alfonsi Date: Thu, 10 Apr 2014 15:11:10 +0100 Subject: [PATCH 14/16] Activeline addon enabled by default --- public/js/editors/addons.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/public/js/editors/addons.js b/public/js/editors/addons.js index 89c63fa1..a723645e 100644 --- a/public/js/editors/addons.js +++ b/public/js/editors/addons.js @@ -10,7 +10,8 @@ trailingspace: false, fold: false, sublime: false, - activeline: false + tern: false, + activeline: true }; if (!jsbin.settings.addons) { From 872cf25aa13697c67b434fbf7d6970739afcafb4 Mon Sep 17 00:00:00 2001 From: Giulia Alfonsi Date: Thu, 10 Apr 2014 15:15:39 +0100 Subject: [PATCH 15/16] Moved account js files to its own folder --- public/js/{ => account}/account-settings.js | 0 public/js/{ => account}/editor-settings.js | 0 public/js/{ => account}/preferences-settings.js | 0 views/account/editor.html | 2 +- views/account/preferences.html | 2 +- views/account/profile.html | 2 +- 6 files changed, 3 insertions(+), 3 deletions(-) rename public/js/{ => account}/account-settings.js (100%) rename public/js/{ => account}/editor-settings.js (100%) rename public/js/{ => account}/preferences-settings.js (100%) diff --git a/public/js/account-settings.js b/public/js/account/account-settings.js similarity index 100% rename from public/js/account-settings.js rename to public/js/account/account-settings.js diff --git a/public/js/editor-settings.js b/public/js/account/editor-settings.js similarity index 100% rename from public/js/editor-settings.js rename to public/js/account/editor-settings.js diff --git a/public/js/preferences-settings.js b/public/js/account/preferences-settings.js similarity index 100% rename from public/js/preferences-settings.js rename to public/js/account/preferences-settings.js diff --git a/views/account/editor.html b/views/account/editor.html index ebf1f0fd..da145c76 100644 --- a/views/account/editor.html +++ b/views/account/editor.html @@ -174,6 +174,6 @@ - + {{#addons}}{{/addons}} diff --git a/views/account/preferences.html b/views/account/preferences.html index 7358d6b4..66d35c09 100644 --- a/views/account/preferences.html +++ b/views/account/preferences.html @@ -41,4 +41,4 @@ - \ 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 fa25fd4b..6b579144 100644 --- a/views/account/profile.html +++ b/views/account/profile.html @@ -27,4 +27,4 @@ - \ No newline at end of file + \ No newline at end of file From f9a8cefa4f8f099c8c6a8a55b75c1cdcbc4903f8 Mon Sep 17 00:00:00 2001 From: Giulia Alfonsi Date: Thu, 10 Apr 2014 15:31:49 +0100 Subject: [PATCH 16/16] UI tweaks --- public/css/account.css | 6 +++--- views/account/editor.html | 2 ++ views/account/preferences.html | 3 ++- views/partials/account_sidebar.html | 8 +++----- 4 files changed, 10 insertions(+), 9 deletions(-) diff --git a/public/css/account.css b/public/css/account.css index ffb1214f..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; diff --git a/views/account/editor.html b/views/account/editor.html index da145c76..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

diff --git a/views/account/preferences.html b/views/account/preferences.html index 66d35c09..581f19a8 100644 --- a/views/account/preferences.html +++ b/views/account/preferences.html @@ -4,7 +4,8 @@

Configure how JS Bin is set up when you create a new bin.

+ HTML content, processors selected, and more -->.
+ As soon as you make any changes, they will be automatically saved.

diff --git a/views/partials/account_sidebar.html b/views/partials/account_sidebar.html index 6505d605..d2811cc1 100644 --- a/views/partials/account_sidebar.html +++ b/views/partials/account_sidebar.html @@ -2,14 +2,12 @@