forked from timwis/vizwit
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request timwis#161 from timwis/editor
Live editor
- Loading branch information
Showing
16 changed files
with
214 additions
and
90 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
<!doctype html> | ||
<html> | ||
<head> | ||
<meta charset="utf-8"> | ||
<title>VizWit Editor</title> | ||
|
||
<link rel="stylesheet" href="//fonts.googleapis.com/css?family=Arimo:400,700,400italic"> | ||
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css"> | ||
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/font-awesome/4.4.0/css/font-awesome.min.css"> | ||
<link rel="stylesheet" href="https://cdn.datatables.net/1.10.9/css/dataTables.bootstrap.min.css"> | ||
<link rel="stylesheet" href="https://api.mapbox.com/mapbox.js/v2.2.1/mapbox.css"> | ||
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/backbone.modal/1.1.5/backbone.modal-min.css"> | ||
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/backbone.modal/1.1.5/backbone.modal.theme-min.css"> | ||
<link rel="stylesheet" href="styles/main.css"> | ||
<link rel="stylesheet" href="styles/editor.css"> | ||
</head> | ||
<body> | ||
<div class="row"> | ||
<div id="editor" class="split"></div> | ||
<div id="preview" class="split"> | ||
<div class="header-container"> | ||
<div class="container-fluid" id="page-header"></div> | ||
</div> | ||
|
||
<div class="container-fluid"> | ||
<div id="page-content"></div> | ||
</div> | ||
</div> | ||
</div> | ||
|
||
<script src="scripts/vizwit-editor.js"></script> | ||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
module.exports = { | ||
socrata: require('../collections/socrata') | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,88 +1,67 @@ | ||
/* global global */ | ||
var $ = global.jQuery = require('jquery') | ||
var _ = global._ = require('underscore') | ||
var $ = require('jquery') | ||
var _ = require('underscore') | ||
var Backbone = require('backbone') | ||
var deparam = require('node-jquery-deparam') | ||
require('gridstack/dist/gridstack') | ||
|
||
var Header = require('./views/header') | ||
var vizwit = require('./vizwit') | ||
var Gist = require('./collections/gist') | ||
|
||
var vent = _.clone(Backbone.Events) | ||
var fieldsCache = {} | ||
|
||
var params = window.location.search.substr(1) ? deparam(window.location.search.substr(1)) : {} | ||
module.exports = function (config, options) { | ||
options = options || {} | ||
if (!config.version || config.version !== '2') console.error('Wrong config version') | ||
|
||
// If no gist specified, redirect to homepage | ||
var redirect = function () { window.location.replace('http://vizwit.io') } | ||
if (!params.gist) { | ||
redirect() | ||
} | ||
|
||
// Fetch gist | ||
(new Gist(null, {id: params.gist})).fetch({ | ||
success: function (collection, response, options) { | ||
if (!collection.length) return console.error('No files in gist', params.gist) | ||
// Render header | ||
if (config.header) { | ||
var header = new Header(config.header) | ||
$(options.headerSelector).empty().append(header.render().el) | ||
|
||
// If a file was provided, use that one; otherwise use the first file in the gist | ||
var model = params.file && collection.get(params.file) ? collection.get(params.file) : collection.at(0) | ||
var config = JSON.parse(model.get('content')) | ||
// Update <title> tag | ||
if (config.header.title) { | ||
var originalTitle = $('title').text() | ||
$('title').text(config.header.title + ' - ' + originalTitle) | ||
} | ||
} | ||
|
||
if (!config.version || config.version !== '2') return redirect() | ||
var container = $(options.contentSelector) | ||
var heightInterval = 60 // from gridstack.js | ||
var current = {x: null, y: null} | ||
var row | ||
|
||
// Render header | ||
if (config.header) { | ||
var header = new Header(config.header) | ||
$('#page-header').append(header.render().el) | ||
container.empty() | ||
|
||
// Update <title> tag | ||
if (config.header.title) { | ||
var originalTitle = $('title').text() | ||
$('title').text(config.header.title + ' - ' + originalTitle) | ||
} | ||
config.cards.forEach(function (config) { | ||
// If y suggests we're on a new row (including the first item), create a new row | ||
if (config.y !== current.y) { | ||
row = $('<div class="row"></div>') | ||
container.append(row) | ||
current.y = config.y | ||
current.x = 0 | ||
} | ||
|
||
var container = $('#page-content') | ||
var heightInterval = 60 // from gridstack.js | ||
var current = {x: null, y: null} | ||
var row | ||
|
||
config.cards.forEach(function (config) { | ||
// If y suggests we're on a new row (including the first item), create a new row | ||
if (config.y !== current.y) { | ||
row = $('<div class="row"></div>') | ||
container.append(row) | ||
current.y = config.y | ||
current.x = 0 | ||
} | ||
var column = $('<div/>') | ||
|
||
var column = $('<div/>') | ||
// Add width class | ||
column.addClass('col-sm-' + config.width) | ||
|
||
// Add width class | ||
column.addClass('col-sm-' + config.width) | ||
|
||
// If x is not the same as our current x position, add offset class | ||
if (config.x !== current.x) { | ||
column.addClass('col-sm-offset-' + (config.x - current.x)) | ||
} | ||
// Set height of new div | ||
column.css('min-height', config.height * heightInterval) | ||
// If x is not the same as our current x position, add offset class | ||
if (config.x !== current.x) { | ||
column.addClass('col-sm-offset-' + (config.x - current.x)) | ||
} | ||
// Set height of new div | ||
column.css('min-height', config.height * heightInterval) | ||
|
||
// Increment current.x to new starting position | ||
current.x += config.width | ||
// Increment current.x to new starting position | ||
current.x += config.width | ||
|
||
// Add the div to the current row | ||
row.append(column) | ||
// Add the div to the current row | ||
row.append(column) | ||
|
||
// Initialize vizwit on new div | ||
vizwit.init(column, config.vizwit, { | ||
vent: vent, | ||
fieldsCache: fieldsCache | ||
}) | ||
// Initialize vizwit on new div | ||
vizwit.init(column, config.vizwit, { | ||
vent: vent, | ||
fieldsCache: fieldsCache | ||
}) | ||
}, | ||
error: function () { | ||
console.error('Error fetching gist', params.gist) | ||
} | ||
}) | ||
}) | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
var _ = require('underscore') | ||
var split = require('split.js') | ||
var ace = require('brace') | ||
;require('brace/mode/json') | ||
var layout = require('./layout') | ||
|
||
var sampleData = require('../data/sample.json') | ||
|
||
var layoutOptions = { | ||
headerSelector: '#page-header', | ||
contentSelector: '#page-content' | ||
} | ||
|
||
split(['#editor', '#preview'], {sizes: [40, 60]}) | ||
|
||
var editor = ace.edit('editor') | ||
var session = editor.getSession() | ||
session.setMode('ace/mode/json') | ||
editor.setValue(JSON.stringify(sampleData, null, 2), -1) | ||
|
||
var refresh = function () { | ||
var input = JSON.parse(editor.getValue()) | ||
layout(input, layoutOptions) | ||
} | ||
|
||
session.on('change', _.debounce(refresh, 300)) | ||
|
||
refresh() |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
var $ = require('jquery') | ||
var deparam = require('node-jquery-deparam') | ||
var Gist = require('./collections/gist') | ||
var layout = require('./layout') | ||
|
||
var params = window.location.search.substr(1) ? deparam(window.location.search.substr(1)) : {} | ||
var pathToFiles = 'data/' // should include trailing slash | ||
|
||
var layoutOptions = { | ||
headerSelector: '#page-header', | ||
contentSelector: '#page-content' | ||
} | ||
|
||
// If gist ID specified, fetch it using github's API | ||
if (params.gist) { | ||
(new Gist(null, {id: params.gist})).fetch({ | ||
success: function (collection, response, options) { | ||
if (!collection.length) return console.error('No files in gist', params.gist) | ||
|
||
// If a file was provided, use that one; otherwise use the first file in the gist | ||
var model = params.file && collection.get(params.file) ? collection.get(params.file) : collection.at(0) | ||
var config = JSON.parse(model.get('content')) | ||
|
||
layout(config, layoutOptions) | ||
}, | ||
error: function () { | ||
console.error('Error fetching gist', params.gist) | ||
} | ||
}) | ||
// If file specified, load it from the files directory | ||
} else if (params.file) { | ||
$.getJSON(pathToFiles + params.file, function (data) { | ||
layout(data, layoutOptions) | ||
}).fail(function () { | ||
console.error('Error loading file', params.file) | ||
}) | ||
// If no config specified, redirect to homepage | ||
} else { | ||
window.location.replace('http://vizwit.io') | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.