code_sync 0.6.7
Sign up to get free protection for your applications and to get access to all the features.
- data/.rvmrc +1 -0
- data/CNAME +1 -0
- data/Gemfile +24 -0
- data/Gemfile.lock +117 -0
- data/LICENSE.md +22 -0
- data/ROADMAP.md +20 -0
- data/TODO.md +14 -0
- data/bin/codesync +11 -0
- data/code_sync.gemspec +30 -0
- data/config/routes.rb +26 -0
- data/lib/assets/javascripts/canvas.coffee +12 -0
- data/lib/assets/javascripts/canvas/editors.coffee +48 -0
- data/lib/assets/javascripts/canvas/index.coffee +15 -0
- data/lib/assets/javascripts/canvas/layer_controller.coffee +47 -0
- data/lib/assets/javascripts/code_sync.coffee +3 -0
- data/lib/assets/javascripts/code_sync/backends/gist.coffee +78 -0
- data/lib/assets/javascripts/code_sync/client/index.coffee +104 -0
- data/lib/assets/javascripts/code_sync/client/util.coffee +61 -0
- data/lib/assets/javascripts/code_sync/codemirror.coffee +12 -0
- data/lib/assets/javascripts/code_sync/config.js.coffee.erb +38 -0
- data/lib/assets/javascripts/code_sync/console/index.coffee +54 -0
- data/lib/assets/javascripts/code_sync/console/templates/console.jst.skim +10 -0
- data/lib/assets/javascripts/code_sync/dependencies.coffee +6 -0
- data/lib/assets/javascripts/code_sync/editor/advanced.coffee +0 -0
- data/lib/assets/javascripts/code_sync/editor/datasources/document.coffee +212 -0
- data/lib/assets/javascripts/code_sync/editor/datasources/gist_loader.coffee +7 -0
- data/lib/assets/javascripts/code_sync/editor/datasources/modes.coffee +117 -0
- data/lib/assets/javascripts/code_sync/editor/datasources/project_assets.coffee +14 -0
- data/lib/assets/javascripts/code_sync/editor/index.coffee +415 -0
- data/lib/assets/javascripts/code_sync/editor/plugins/asset_selector.coffee +106 -0
- data/lib/assets/javascripts/code_sync/editor/plugins/color_picker.coffee +83 -0
- data/lib/assets/javascripts/code_sync/editor/plugins/document_manager.coffee +55 -0
- data/lib/assets/javascripts/code_sync/editor/plugins/document_tabs.coffee +178 -0
- data/lib/assets/javascripts/code_sync/editor/plugins/element_sync.coffee +111 -0
- data/lib/assets/javascripts/code_sync/editor/plugins/keymap_selector.coffee +44 -0
- data/lib/assets/javascripts/code_sync/editor/plugins/mode_selector.coffee +53 -0
- data/lib/assets/javascripts/code_sync/editor/plugins/name_input.coffee +44 -0
- data/lib/assets/javascripts/code_sync/editor/plugins/preferences.coffee +71 -0
- data/lib/assets/javascripts/code_sync/editor/templates/asset_editor.jst.skim +2 -0
- data/lib/assets/javascripts/code_sync/editor/templates/asset_selector.jst.skim +5 -0
- data/lib/assets/javascripts/code_sync/editor/templates/document_manager_tab.jst.skim +15 -0
- data/lib/assets/javascripts/code_sync/editor/templates/element_sync.jst.skim +19 -0
- data/lib/assets/javascripts/code_sync/editor/templates/preferences_panel.jst.skim +38 -0
- data/lib/assets/javascripts/code_sync/editor/views/asset_selector.coffee +106 -0
- data/lib/assets/javascripts/code_sync/editor/views/color_picker.coffee +76 -0
- data/lib/assets/javascripts/code_sync/editor/views/document_manager.coffee +176 -0
- data/lib/assets/javascripts/code_sync/editor/views/keymap_selector.coffee +37 -0
- data/lib/assets/javascripts/code_sync/editor/views/mode_selector.coffee +47 -0
- data/lib/assets/javascripts/code_sync/editor/views/name_input.coffee +44 -0
- data/lib/assets/javascripts/code_sync/editor/views/preferences.coffee +71 -0
- data/lib/assets/javascripts/code_sync/index.coffee +4 -0
- data/lib/assets/javascripts/code_sync/reloader.coffee +2 -0
- data/lib/assets/javascripts/code_sync_basic.coffee +1 -0
- data/lib/assets/javascripts/demos.coffee +48 -0
- data/lib/assets/javascripts/demos/default-content.coffee +72 -0
- data/lib/assets/javascripts/demos/layout_selector.coffee +19 -0
- data/lib/assets/javascripts/demos/tour.coffee +70 -0
- data/lib/assets/javascripts/demos/tour.jst.skim +29 -0
- data/lib/assets/javascripts/marketing.coffee +0 -0
- data/lib/assets/javascripts/vendor/.DS_Store +0 -0
- data/lib/assets/javascripts/vendor/backbone-events.js +160 -0
- data/lib/assets/javascripts/vendor/backbone-min.js +4 -0
- data/lib/assets/javascripts/vendor/codemirror-coffeescript.js +346 -0
- data/lib/assets/javascripts/vendor/codemirror-css.js +570 -0
- data/lib/assets/javascripts/vendor/codemirror-haml.js +153 -0
- data/lib/assets/javascripts/vendor/codemirror-htmlmixed.js +104 -0
- data/lib/assets/javascripts/vendor/codemirror-javascript.js +468 -0
- data/lib/assets/javascripts/vendor/codemirror-markdown.js +526 -0
- data/lib/assets/javascripts/vendor/codemirror-ruby.js +194 -0
- data/lib/assets/javascripts/vendor/codemirror-sass.js +330 -0
- data/lib/assets/javascripts/vendor/codemirror-skim.js +330 -0
- data/lib/assets/javascripts/vendor/codemirror-vim.js +3159 -0
- data/lib/assets/javascripts/vendor/codemirror-xml.js +328 -0
- data/lib/assets/javascripts/vendor/console.js +339 -0
- data/lib/assets/javascripts/vendor/gisted.js +27 -0
- data/lib/assets/javascripts/vendor/jquery-ui-resize-drag.min.js +6 -0
- data/lib/assets/javascripts/vendor/jquery.js +5 -0
- data/lib/assets/javascripts/vendor/keylauncher.js +4 -0
- data/lib/assets/javascripts/vendor/keymaster.min.js +4 -0
- data/lib/assets/javascripts/vendor/spectrum.js +1868 -0
- data/lib/assets/javascripts/vendor/underscore-min.js +1 -0
- data/lib/assets/javascripts/vendor/underscore.string.min.js +1 -0
- data/lib/assets/javascripts/vendor/vendored_codemirror.js +5558 -0
- data/lib/assets/javascripts/vendor/zepto.js +2 -0
- data/lib/assets/stylesheets/canvas.css.scss +101 -0
- data/lib/assets/stylesheets/code_sync.css.scss +4 -0
- data/lib/assets/stylesheets/code_sync/codemirror.css +7 -0
- data/lib/assets/stylesheets/code_sync/console.css +86 -0
- data/lib/assets/stylesheets/code_sync/editor/asset-name-input.css.scss +12 -0
- data/lib/assets/stylesheets/code_sync/editor/asset-selector.css.scss +58 -0
- data/lib/assets/stylesheets/code_sync/editor/codesync-color-picker.css.sass +5 -0
- data/lib/assets/stylesheets/code_sync/editor/document-tabs.css.scss +61 -0
- data/lib/assets/stylesheets/code_sync/editor/element-sync.css.scss +72 -0
- data/lib/assets/stylesheets/code_sync/editor/mode-selector.css.scss +0 -0
- data/lib/assets/stylesheets/code_sync/editor/preferences-panel.css.scss +26 -0
- data/lib/assets/stylesheets/code_sync/index.css.scss +141 -0
- data/lib/assets/stylesheets/demos.css.scss +96 -0
- data/lib/assets/stylesheets/marketing.css.sass +46 -0
- data/lib/assets/stylesheets/marketing/syntax.css.scss +1 -0
- data/lib/assets/stylesheets/vendor/animate.css +1 -0
- data/lib/assets/stylesheets/vendor/codemirror-ambiance.css +75 -0
- data/lib/assets/stylesheets/vendor/codemirror-lesserdark.css +44 -0
- data/lib/assets/stylesheets/vendor/codemirror-monokai.css +28 -0
- data/lib/assets/stylesheets/vendor/codemirror-xq-light.css +43 -0
- data/lib/assets/stylesheets/vendor/grid-layout.css +1406 -0
- data/lib/assets/stylesheets/vendor/spectrum.css +481 -0
- data/lib/assets/stylesheets/vendor/vendored_codemirror.css +246 -0
- data/lib/code_sync.rb +41 -0
- data/lib/code_sync/cli.rb +73 -0
- data/lib/code_sync/manager.rb +238 -0
- data/lib/code_sync/processors.rb +18 -0
- data/lib/code_sync/processors/basic.rb +9 -0
- data/lib/code_sync/processors/jst_processor.rb +17 -0
- data/lib/code_sync/pry_console.rb +132 -0
- data/lib/code_sync/rails.rb +7 -0
- data/lib/code_sync/rails/engine.rb +12 -0
- data/lib/code_sync/server.rb +225 -0
- data/lib/code_sync/sprockets_adapter.rb +145 -0
- data/lib/code_sync/temp_asset.rb +20 -0
- data/lib/code_sync/version.rb +3 -0
- data/lib/middleman_extension.rb +43 -0
- data/readme.md +26 -0
- data/site/.gitignore +14 -0
- data/site/Gemfile +13 -0
- data/site/Gemfile.lock +183 -0
- data/site/config.rb +26 -0
- data/site/source/canvas.html.slim +21 -0
- data/site/source/codepen-style-demo.html.slim +21 -0
- data/site/source/demo.html.slim +30 -0
- data/site/source/index.html.slim +128 -0
- data/site/source/layouts/layout.slim +18 -0
- data/site/source/samples/_client.html.md +13 -0
- data/site/source/samples/_editor.html.md +19 -0
- data/site/source/samples/_hooks.html.md +8 -0
- data/site/source/samples/_middleman.html.md +7 -0
- data/site/source/samples/_rails.html.md +8 -0
- data/site/source/samples/_standalone.html.md +36 -0
- data/spec/lib/code_sync/sprockets_adapter_spec.rb +44 -0
- data/spec/spec_helper.rb +21 -0
- data/spec/support/.DS_Store +0 -0
- data/spec/support/dummy_middleman/.gitignore +14 -0
- data/spec/support/dummy_middleman/Gemfile +5 -0
- data/spec/support/dummy_middleman/Gemfile.lock +100 -0
- data/spec/support/dummy_middleman/config.rb +77 -0
- data/spec/support/dummy_middleman/source/images/background.png +0 -0
- data/spec/support/dummy_middleman/source/images/middleman.png +0 -0
- data/spec/support/dummy_middleman/source/index.html.erb +10 -0
- data/spec/support/dummy_middleman/source/javascripts/all.js +1 -0
- data/spec/support/dummy_middleman/source/layouts/layout.erb +19 -0
- data/spec/support/dummy_middleman/source/stylesheets/all.css +55 -0
- data/spec/support/dummy_middleman/source/stylesheets/normalize.css +375 -0
- data/spec/support/dummy_rails/.gitignore +15 -0
- data/spec/support/dummy_rails/Gemfile +38 -0
- data/spec/support/dummy_rails/Gemfile.lock +112 -0
- data/spec/support/dummy_rails/README.rdoc +261 -0
- data/spec/support/dummy_rails/Rakefile +7 -0
- data/spec/support/dummy_rails/app/assets/images/rails.png +0 -0
- data/spec/support/dummy_rails/app/assets/javascripts/application.js +15 -0
- data/spec/support/dummy_rails/app/assets/stylesheets/application.css +13 -0
- data/spec/support/dummy_rails/app/controllers/application_controller.rb +3 -0
- data/spec/support/dummy_rails/app/helpers/application_helper.rb +2 -0
- data/spec/support/dummy_rails/app/mailers/.gitkeep +0 -0
- data/spec/support/dummy_rails/app/models/.gitkeep +0 -0
- data/spec/support/dummy_rails/app/views/layouts/application.html.erb +14 -0
- data/spec/support/dummy_rails/config.ru +4 -0
- data/spec/support/dummy_rails/config/application.rb +62 -0
- data/spec/support/dummy_rails/config/boot.rb +6 -0
- data/spec/support/dummy_rails/config/database.yml +25 -0
- data/spec/support/dummy_rails/config/environment.rb +5 -0
- data/spec/support/dummy_rails/config/environments/development.rb +37 -0
- data/spec/support/dummy_rails/config/environments/production.rb +67 -0
- data/spec/support/dummy_rails/config/environments/test.rb +37 -0
- data/spec/support/dummy_rails/config/initializers/backtrace_silencers.rb +7 -0
- data/spec/support/dummy_rails/config/initializers/inflections.rb +15 -0
- data/spec/support/dummy_rails/config/initializers/mime_types.rb +5 -0
- data/spec/support/dummy_rails/config/initializers/secret_token.rb +7 -0
- data/spec/support/dummy_rails/config/initializers/session_store.rb +8 -0
- data/spec/support/dummy_rails/config/initializers/wrap_parameters.rb +14 -0
- data/spec/support/dummy_rails/config/locales/en.yml +5 -0
- data/spec/support/dummy_rails/config/routes.rb +58 -0
- data/spec/support/dummy_rails/db/seeds.rb +7 -0
- data/spec/support/dummy_rails/doc/README_FOR_APP +2 -0
- data/spec/support/dummy_rails/lib/assets/.gitkeep +0 -0
- data/spec/support/dummy_rails/lib/tasks/.gitkeep +0 -0
- data/spec/support/dummy_rails/log/.gitkeep +0 -0
- data/spec/support/dummy_rails/public/404.html +26 -0
- data/spec/support/dummy_rails/public/422.html +26 -0
- data/spec/support/dummy_rails/public/500.html +25 -0
- data/spec/support/dummy_rails/public/favicon.ico +0 -0
- data/spec/support/dummy_rails/public/index.html +241 -0
- data/spec/support/dummy_rails/public/robots.txt +5 -0
- data/spec/support/dummy_rails/script/rails +6 -0
- data/spec/support/dummy_rails/test/fixtures/.gitkeep +0 -0
- data/spec/support/dummy_rails/test/functional/.gitkeep +0 -0
- data/spec/support/dummy_rails/test/integration/.gitkeep +0 -0
- data/spec/support/dummy_rails/test/performance/browsing_test.rb +12 -0
- data/spec/support/dummy_rails/test/test_helper.rb +13 -0
- data/spec/support/dummy_rails/test/unit/.gitkeep +0 -0
- data/spec/support/dummy_rails/vendor/assets/javascripts/.gitkeep +0 -0
- data/spec/support/dummy_rails/vendor/assets/stylesheets/.gitkeep +0 -0
- data/spec/support/dummy_rails/vendor/plugins/.gitkeep +0 -0
- data/spec/support/dummy_static/.DS_Store +0 -0
- data/spec/support/dummy_static/app/.DS_Store +0 -0
- data/spec/support/dummy_static/app/assets/.DS_Store +0 -0
- data/spec/support/dummy_static/app/assets/javascripts/manifest.coffee +4 -0
- data/spec/support/dummy_static/app/assets/javascripts/spec_application_javascript.coffee +4 -0
- data/spec/support/dummy_static/app/assets/stylesheets/spec_application_stylesheet.css.scss +5 -0
- data/spec/support/dummy_static/lib/assets/javascripts/spec_library_javascript.coffee +3 -0
- data/spec/support/dummy_static/lib/assets/stylesheets/spec_library_stylesheet.css.scss +5 -0
- data/spec/support/dummy_static/vendor/assets/javascripts/spec_vendor_javascript.js +5 -0
- data/spec/support/dummy_static/vendor/assets/stylesheets/spec_vendor_stylesheets.css +3 -0
- data/vendor/assets/stylesheets/code_sync.css +1 -0
- metadata +492 -0
@@ -0,0 +1,19 @@
|
|
1
|
+
window.LayoutSelector = Backbone.View.extend
|
2
|
+
id: "layout-selector"
|
3
|
+
tagName: "ul"
|
4
|
+
|
5
|
+
events:
|
6
|
+
"click .opt1": ()->
|
7
|
+
$('.editor-container').attr('data-layout','one')
|
8
|
+
|
9
|
+
"click .opt2": ()->
|
10
|
+
$('.editor-container').attr('data-layout','two')
|
11
|
+
|
12
|
+
"click .opt3": ()->
|
13
|
+
$('.editor-container').attr('data-layout','three')
|
14
|
+
|
15
|
+
render: ()->
|
16
|
+
for n in [1,2,3]
|
17
|
+
@$el.append "<li class='opt#{n}'>#{n}</li>"
|
18
|
+
|
19
|
+
@
|
@@ -0,0 +1,70 @@
|
|
1
|
+
CodeSync.tour =
|
2
|
+
step: 0
|
3
|
+
|
4
|
+
make = (tagName, attributes, content)->
|
5
|
+
el = document.createElement(tagName);
|
6
|
+
if (attributes)
|
7
|
+
Backbone.$(el).attr(attributes)
|
8
|
+
if (content != null)
|
9
|
+
Backbone.$(el).html(content)
|
10
|
+
|
11
|
+
el
|
12
|
+
|
13
|
+
showBubble = (content,position={})->
|
14
|
+
positionStyle = "position: absolute;"
|
15
|
+
|
16
|
+
for k,v of position when v?
|
17
|
+
v = "#{ v }px" unless "#{ v }".match(/px/)
|
18
|
+
positionStyle += "#{ k }:#{ v };"
|
19
|
+
|
20
|
+
bubble = make("div",{class:"bubble",style:positionStyle}, content)
|
21
|
+
|
22
|
+
$(".next", bubble).on "click", ()->
|
23
|
+
$('body .bubble').addClass('animated bounceOutRight')
|
24
|
+
CodeSync.startTour(next: true)
|
25
|
+
|
26
|
+
$('body').append(bubble)
|
27
|
+
|
28
|
+
$(bubble)
|
29
|
+
|
30
|
+
CodeSync.enableTour = ()->
|
31
|
+
$('.tour-button').off "click"
|
32
|
+
$('.tour-button').on "click", ()->
|
33
|
+
$(@).addClass("animated fadeOut")
|
34
|
+
CodeSync.startTour(restart:true)
|
35
|
+
|
36
|
+
CodeSync.startTour = (options={})->
|
37
|
+
if $('.codesync-tour-content').length is 0
|
38
|
+
$('body').append JST["demos/tour"]()
|
39
|
+
|
40
|
+
if options.restart is true
|
41
|
+
CodeSync.tour.step = 0
|
42
|
+
|
43
|
+
if options.next is true
|
44
|
+
CodeSync.tour.step = CodeSync.tour.step + 1
|
45
|
+
|
46
|
+
nextStep = CodeSync.tour.step
|
47
|
+
tourData = $(".codesync-tour-content .content[data-tour-step=#{ nextStep }]")
|
48
|
+
|
49
|
+
if tourData.length > 0
|
50
|
+
bubbleContent = tourData[0].outerHTML
|
51
|
+
|
52
|
+
orientation = tourData.data('position') || "below"
|
53
|
+
transition = if orientation is "below" then "bounceInDown" else "bounceInUp"
|
54
|
+
target = tourData.data('target')
|
55
|
+
|
56
|
+
if $(target).length > 0
|
57
|
+
currentPos = $(target).position()
|
58
|
+
if orientation is "below"
|
59
|
+
top = currentPos.top + $(target).height() + 25
|
60
|
+
left = currentPos.left + 80
|
61
|
+
else
|
62
|
+
bottom = "120px"
|
63
|
+
right = "15px"
|
64
|
+
else
|
65
|
+
top = "600px"
|
66
|
+
left = "600px"
|
67
|
+
|
68
|
+
bubbleElement = showBubble(bubbleContent,{top,left,bottom,right})
|
69
|
+
|
70
|
+
bubbleElement.addClass("animated #{ transition }")
|
@@ -0,0 +1,29 @@
|
|
1
|
+
.codesync-tour-content style="display: none"
|
2
|
+
.content data-tour-step="0" data-target="[data-codesync='panel-1']"
|
3
|
+
h4 SCSS Editor
|
4
|
+
p
|
5
|
+
| This is a SCSS editor. It allows you to use SCSS or SASS to write some CSS to style the contents of the page.
|
6
|
+
|
7
|
+
a.next Next
|
8
|
+
|
9
|
+
|
10
|
+
.content data-tour-step="1" data-target="[data-codesync='panel-2']"
|
11
|
+
h4 Skim Editor
|
12
|
+
p
|
13
|
+
| This is a Skim template editor. A CodeSync.onScriptChange hook is wired up so that whenever it changes, the contents will be rendered in the canvas below.
|
14
|
+
|
15
|
+
a.next Next
|
16
|
+
|
17
|
+
.content data-tour-step="2" data-target="[data-codesync='panel-3']"
|
18
|
+
h4 Coffeescript Editor
|
19
|
+
p
|
20
|
+
| This is a Coffeescript editor. The contents of your code will be evaluated and ran as you type.
|
21
|
+
|
22
|
+
a.next Next
|
23
|
+
|
24
|
+
.content data-tour-step="3" data-target="#layout-selector" data-position="above"
|
25
|
+
h4 Layout Selector
|
26
|
+
p
|
27
|
+
| This little widget will control the layout of the editors on this page.
|
28
|
+
|
29
|
+
a.next Cool Homie.
|
File without changes
|
Binary file
|
@@ -0,0 +1,160 @@
|
|
1
|
+
(function(){
|
2
|
+
// Backbone.Events
|
3
|
+
// ---------------
|
4
|
+
|
5
|
+
// Regular expression used to split event strings.
|
6
|
+
var eventSplitter = /\s+/;
|
7
|
+
|
8
|
+
// Implement fancy features of the Events API such as multiple event
|
9
|
+
// names `"change blur"` and jQuery-style event maps `{change: action}`
|
10
|
+
// in terms of the existing API.
|
11
|
+
var eventsApi = function(obj, action, name, rest) {
|
12
|
+
if (!name) return true;
|
13
|
+
if (typeof name === 'object') {
|
14
|
+
for (var key in name) {
|
15
|
+
obj[action].apply(obj, [key, name[key]].concat(rest));
|
16
|
+
}
|
17
|
+
} else if (eventSplitter.test(name)) {
|
18
|
+
var names = name.split(eventSplitter);
|
19
|
+
for (var i = 0, l = names.length; i < l; i++) {
|
20
|
+
obj[action].apply(obj, [names[i]].concat(rest));
|
21
|
+
}
|
22
|
+
} else {
|
23
|
+
return true;
|
24
|
+
}
|
25
|
+
};
|
26
|
+
|
27
|
+
// Optimized internal dispatch function for triggering events. Tries to
|
28
|
+
// keep the usual cases speedy (most Backbone events have 3 arguments).
|
29
|
+
var triggerEvents = function(events, args) {
|
30
|
+
var ev, i = -1, l = events.length;
|
31
|
+
switch (args.length) {
|
32
|
+
case 0: while (++i < l) (ev = events[i]).callback.call(ev.ctx);
|
33
|
+
return;
|
34
|
+
case 1: while (++i < l) (ev = events[i]).callback.call(ev.ctx, args[0]);
|
35
|
+
return;
|
36
|
+
case 2: while (++i < l) (ev = events[i]).callback.call(ev.ctx, args[0], args[1]);
|
37
|
+
return;
|
38
|
+
case 3: while (++i < l) (ev = events[i]).callback.call(ev.ctx, args[0], args[1], args[2]);
|
39
|
+
return;
|
40
|
+
default: while (++i < l) (ev = events[i]).callback.apply(ev.ctx, args);
|
41
|
+
}
|
42
|
+
};
|
43
|
+
|
44
|
+
// A module that can be mixed in to *any object* in order to provide it with
|
45
|
+
// custom events. You may bind with `on` or remove with `off` callback
|
46
|
+
// functions to an event; `trigger`-ing an event fires all callbacks in
|
47
|
+
// succession.
|
48
|
+
//
|
49
|
+
// var object = {};
|
50
|
+
// _.extend(object, Backbone.Events);
|
51
|
+
// object.on('expand', function(){ alert('expanded'); });
|
52
|
+
// object.trigger('expand');
|
53
|
+
//
|
54
|
+
var Events = {
|
55
|
+
|
56
|
+
// Bind one or more space separated events, or an events map,
|
57
|
+
// to a `callback` function. Passing `"all"` will bind the callback to
|
58
|
+
// all events fired.
|
59
|
+
on: function(name, callback, context) {
|
60
|
+
if (!(eventsApi(this, 'on', name, [callback, context]) && callback)) return this;
|
61
|
+
this._events || (this._events = {});
|
62
|
+
var list = this._events[name] || (this._events[name] = []);
|
63
|
+
list.push({callback: callback, context: context, ctx: context || this});
|
64
|
+
return this;
|
65
|
+
},
|
66
|
+
|
67
|
+
// Bind events to only be triggered a single time. After the first time
|
68
|
+
// the callback is invoked, it will be removed.
|
69
|
+
once: function(name, callback, context) {
|
70
|
+
if (!(eventsApi(this, 'once', name, [callback, context]) && callback)) return this;
|
71
|
+
var self = this;
|
72
|
+
var once = _.once(function() {
|
73
|
+
self.off(name, once);
|
74
|
+
callback.apply(this, arguments);
|
75
|
+
});
|
76
|
+
once._callback = callback;
|
77
|
+
this.on(name, once, context);
|
78
|
+
return this;
|
79
|
+
},
|
80
|
+
|
81
|
+
// Remove one or many callbacks. If `context` is null, removes all
|
82
|
+
// callbacks with that function. If `callback` is null, removes all
|
83
|
+
// callbacks for the event. If `name` is null, removes all bound
|
84
|
+
// callbacks for all events.
|
85
|
+
off: function(name, callback, context) {
|
86
|
+
var list, ev, events, names, i, l, j, k;
|
87
|
+
if (!this._events || !eventsApi(this, 'off', name, [callback, context])) return this;
|
88
|
+
if (!name && !callback && !context) {
|
89
|
+
this._events = {};
|
90
|
+
return this;
|
91
|
+
}
|
92
|
+
|
93
|
+
names = name ? [name] : _.keys(this._events);
|
94
|
+
for (i = 0, l = names.length; i < l; i++) {
|
95
|
+
name = names[i];
|
96
|
+
if (list = this._events[name]) {
|
97
|
+
events = [];
|
98
|
+
if (callback || context) {
|
99
|
+
for (j = 0, k = list.length; j < k; j++) {
|
100
|
+
ev = list[j];
|
101
|
+
if ((callback && callback !== ev.callback &&
|
102
|
+
callback !== ev.callback._callback) ||
|
103
|
+
(context && context !== ev.context)) {
|
104
|
+
events.push(ev);
|
105
|
+
}
|
106
|
+
}
|
107
|
+
}
|
108
|
+
this._events[name] = events;
|
109
|
+
}
|
110
|
+
}
|
111
|
+
|
112
|
+
return this;
|
113
|
+
},
|
114
|
+
|
115
|
+
// Trigger one or many events, firing all bound callbacks. Callbacks are
|
116
|
+
// passed the same arguments as `trigger` is, apart from the event name
|
117
|
+
// (unless you're listening on `"all"`, which will cause your callback to
|
118
|
+
// receive the true name of the event as the first argument).
|
119
|
+
trigger: function(name) {
|
120
|
+
if (!this._events) return this;
|
121
|
+
var args = slice.call(arguments, 1);
|
122
|
+
if (!eventsApi(this, 'trigger', name, args)) return this;
|
123
|
+
var events = this._events[name];
|
124
|
+
var allEvents = this._events.all;
|
125
|
+
if (events) triggerEvents(events, args);
|
126
|
+
if (allEvents) triggerEvents(allEvents, arguments);
|
127
|
+
return this;
|
128
|
+
},
|
129
|
+
|
130
|
+
// An inversion-of-control version of `on`. Tell *this* object to listen to
|
131
|
+
// an event in another object ... keeping track of what it's listening to.
|
132
|
+
listenTo: function(obj, name, callback) {
|
133
|
+
var listeners = this._listeners || (this._listeners = {});
|
134
|
+
var id = obj._listenerId || (obj._listenerId = _.uniqueId('l'));
|
135
|
+
listeners[id] = obj;
|
136
|
+
obj.on(name, typeof name === 'object' ? this : callback, this);
|
137
|
+
return this;
|
138
|
+
},
|
139
|
+
|
140
|
+
// Tell this object to stop listening to either specific events ... or
|
141
|
+
// to every object it's currently listening to.
|
142
|
+
stopListening: function(obj, name, callback) {
|
143
|
+
var listeners = this._listeners;
|
144
|
+
if (!listeners) return;
|
145
|
+
if (obj) {
|
146
|
+
obj.off(name, typeof name === 'object' ? this : callback, this);
|
147
|
+
if (!name && !callback) delete listeners[obj._listenerId];
|
148
|
+
} else {
|
149
|
+
if (typeof name === 'object') callback = this;
|
150
|
+
for (var id in listeners) {
|
151
|
+
listeners[id].off(name, callback, this);
|
152
|
+
}
|
153
|
+
this._listeners = {};
|
154
|
+
}
|
155
|
+
return this;
|
156
|
+
}
|
157
|
+
};
|
158
|
+
|
159
|
+
window.CodeSyncEvents = Events;
|
160
|
+
})();
|
@@ -0,0 +1,4 @@
|
|
1
|
+
(function(){var t=this;var e=t.Backbone;var i=[];var r=i.push;var s=i.slice;var n=i.splice;var a;if(typeof exports!=="undefined"){a=exports}else{a=t.Backbone={}}a.VERSION="1.0.0";var h=t._;if(!h&&typeof require!=="undefined")h=require("underscore");a.$=t.jQuery||t.Zepto||t.ender||t.$;a.noConflict=function(){t.Backbone=e;return this};a.emulateHTTP=false;a.emulateJSON=false;var o=a.Events={on:function(t,e,i){if(!l(this,"on",t,[e,i])||!e)return this;this._events||(this._events={});var r=this._events[t]||(this._events[t]=[]);r.push({callback:e,context:i,ctx:i||this});return this},once:function(t,e,i){if(!l(this,"once",t,[e,i])||!e)return this;var r=this;var s=h.once(function(){r.off(t,s);e.apply(this,arguments)});s._callback=e;return this.on(t,s,i)},off:function(t,e,i){var r,s,n,a,o,u,c,f;if(!this._events||!l(this,"off",t,[e,i]))return this;if(!t&&!e&&!i){this._events={};return this}a=t?[t]:h.keys(this._events);for(o=0,u=a.length;o<u;o++){t=a[o];if(n=this._events[t]){this._events[t]=r=[];if(e||i){for(c=0,f=n.length;c<f;c++){s=n[c];if(e&&e!==s.callback&&e!==s.callback._callback||i&&i!==s.context){r.push(s)}}}if(!r.length)delete this._events[t]}}return this},trigger:function(t){if(!this._events)return this;var e=s.call(arguments,1);if(!l(this,"trigger",t,e))return this;var i=this._events[t];var r=this._events.all;if(i)c(i,e);if(r)c(r,arguments);return this},stopListening:function(t,e,i){var r=this._listeners;if(!r)return this;var s=!e&&!i;if(typeof e==="object")i=this;if(t)(r={})[t._listenerId]=t;for(var n in r){r[n].off(e,i,this);if(s)delete this._listeners[n]}return this}};var u=/\s+/;var l=function(t,e,i,r){if(!i)return true;if(typeof i==="object"){for(var s in i){t[e].apply(t,[s,i[s]].concat(r))}return false}if(u.test(i)){var n=i.split(u);for(var a=0,h=n.length;a<h;a++){t[e].apply(t,[n[a]].concat(r))}return false}return true};var c=function(t,e){var i,r=-1,s=t.length,n=e[0],a=e[1],h=e[2];switch(e.length){case 0:while(++r<s)(i=t[r]).callback.call(i.ctx);return;case 1:while(++r<s)(i=t[r]).callback.call(i.ctx,n);return;case 2:while(++r<s)(i=t[r]).callback.call(i.ctx,n,a);return;case 3:while(++r<s)(i=t[r]).callback.call(i.ctx,n,a,h);return;default:while(++r<s)(i=t[r]).callback.apply(i.ctx,e)}};var f={listenTo:"on",listenToOnce:"once"};h.each(f,function(t,e){o[e]=function(e,i,r){var s=this._listeners||(this._listeners={});var n=e._listenerId||(e._listenerId=h.uniqueId("l"));s[n]=e;if(typeof i==="object")r=this;e[t](i,r,this);return this}});o.bind=o.on;o.unbind=o.off;h.extend(a,o);var d=a.Model=function(t,e){var i;var r=t||{};e||(e={});this.cid=h.uniqueId("c");this.attributes={};h.extend(this,h.pick(e,p));if(e.parse)r=this.parse(r,e)||{};if(i=h.result(this,"defaults")){r=h.defaults({},r,i)}this.set(r,e);this.changed={};this.initialize.apply(this,arguments)};var p=["url","urlRoot","collection"];h.extend(d.prototype,o,{changed:null,validationError:null,idAttribute:"id",initialize:function(){},toJSON:function(t){return h.clone(this.attributes)},sync:function(){return a.sync.apply(this,arguments)},get:function(t){return this.attributes[t]},escape:function(t){return h.escape(this.get(t))},has:function(t){return this.get(t)!=null},set:function(t,e,i){var r,s,n,a,o,u,l,c;if(t==null)return this;if(typeof t==="object"){s=t;i=e}else{(s={})[t]=e}i||(i={});if(!this._validate(s,i))return false;n=i.unset;o=i.silent;a=[];u=this._changing;this._changing=true;if(!u){this._previousAttributes=h.clone(this.attributes);this.changed={}}c=this.attributes,l=this._previousAttributes;if(this.idAttribute in s)this.id=s[this.idAttribute];for(r in s){e=s[r];if(!h.isEqual(c[r],e))a.push(r);if(!h.isEqual(l[r],e)){this.changed[r]=e}else{delete this.changed[r]}n?delete c[r]:c[r]=e}if(!o){if(a.length)this._pending=true;for(var f=0,d=a.length;f<d;f++){this.trigger("change:"+a[f],this,c[a[f]],i)}}if(u)return this;if(!o){while(this._pending){this._pending=false;this.trigger("change",this,i)}}this._pending=false;this._changing=false;return this},unset:function(t,e){return this.set(t,void 0,h.extend({},e,{unset:true}))},clear:function(t){var e={};for(var i in this.attributes)e[i]=void 0;return this.set(e,h.extend({},t,{unset:true}))},hasChanged:function(t){if(t==null)return!h.isEmpty(this.changed);return h.has(this.changed,t)},changedAttributes:function(t){if(!t)return this.hasChanged()?h.clone(this.changed):false;var e,i=false;var r=this._changing?this._previousAttributes:this.attributes;for(var s in t){if(h.isEqual(r[s],e=t[s]))continue;(i||(i={}))[s]=e}return i},previous:function(t){if(t==null||!this._previousAttributes)return null;return this._previousAttributes[t]},previousAttributes:function(){return h.clone(this._previousAttributes)},fetch:function(t){t=t?h.clone(t):{};if(t.parse===void 0)t.parse=true;var e=this;var i=t.success;t.success=function(r){if(!e.set(e.parse(r,t),t))return false;if(i)i(e,r,t);e.trigger("sync",e,r,t)};R(this,t);return this.sync("read",this,t)},save:function(t,e,i){var r,s,n,a=this.attributes;if(t==null||typeof t==="object"){r=t;i=e}else{(r={})[t]=e}if(r&&(!i||!i.wait)&&!this.set(r,i))return false;i=h.extend({validate:true},i);if(!this._validate(r,i))return false;if(r&&i.wait){this.attributes=h.extend({},a,r)}if(i.parse===void 0)i.parse=true;var o=this;var u=i.success;i.success=function(t){o.attributes=a;var e=o.parse(t,i);if(i.wait)e=h.extend(r||{},e);if(h.isObject(e)&&!o.set(e,i)){return false}if(u)u(o,t,i);o.trigger("sync",o,t,i)};R(this,i);s=this.isNew()?"create":i.patch?"patch":"update";if(s==="patch")i.attrs=r;n=this.sync(s,this,i);if(r&&i.wait)this.attributes=a;return n},destroy:function(t){t=t?h.clone(t):{};var e=this;var i=t.success;var r=function(){e.trigger("destroy",e,e.collection,t)};t.success=function(s){if(t.wait||e.isNew())r();if(i)i(e,s,t);if(!e.isNew())e.trigger("sync",e,s,t)};if(this.isNew()){t.success();return false}R(this,t);var s=this.sync("delete",this,t);if(!t.wait)r();return s},url:function(){var t=h.result(this,"urlRoot")||h.result(this.collection,"url")||U();if(this.isNew())return t;return t+(t.charAt(t.length-1)==="/"?"":"/")+encodeURIComponent(this.id)},parse:function(t,e){return t},clone:function(){return new this.constructor(this.attributes)},isNew:function(){return this.id==null},isValid:function(t){return this._validate({},h.extend(t||{},{validate:true}))},_validate:function(t,e){if(!e.validate||!this.validate)return true;t=h.extend({},this.attributes,t);var i=this.validationError=this.validate(t,e)||null;if(!i)return true;this.trigger("invalid",this,i,h.extend(e||{},{validationError:i}));return false}});var v=["keys","values","pairs","invert","pick","omit"];h.each(v,function(t){d.prototype[t]=function(){var e=s.call(arguments);e.unshift(this.attributes);return h[t].apply(h,e)}});var g=a.Collection=function(t,e){e||(e={});if(e.url)this.url=e.url;if(e.model)this.model=e.model;if(e.comparator!==void 0)this.comparator=e.comparator;this._reset();this.initialize.apply(this,arguments);if(t)this.reset(t,h.extend({silent:true},e))};var m={add:true,remove:true,merge:true};var y={add:true,merge:false,remove:false};h.extend(g.prototype,o,{model:d,initialize:function(){},toJSON:function(t){return this.map(function(e){return e.toJSON(t)})},sync:function(){return a.sync.apply(this,arguments)},add:function(t,e){return this.set(t,h.defaults(e||{},y))},remove:function(t,e){t=h.isArray(t)?t.slice():[t];e||(e={});var i,r,s,n;for(i=0,r=t.length;i<r;i++){n=this.get(t[i]);if(!n)continue;delete this._byId[n.id];delete this._byId[n.cid];s=this.indexOf(n);this.models.splice(s,1);this.length--;if(!e.silent){e.index=s;n.trigger("remove",n,this,e)}this._removeReference(n)}return this},set:function(t,e){e=h.defaults(e||{},m);if(e.parse)t=this.parse(t,e);if(!h.isArray(t))t=t?[t]:[];var i,s,a,o,u,l;var c=e.at;var f=this.comparator&&c==null&&e.sort!==false;var d=h.isString(this.comparator)?this.comparator:null;var p=[],v=[],g={};for(i=0,s=t.length;i<s;i++){if(!(a=this._prepareModel(t[i],e)))continue;if(u=this.get(a)){if(e.remove)g[u.cid]=true;if(e.merge){u.set(a.attributes,e);if(f&&!l&&u.hasChanged(d))l=true}}else if(e.add){p.push(a);a.on("all",this._onModelEvent,this);this._byId[a.cid]=a;if(a.id!=null)this._byId[a.id]=a}}if(e.remove){for(i=0,s=this.length;i<s;++i){if(!g[(a=this.models[i]).cid])v.push(a)}if(v.length)this.remove(v,e)}if(p.length){if(f)l=true;this.length+=p.length;if(c!=null){n.apply(this.models,[c,0].concat(p))}else{r.apply(this.models,p)}}if(l)this.sort({silent:true});if(e.silent)return this;for(i=0,s=p.length;i<s;i++){(a=p[i]).trigger("add",a,this,e)}if(l)this.trigger("sort",this,e);return this},reset:function(t,e){e||(e={});for(var i=0,r=this.models.length;i<r;i++){this._removeReference(this.models[i])}e.previousModels=this.models;this._reset();this.add(t,h.extend({silent:true},e));if(!e.silent)this.trigger("reset",this,e);return this},push:function(t,e){t=this._prepareModel(t,e);this.add(t,h.extend({at:this.length},e));return t},pop:function(t){var e=this.at(this.length-1);this.remove(e,t);return e},unshift:function(t,e){t=this._prepareModel(t,e);this.add(t,h.extend({at:0},e));return t},shift:function(t){var e=this.at(0);this.remove(e,t);return e},slice:function(t,e){return this.models.slice(t,e)},get:function(t){if(t==null)return void 0;return this._byId[t.id!=null?t.id:t.cid||t]},at:function(t){return this.models[t]},where:function(t,e){if(h.isEmpty(t))return e?void 0:[];return this[e?"find":"filter"](function(e){for(var i in t){if(t[i]!==e.get(i))return false}return true})},findWhere:function(t){return this.where(t,true)},sort:function(t){if(!this.comparator)throw new Error("Cannot sort a set without a comparator");t||(t={});if(h.isString(this.comparator)||this.comparator.length===1){this.models=this.sortBy(this.comparator,this)}else{this.models.sort(h.bind(this.comparator,this))}if(!t.silent)this.trigger("sort",this,t);return this},sortedIndex:function(t,e,i){e||(e=this.comparator);var r=h.isFunction(e)?e:function(t){return t.get(e)};return h.sortedIndex(this.models,t,r,i)},pluck:function(t){return h.invoke(this.models,"get",t)},fetch:function(t){t=t?h.clone(t):{};if(t.parse===void 0)t.parse=true;var e=t.success;var i=this;t.success=function(r){var s=t.reset?"reset":"set";i[s](r,t);if(e)e(i,r,t);i.trigger("sync",i,r,t)};R(this,t);return this.sync("read",this,t)},create:function(t,e){e=e?h.clone(e):{};if(!(t=this._prepareModel(t,e)))return false;if(!e.wait)this.add(t,e);var i=this;var r=e.success;e.success=function(s){if(e.wait)i.add(t,e);if(r)r(t,s,e)};t.save(null,e);return t},parse:function(t,e){return t},clone:function(){return new this.constructor(this.models)},_reset:function(){this.length=0;this.models=[];this._byId={}},_prepareModel:function(t,e){if(t instanceof d){if(!t.collection)t.collection=this;return t}e||(e={});e.collection=this;var i=new this.model(t,e);if(!i._validate(t,e)){this.trigger("invalid",this,t,e);return false}return i},_removeReference:function(t){if(this===t.collection)delete t.collection;t.off("all",this._onModelEvent,this)},_onModelEvent:function(t,e,i,r){if((t==="add"||t==="remove")&&i!==this)return;if(t==="destroy")this.remove(e,r);if(e&&t==="change:"+e.idAttribute){delete this._byId[e.previous(e.idAttribute)];if(e.id!=null)this._byId[e.id]=e}this.trigger.apply(this,arguments)}});var _=["forEach","each","map","collect","reduce","foldl","inject","reduceRight","foldr","find","detect","filter","select","reject","every","all","some","any","include","contains","invoke","max","min","toArray","size","first","head","take","initial","rest","tail","drop","last","without","indexOf","shuffle","lastIndexOf","isEmpty","chain"];h.each(_,function(t){g.prototype[t]=function(){var e=s.call(arguments);e.unshift(this.models);return h[t].apply(h,e)}});var w=["groupBy","countBy","sortBy"];h.each(w,function(t){g.prototype[t]=function(e,i){var r=h.isFunction(e)?e:function(t){return t.get(e)};return h[t](this.models,r,i)}});var b=a.View=function(t){this.cid=h.uniqueId("view");this._configure(t||{});this._ensureElement();this.initialize.apply(this,arguments);this.delegateEvents()};var x=/^(\S+)\s*(.*)$/;var E=["model","collection","el","id","attributes","className","tagName","events"];h.extend(b.prototype,o,{tagName:"div",$:function(t){return this.$el.find(t)},initialize:function(){},render:function(){return this},remove:function(){this.$el.remove();this.stopListening();return this},setElement:function(t,e){if(this.$el)this.undelegateEvents();this.$el=t instanceof a.$?t:a.$(t);this.el=this.$el[0];if(e!==false)this.delegateEvents();return this},delegateEvents:function(t){if(!(t||(t=h.result(this,"events"))))return this;this.undelegateEvents();for(var e in t){var i=t[e];if(!h.isFunction(i))i=this[t[e]];if(!i)continue;var r=e.match(x);var s=r[1],n=r[2];i=h.bind(i,this);s+=".delegateEvents"+this.cid;if(n===""){this.$el.on(s,i)}else{this.$el.on(s,n,i)}}return this},undelegateEvents:function(){this.$el.off(".delegateEvents"+this.cid);return this},_configure:function(t){if(this.options)t=h.extend({},h.result(this,"options"),t);h.extend(this,h.pick(t,E));this.options=t},_ensureElement:function(){if(!this.el){var t=h.extend({},h.result(this,"attributes"));if(this.id)t.id=h.result(this,"id");if(this.className)t["class"]=h.result(this,"className");var e=a.$("<"+h.result(this,"tagName")+">").attr(t);this.setElement(e,false)}else{this.setElement(h.result(this,"el"),false)}}});a.sync=function(t,e,i){var r=k[t];h.defaults(i||(i={}),{emulateHTTP:a.emulateHTTP,emulateJSON:a.emulateJSON});var s={type:r,dataType:"json"};if(!i.url){s.url=h.result(e,"url")||U()}if(i.data==null&&e&&(t==="create"||t==="update"||t==="patch")){s.contentType="application/json";s.data=JSON.stringify(i.attrs||e.toJSON(i))}if(i.emulateJSON){s.contentType="application/x-www-form-urlencoded";s.data=s.data?{model:s.data}:{}}if(i.emulateHTTP&&(r==="PUT"||r==="DELETE"||r==="PATCH")){s.type="POST";if(i.emulateJSON)s.data._method=r;var n=i.beforeSend;i.beforeSend=function(t){t.setRequestHeader("X-HTTP-Method-Override",r);if(n)return n.apply(this,arguments)}}if(s.type!=="GET"&&!i.emulateJSON){s.processData=false}if(s.type==="PATCH"&&window.ActiveXObject&&!(window.external&&window.external.msActiveXFilteringEnabled)){s.xhr=function(){return new ActiveXObject("Microsoft.XMLHTTP")}}var o=i.xhr=a.ajax(h.extend(s,i));e.trigger("request",e,o,i);return o};var k={create:"POST",update:"PUT",patch:"PATCH","delete":"DELETE",read:"GET"};a.ajax=function(){return a.$.ajax.apply(a.$,arguments)};var S=a.Router=function(t){t||(t={});if(t.routes)this.routes=t.routes;this._bindRoutes();this.initialize.apply(this,arguments)};var $=/\((.*?)\)/g;var T=/(\(\?)?:\w+/g;var H=/\*\w+/g;var A=/[\-{}\[\]+?.,\\\^$|#\s]/g;h.extend(S.prototype,o,{initialize:function(){},route:function(t,e,i){if(!h.isRegExp(t))t=this._routeToRegExp(t);if(h.isFunction(e)){i=e;e=""}if(!i)i=this[e];var r=this;a.history.route(t,function(s){var n=r._extractParameters(t,s);i&&i.apply(r,n);r.trigger.apply(r,["route:"+e].concat(n));r.trigger("route",e,n);a.history.trigger("route",r,e,n)});return this},navigate:function(t,e){a.history.navigate(t,e);return this},_bindRoutes:function(){if(!this.routes)return;this.routes=h.result(this,"routes");var t,e=h.keys(this.routes);while((t=e.pop())!=null){this.route(t,this.routes[t])}},_routeToRegExp:function(t){t=t.replace(A,"\\$&").replace($,"(?:$1)?").replace(T,function(t,e){return e?t:"([^/]+)"}).replace(H,"(.*?)");return new RegExp("^"+t+"$")},_extractParameters:function(t,e){var i=t.exec(e).slice(1);return h.map(i,function(t){return t?decodeURIComponent(t):null})}});var I=a.History=function(){this.handlers=[];h.bindAll(this,"checkUrl");if(typeof window!=="undefined"){this.location=window.location;this.history=window.history}};var N=/^[#\/]|\s+$/g;var P=/^\/+|\/+$/g;var O=/msie [\w.]+/;var C=/\/$/;I.started=false;h.extend(I.prototype,o,{interval:50,getHash:function(t){var e=(t||this).location.href.match(/#(.*)$/);return e?e[1]:""},getFragment:function(t,e){if(t==null){if(this._hasPushState||!this._wantsHashChange||e){t=this.location.pathname;var i=this.root.replace(C,"");if(!t.indexOf(i))t=t.substr(i.length)}else{t=this.getHash()}}return t.replace(N,"")},start:function(t){if(I.started)throw new Error("Backbone.history has already been started");I.started=true;this.options=h.extend({},{root:"/"},this.options,t);this.root=this.options.root;this._wantsHashChange=this.options.hashChange!==false;this._wantsPushState=!!this.options.pushState;this._hasPushState=!!(this.options.pushState&&this.history&&this.history.pushState);var e=this.getFragment();var i=document.documentMode;var r=O.exec(navigator.userAgent.toLowerCase())&&(!i||i<=7);this.root=("/"+this.root+"/").replace(P,"/");if(r&&this._wantsHashChange){this.iframe=a.$('<iframe src="javascript:0" tabindex="-1" />').hide().appendTo("body")[0].contentWindow;this.navigate(e)}if(this._hasPushState){a.$(window).on("popstate",this.checkUrl)}else if(this._wantsHashChange&&"onhashchange"in window&&!r){a.$(window).on("hashchange",this.checkUrl)}else if(this._wantsHashChange){this._checkUrlInterval=setInterval(this.checkUrl,this.interval)}this.fragment=e;var s=this.location;var n=s.pathname.replace(/[^\/]$/,"$&/")===this.root;if(this._wantsHashChange&&this._wantsPushState&&!this._hasPushState&&!n){this.fragment=this.getFragment(null,true);this.location.replace(this.root+this.location.search+"#"+this.fragment);return true}else if(this._wantsPushState&&this._hasPushState&&n&&s.hash){this.fragment=this.getHash().replace(N,"");this.history.replaceState({},document.title,this.root+this.fragment+s.search)}if(!this.options.silent)return this.loadUrl()},stop:function(){a.$(window).off("popstate",this.checkUrl).off("hashchange",this.checkUrl);clearInterval(this._checkUrlInterval);I.started=false},route:function(t,e){this.handlers.unshift({route:t,callback:e})},checkUrl:function(t){var e=this.getFragment();if(e===this.fragment&&this.iframe){e=this.getFragment(this.getHash(this.iframe))}if(e===this.fragment)return false;if(this.iframe)this.navigate(e);this.loadUrl()||this.loadUrl(this.getHash())},loadUrl:function(t){var e=this.fragment=this.getFragment(t);var i=h.any(this.handlers,function(t){if(t.route.test(e)){t.callback(e);return true}});return i},navigate:function(t,e){if(!I.started)return false;if(!e||e===true)e={trigger:e};t=this.getFragment(t||"");if(this.fragment===t)return;this.fragment=t;var i=this.root+t;if(this._hasPushState){this.history[e.replace?"replaceState":"pushState"]({},document.title,i)}else if(this._wantsHashChange){this._updateHash(this.location,t,e.replace);if(this.iframe&&t!==this.getFragment(this.getHash(this.iframe))){if(!e.replace)this.iframe.document.open().close();this._updateHash(this.iframe.location,t,e.replace)}}else{return this.location.assign(i)}if(e.trigger)this.loadUrl(t)},_updateHash:function(t,e,i){if(i){var r=t.href.replace(/(javascript:|#).*$/,"");t.replace(r+"#"+e)}else{t.hash="#"+e}}});a.history=new I;var j=function(t,e){var i=this;var r;if(t&&h.has(t,"constructor")){r=t.constructor}else{r=function(){return i.apply(this,arguments)}}h.extend(r,i,e);var s=function(){this.constructor=r};s.prototype=i.prototype;r.prototype=new s;if(t)h.extend(r.prototype,t);r.__super__=i.prototype;return r};d.extend=g.extend=S.extend=b.extend=I.extend=j;var U=function(){throw new Error('A "url" property or function must be specified')};var R=function(t,e){var i=e.error;e.error=function(r){if(i)i(t,r,e);t.trigger("error",t,r,e)}}}).call(this);
|
2
|
+
/*
|
3
|
+
//@ sourceMappingURL=backbone-min.map
|
4
|
+
*/
|
@@ -0,0 +1,346 @@
|
|
1
|
+
/**
|
2
|
+
* Link to the project's GitHub page:
|
3
|
+
* https://github.com/pickhardt/coffeescript-codemirror-mode
|
4
|
+
*/
|
5
|
+
CodeMirror.defineMode('coffeescript', function(conf) {
|
6
|
+
var ERRORCLASS = 'error';
|
7
|
+
|
8
|
+
function wordRegexp(words) {
|
9
|
+
return new RegExp("^((" + words.join(")|(") + "))\\b");
|
10
|
+
}
|
11
|
+
|
12
|
+
var singleOperators = new RegExp("^[\\+\\-\\*/%&|\\^~<>!\?]");
|
13
|
+
var singleDelimiters = new RegExp('^[\\(\\)\\[\\]\\{\\},:`=;\\.]');
|
14
|
+
var doubleOperators = new RegExp("^((\->)|(\=>)|(\\+\\+)|(\\+\\=)|(\\-\\-)|(\\-\\=)|(\\*\\*)|(\\*\\=)|(\\/\\/)|(\\/\\=)|(==)|(!=)|(<=)|(>=)|(<>)|(<<)|(>>)|(//))");
|
15
|
+
var doubleDelimiters = new RegExp("^((\\.\\.)|(\\+=)|(\\-=)|(\\*=)|(%=)|(/=)|(&=)|(\\|=)|(\\^=))");
|
16
|
+
var tripleDelimiters = new RegExp("^((\\.\\.\\.)|(//=)|(>>=)|(<<=)|(\\*\\*=))");
|
17
|
+
var identifiers = new RegExp("^[_A-Za-z$][_A-Za-z$0-9]*");
|
18
|
+
var properties = new RegExp("^(@|this\.)[_A-Za-z$][_A-Za-z$0-9]*");
|
19
|
+
|
20
|
+
var wordOperators = wordRegexp(['and', 'or', 'not',
|
21
|
+
'is', 'isnt', 'in',
|
22
|
+
'instanceof', 'typeof']);
|
23
|
+
var indentKeywords = ['for', 'while', 'loop', 'if', 'unless', 'else',
|
24
|
+
'switch', 'try', 'catch', 'finally', 'class'];
|
25
|
+
var commonKeywords = ['break', 'by', 'continue', 'debugger', 'delete',
|
26
|
+
'do', 'in', 'of', 'new', 'return', 'then',
|
27
|
+
'this', 'throw', 'when', 'until'];
|
28
|
+
|
29
|
+
var keywords = wordRegexp(indentKeywords.concat(commonKeywords));
|
30
|
+
|
31
|
+
indentKeywords = wordRegexp(indentKeywords);
|
32
|
+
|
33
|
+
|
34
|
+
var stringPrefixes = new RegExp("^('{3}|\"{3}|['\"])");
|
35
|
+
var regexPrefixes = new RegExp("^(/{3}|/)");
|
36
|
+
var commonConstants = ['Infinity', 'NaN', 'undefined', 'null', 'true', 'false', 'on', 'off', 'yes', 'no'];
|
37
|
+
var constants = wordRegexp(commonConstants);
|
38
|
+
|
39
|
+
// Tokenizers
|
40
|
+
function tokenBase(stream, state) {
|
41
|
+
// Handle scope changes
|
42
|
+
if (stream.sol()) {
|
43
|
+
var scopeOffset = state.scopes[0].offset;
|
44
|
+
if (stream.eatSpace()) {
|
45
|
+
var lineOffset = stream.indentation();
|
46
|
+
if (lineOffset > scopeOffset) {
|
47
|
+
return 'indent';
|
48
|
+
} else if (lineOffset < scopeOffset) {
|
49
|
+
return 'dedent';
|
50
|
+
}
|
51
|
+
return null;
|
52
|
+
} else {
|
53
|
+
if (scopeOffset > 0) {
|
54
|
+
dedent(stream, state);
|
55
|
+
}
|
56
|
+
}
|
57
|
+
}
|
58
|
+
if (stream.eatSpace()) {
|
59
|
+
return null;
|
60
|
+
}
|
61
|
+
|
62
|
+
var ch = stream.peek();
|
63
|
+
|
64
|
+
// Handle docco title comment (single line)
|
65
|
+
if (stream.match("####")) {
|
66
|
+
stream.skipToEnd();
|
67
|
+
return 'comment';
|
68
|
+
}
|
69
|
+
|
70
|
+
// Handle multi line comments
|
71
|
+
if (stream.match("###")) {
|
72
|
+
state.tokenize = longComment;
|
73
|
+
return state.tokenize(stream, state);
|
74
|
+
}
|
75
|
+
|
76
|
+
// Single line comment
|
77
|
+
if (ch === '#') {
|
78
|
+
stream.skipToEnd();
|
79
|
+
return 'comment';
|
80
|
+
}
|
81
|
+
|
82
|
+
// Handle number literals
|
83
|
+
if (stream.match(/^-?[0-9\.]/, false)) {
|
84
|
+
var floatLiteral = false;
|
85
|
+
// Floats
|
86
|
+
if (stream.match(/^-?\d*\.\d+(e[\+\-]?\d+)?/i)) {
|
87
|
+
floatLiteral = true;
|
88
|
+
}
|
89
|
+
if (stream.match(/^-?\d+\.\d*/)) {
|
90
|
+
floatLiteral = true;
|
91
|
+
}
|
92
|
+
if (stream.match(/^-?\.\d+/)) {
|
93
|
+
floatLiteral = true;
|
94
|
+
}
|
95
|
+
|
96
|
+
if (floatLiteral) {
|
97
|
+
// prevent from getting extra . on 1..
|
98
|
+
if (stream.peek() == "."){
|
99
|
+
stream.backUp(1);
|
100
|
+
}
|
101
|
+
return 'number';
|
102
|
+
}
|
103
|
+
// Integers
|
104
|
+
var intLiteral = false;
|
105
|
+
// Hex
|
106
|
+
if (stream.match(/^-?0x[0-9a-f]+/i)) {
|
107
|
+
intLiteral = true;
|
108
|
+
}
|
109
|
+
// Decimal
|
110
|
+
if (stream.match(/^-?[1-9]\d*(e[\+\-]?\d+)?/)) {
|
111
|
+
intLiteral = true;
|
112
|
+
}
|
113
|
+
// Zero by itself with no other piece of number.
|
114
|
+
if (stream.match(/^-?0(?![\dx])/i)) {
|
115
|
+
intLiteral = true;
|
116
|
+
}
|
117
|
+
if (intLiteral) {
|
118
|
+
return 'number';
|
119
|
+
}
|
120
|
+
}
|
121
|
+
|
122
|
+
// Handle strings
|
123
|
+
if (stream.match(stringPrefixes)) {
|
124
|
+
state.tokenize = tokenFactory(stream.current(), 'string');
|
125
|
+
return state.tokenize(stream, state);
|
126
|
+
}
|
127
|
+
// Handle regex literals
|
128
|
+
if (stream.match(regexPrefixes)) {
|
129
|
+
if (stream.current() != '/' || stream.match(/^.*\//, false)) { // prevent highlight of division
|
130
|
+
state.tokenize = tokenFactory(stream.current(), 'string-2');
|
131
|
+
return state.tokenize(stream, state);
|
132
|
+
} else {
|
133
|
+
stream.backUp(1);
|
134
|
+
}
|
135
|
+
}
|
136
|
+
|
137
|
+
// Handle operators and delimiters
|
138
|
+
if (stream.match(tripleDelimiters) || stream.match(doubleDelimiters)) {
|
139
|
+
return 'punctuation';
|
140
|
+
}
|
141
|
+
if (stream.match(doubleOperators)
|
142
|
+
|| stream.match(singleOperators)
|
143
|
+
|| stream.match(wordOperators)) {
|
144
|
+
return 'operator';
|
145
|
+
}
|
146
|
+
if (stream.match(singleDelimiters)) {
|
147
|
+
return 'punctuation';
|
148
|
+
}
|
149
|
+
|
150
|
+
if (stream.match(constants)) {
|
151
|
+
return 'atom';
|
152
|
+
}
|
153
|
+
|
154
|
+
if (stream.match(keywords)) {
|
155
|
+
return 'keyword';
|
156
|
+
}
|
157
|
+
|
158
|
+
if (stream.match(identifiers)) {
|
159
|
+
return 'variable';
|
160
|
+
}
|
161
|
+
|
162
|
+
if (stream.match(properties)) {
|
163
|
+
return 'property';
|
164
|
+
}
|
165
|
+
|
166
|
+
// Handle non-detected items
|
167
|
+
stream.next();
|
168
|
+
return ERRORCLASS;
|
169
|
+
}
|
170
|
+
|
171
|
+
function tokenFactory(delimiter, outclass) {
|
172
|
+
var singleline = delimiter.length == 1;
|
173
|
+
return function(stream, state) {
|
174
|
+
while (!stream.eol()) {
|
175
|
+
stream.eatWhile(/[^'"\/\\]/);
|
176
|
+
if (stream.eat('\\')) {
|
177
|
+
stream.next();
|
178
|
+
if (singleline && stream.eol()) {
|
179
|
+
return outclass;
|
180
|
+
}
|
181
|
+
} else if (stream.match(delimiter)) {
|
182
|
+
state.tokenize = tokenBase;
|
183
|
+
return outclass;
|
184
|
+
} else {
|
185
|
+
stream.eat(/['"\/]/);
|
186
|
+
}
|
187
|
+
}
|
188
|
+
if (singleline) {
|
189
|
+
if (conf.mode.singleLineStringErrors) {
|
190
|
+
outclass = ERRORCLASS;
|
191
|
+
} else {
|
192
|
+
state.tokenize = tokenBase;
|
193
|
+
}
|
194
|
+
}
|
195
|
+
return outclass;
|
196
|
+
};
|
197
|
+
}
|
198
|
+
|
199
|
+
function longComment(stream, state) {
|
200
|
+
while (!stream.eol()) {
|
201
|
+
stream.eatWhile(/[^#]/);
|
202
|
+
if (stream.match("###")) {
|
203
|
+
state.tokenize = tokenBase;
|
204
|
+
break;
|
205
|
+
}
|
206
|
+
stream.eatWhile("#");
|
207
|
+
}
|
208
|
+
return "comment";
|
209
|
+
}
|
210
|
+
|
211
|
+
function indent(stream, state, type) {
|
212
|
+
type = type || 'coffee';
|
213
|
+
var indentUnit = 0;
|
214
|
+
if (type === 'coffee') {
|
215
|
+
for (var i = 0; i < state.scopes.length; i++) {
|
216
|
+
if (state.scopes[i].type === 'coffee') {
|
217
|
+
indentUnit = state.scopes[i].offset + conf.indentUnit;
|
218
|
+
break;
|
219
|
+
}
|
220
|
+
}
|
221
|
+
} else {
|
222
|
+
indentUnit = stream.column() + stream.current().length;
|
223
|
+
}
|
224
|
+
state.scopes.unshift({
|
225
|
+
offset: indentUnit,
|
226
|
+
type: type
|
227
|
+
});
|
228
|
+
}
|
229
|
+
|
230
|
+
function dedent(stream, state) {
|
231
|
+
if (state.scopes.length == 1) return;
|
232
|
+
if (state.scopes[0].type === 'coffee') {
|
233
|
+
var _indent = stream.indentation();
|
234
|
+
var _indent_index = -1;
|
235
|
+
for (var i = 0; i < state.scopes.length; ++i) {
|
236
|
+
if (_indent === state.scopes[i].offset) {
|
237
|
+
_indent_index = i;
|
238
|
+
break;
|
239
|
+
}
|
240
|
+
}
|
241
|
+
if (_indent_index === -1) {
|
242
|
+
return true;
|
243
|
+
}
|
244
|
+
while (state.scopes[0].offset !== _indent) {
|
245
|
+
state.scopes.shift();
|
246
|
+
}
|
247
|
+
return false;
|
248
|
+
} else {
|
249
|
+
state.scopes.shift();
|
250
|
+
return false;
|
251
|
+
}
|
252
|
+
}
|
253
|
+
|
254
|
+
function tokenLexer(stream, state) {
|
255
|
+
var style = state.tokenize(stream, state);
|
256
|
+
var current = stream.current();
|
257
|
+
|
258
|
+
// Handle '.' connected identifiers
|
259
|
+
if (current === '.') {
|
260
|
+
style = state.tokenize(stream, state);
|
261
|
+
current = stream.current();
|
262
|
+
if (style === 'variable') {
|
263
|
+
return 'variable';
|
264
|
+
} else {
|
265
|
+
return ERRORCLASS;
|
266
|
+
}
|
267
|
+
}
|
268
|
+
|
269
|
+
// Handle scope changes.
|
270
|
+
if (current === 'return') {
|
271
|
+
state.dedent += 1;
|
272
|
+
}
|
273
|
+
if (((current === '->' || current === '=>') &&
|
274
|
+
!state.lambda &&
|
275
|
+
state.scopes[0].type == 'coffee' &&
|
276
|
+
stream.peek() === '')
|
277
|
+
|| style === 'indent') {
|
278
|
+
indent(stream, state);
|
279
|
+
}
|
280
|
+
var delimiter_index = '[({'.indexOf(current);
|
281
|
+
if (delimiter_index !== -1) {
|
282
|
+
indent(stream, state, '])}'.slice(delimiter_index, delimiter_index+1));
|
283
|
+
}
|
284
|
+
if (indentKeywords.exec(current)){
|
285
|
+
indent(stream, state);
|
286
|
+
}
|
287
|
+
if (current == 'then'){
|
288
|
+
dedent(stream, state);
|
289
|
+
}
|
290
|
+
|
291
|
+
|
292
|
+
if (style === 'dedent') {
|
293
|
+
if (dedent(stream, state)) {
|
294
|
+
return ERRORCLASS;
|
295
|
+
}
|
296
|
+
}
|
297
|
+
delimiter_index = '])}'.indexOf(current);
|
298
|
+
if (delimiter_index !== -1) {
|
299
|
+
if (dedent(stream, state)) {
|
300
|
+
return ERRORCLASS;
|
301
|
+
}
|
302
|
+
}
|
303
|
+
if (state.dedent > 0 && stream.eol() && state.scopes[0].type == 'coffee') {
|
304
|
+
if (state.scopes.length > 1) state.scopes.shift();
|
305
|
+
state.dedent -= 1;
|
306
|
+
}
|
307
|
+
|
308
|
+
return style;
|
309
|
+
}
|
310
|
+
|
311
|
+
var external = {
|
312
|
+
startState: function(basecolumn) {
|
313
|
+
return {
|
314
|
+
tokenize: tokenBase,
|
315
|
+
scopes: [{offset:basecolumn || 0, type:'coffee'}],
|
316
|
+
lastToken: null,
|
317
|
+
lambda: false,
|
318
|
+
dedent: 0
|
319
|
+
};
|
320
|
+
},
|
321
|
+
|
322
|
+
token: function(stream, state) {
|
323
|
+
var style = tokenLexer(stream, state);
|
324
|
+
|
325
|
+
state.lastToken = {style:style, content: stream.current()};
|
326
|
+
|
327
|
+
if (stream.eol() && stream.lambda) {
|
328
|
+
state.lambda = false;
|
329
|
+
}
|
330
|
+
|
331
|
+
return style;
|
332
|
+
},
|
333
|
+
|
334
|
+
indent: function(state) {
|
335
|
+
if (state.tokenize != tokenBase) {
|
336
|
+
return 0;
|
337
|
+
}
|
338
|
+
|
339
|
+
return state.scopes[0].offset;
|
340
|
+
}
|
341
|
+
|
342
|
+
};
|
343
|
+
return external;
|
344
|
+
});
|
345
|
+
|
346
|
+
CodeMirror.defineMIME('text/x-coffeescript', 'coffeescript');
|