tolaria 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +66 -0
- data/.yardopts +4 -0
- data/CNAME +1 -0
- data/CONTRIBUTING.md +32 -0
- data/Gemfile +2 -0
- data/LICENSE.md +9 -0
- data/README.md +538 -0
- data/Rakefile +52 -0
- data/app/assets/fonts/admin/fontawesome.eot +0 -0
- data/app/assets/fonts/admin/fontawesome.svg +565 -0
- data/app/assets/fonts/admin/fontawesome.ttf +0 -0
- data/app/assets/fonts/admin/fontawesome.woff +0 -0
- data/app/assets/fonts/admin/fontawesome.woff2 +0 -0
- data/app/assets/images/admin/columbia_banner.png +0 -0
- data/app/assets/images/admin/favicon.ico +0 -0
- data/app/assets/images/admin/noise.png +0 -0
- data/app/assets/images/admin/select_arrows.svg +1 -0
- data/app/assets/javascripts/admin/admin.js +4 -0
- data/app/assets/javascripts/admin/base.js +12 -0
- data/app/assets/javascripts/admin/lib/backbone.js +1888 -0
- data/app/assets/javascripts/admin/lib/jquery.chosen.js +1272 -0
- data/app/assets/javascripts/admin/lib/jquery.js +10361 -0
- data/app/assets/javascripts/admin/lib/jquery.selection.js +352 -0
- data/app/assets/javascripts/admin/lib/moment.js +3103 -0
- data/app/assets/javascripts/admin/lib/no.js +6 -0
- data/app/assets/javascripts/admin/lib/underscore.js +1570 -0
- data/app/assets/javascripts/admin/models/composer_buttons.js +45 -0
- data/app/assets/javascripts/admin/models/rails_meta.js +4 -0
- data/app/assets/javascripts/admin/views/field_with_errors.js +19 -0
- data/app/assets/javascripts/admin/views/fields/attachment_field.js +32 -0
- data/app/assets/javascripts/admin/views/fields/has_many.js +64 -0
- data/app/assets/javascripts/admin/views/fields/image_association_select.js +31 -0
- data/app/assets/javascripts/admin/views/fields/markdown_composer.js +167 -0
- data/app/assets/javascripts/admin/views/fields/searchable_select.js +70 -0
- data/app/assets/javascripts/admin/views/fields/slug_field.js +38 -0
- data/app/assets/javascripts/admin/views/fields/swatch_field.js +55 -0
- data/app/assets/javascripts/admin/views/fields/timestamp_field.js +80 -0
- data/app/assets/javascripts/admin/views/flash_message.js +18 -0
- data/app/assets/javascripts/admin/views/form_orchestrator.js +41 -0
- data/app/assets/javascripts/admin/views/navigation.js +20 -0
- data/app/assets/javascripts/admin/views/resource_form.js +18 -0
- data/app/assets/javascripts/admin/views/search_form.js +20 -0
- data/app/assets/javascripts/admin/views/sessions.js +109 -0
- data/app/assets/javascripts/admin/views/virtual_form.js +47 -0
- data/app/assets/stylesheets/admin/_base.scss +5 -0
- data/app/assets/stylesheets/admin/_reset.scss +149 -0
- data/app/assets/stylesheets/admin/_root.scss +63 -0
- data/app/assets/stylesheets/admin/admin.scss +4 -0
- data/app/assets/stylesheets/admin/components/_blank_slate.scss +44 -0
- data/app/assets/stylesheets/admin/components/_buttons.scss +82 -0
- data/app/assets/stylesheets/admin/components/_flash_message.scss +64 -0
- data/app/assets/stylesheets/admin/components/_footer.scss +9 -0
- data/app/assets/stylesheets/admin/components/_header.scss +107 -0
- data/app/assets/stylesheets/admin/components/_index_table.scss +120 -0
- data/app/assets/stylesheets/admin/components/_main.scss +68 -0
- data/app/assets/stylesheets/admin/components/_markdown_body.scss +109 -0
- data/app/assets/stylesheets/admin/components/_navigation.scss +110 -0
- data/app/assets/stylesheets/admin/components/_pagination.scss +36 -0
- data/app/assets/stylesheets/admin/components/_pill.scss +11 -0
- data/app/assets/stylesheets/admin/components/_resource_form.scss +222 -0
- data/app/assets/stylesheets/admin/components/_search_form.scss +36 -0
- data/app/assets/stylesheets/admin/components/_sessions.scss +152 -0
- data/app/assets/stylesheets/admin/components/_show_table.scss +67 -0
- data/app/assets/stylesheets/admin/components/forms/_attachment_field.scss +59 -0
- data/app/assets/stylesheets/admin/components/forms/_chosen.scss +478 -0
- data/app/assets/stylesheets/admin/components/forms/_image_association_select.scss +20 -0
- data/app/assets/stylesheets/admin/components/forms/_markdown_composer.scss +149 -0
- data/app/assets/stylesheets/admin/components/forms/_nested_fields.scss +63 -0
- data/app/assets/stylesheets/admin/components/forms/_searchable_select.scss +8 -0
- data/app/assets/stylesheets/admin/components/forms/_slug_field.scss +20 -0
- data/app/assets/stylesheets/admin/components/forms/_swatch_field.scss +47 -0
- data/app/assets/stylesheets/admin/components/forms/_timestamp_field.scss +15 -0
- data/app/assets/stylesheets/admin/components/help_link.scss +6 -0
- data/app/assets/stylesheets/admin/mixins/_clearfix.scss +18 -0
- data/app/assets/stylesheets/admin/mixins/_min_max_width.scss +11 -0
- data/app/assets/stylesheets/admin/mixins/_rgbb.scss +7 -0
- data/app/assets/stylesheets/admin/mixins/_visuallyhidden.scss +33 -0
- data/app/assets/stylesheets/admin/settings/_animations.scss +21 -0
- data/app/assets/stylesheets/admin/settings/_breakpoints.scss +2 -0
- data/app/assets/stylesheets/admin/settings/_colors.scss +32 -0
- data/app/assets/stylesheets/admin/settings/_fonts.scss +31 -0
- data/app/assets/stylesheets/admin/settings/_icons.scss +1658 -0
- data/app/controllers/admin/admin_controller.rb +21 -0
- data/app/controllers/admin/sessions_controller.rb +112 -0
- data/app/controllers/tolaria/resource_controller.rb +132 -0
- data/app/controllers/tolaria/tolaria_controller.rb +40 -0
- data/app/helpers/admin/table_helper.rb +175 -0
- data/app/helpers/admin/view_helper.rb +76 -0
- data/app/mailers/passcode_mailer.rb +11 -0
- data/app/models/administrator.rb +146 -0
- data/app/views/admin/administrators/_form.html.erb +16 -0
- data/app/views/admin/administrators/_index.html.erb +20 -0
- data/app/views/admin/administrators/_search.html.erb +5 -0
- data/app/views/admin/administrators/_show.html.erb +14 -0
- data/app/views/admin/help/help_link.html.erb +16 -0
- data/app/views/admin/session/form.html.erb +52 -0
- data/app/views/admin/shared/_flash_messages.html.erb +42 -0
- data/app/views/admin/shared/_footer.html.erb +8 -0
- data/app/views/admin/shared/_head.html.erb +11 -0
- data/app/views/admin/shared/_header.html.erb +43 -0
- data/app/views/admin/shared/_navigation.html.erb +47 -0
- data/app/views/admin/shared/_skiplinks.html.erb +0 -0
- data/app/views/admin/shared/forms/_attachment_field.html.erb +17 -0
- data/app/views/admin/shared/forms/_has_many.html.erb +14 -0
- data/app/views/admin/shared/forms/_has_many_header.html.erb +19 -0
- data/app/views/admin/shared/forms/_image_association_select.html.erb +6 -0
- data/app/views/admin/shared/forms/_image_field.html.erb +19 -0
- data/app/views/admin/shared/forms/_markdown_composer.html.erb +29 -0
- data/app/views/admin/shared/forms/_searchable_select.html.erb +3 -0
- data/app/views/admin/shared/forms/_slug_field.html.erb +9 -0
- data/app/views/admin/shared/forms/_swatch_field.html.erb +4 -0
- data/app/views/admin/shared/forms/_timestamp_field.html.erb +19 -0
- data/app/views/admin/tolaria_resource/_form_buttons.html.erb +10 -0
- data/app/views/admin/tolaria_resource/_index_table.html.erb +73 -0
- data/app/views/admin/tolaria_resource/_search_form.html.erb +32 -0
- data/app/views/admin/tolaria_resource/_show_buttons.html.erb +13 -0
- data/app/views/admin/tolaria_resource/edit.html.erb +34 -0
- data/app/views/admin/tolaria_resource/index.html.erb +36 -0
- data/app/views/admin/tolaria_resource/new.html.erb +1 -0
- data/app/views/admin/tolaria_resource/show.html.erb +52 -0
- data/app/views/kaminari/admin/_first_page.html.erb +9 -0
- data/app/views/kaminari/admin/_last_page.html.erb +9 -0
- data/app/views/kaminari/admin/_next_page.html.erb +9 -0
- data/app/views/kaminari/admin/_page.html.erb +17 -0
- data/app/views/kaminari/admin/_paginator.html.erb +21 -0
- data/app/views/kaminari/admin/_prev_page.html.erb +9 -0
- data/app/views/layouts/admin/admin.html.erb +21 -0
- data/app/views/layouts/admin/sessions.html.erb +12 -0
- data/app/views/passcode_mailer/passcode.text.erb +5 -0
- data/lib/generators/tolaria/install/install_generator.rb +21 -0
- data/lib/generators/tolaria/install/templates/administrators_migration.rb +31 -0
- data/lib/generators/tolaria/install/templates/tolaria_initializer.rb +93 -0
- data/lib/tasks/admin.rake +32 -0
- data/lib/tolaria.rb +27 -0
- data/lib/tolaria/active_record.rb +55 -0
- data/lib/tolaria/admin.rb +4 -0
- data/lib/tolaria/categories.rb +21 -0
- data/lib/tolaria/config.rb +40 -0
- data/lib/tolaria/default_config.rb +74 -0
- data/lib/tolaria/engine.rb +23 -0
- data/lib/tolaria/form_buildable.rb +203 -0
- data/lib/tolaria/help_links.rb +78 -0
- data/lib/tolaria/introspection.rb +13 -0
- data/lib/tolaria/manage.rb +57 -0
- data/lib/tolaria/managed_class.rb +90 -0
- data/lib/tolaria/markdown.rb +28 -0
- data/lib/tolaria/random_tokens.rb +16 -0
- data/lib/tolaria/reload.rb +21 -0
- data/lib/tolaria/routes.rb +33 -0
- data/lib/tolaria/version.rb +13 -0
- data/test/demo/Rakefile +4 -0
- data/test/demo/app/assets/javascripts/application.js +1 -0
- data/test/demo/app/assets/stylesheets/application.scss +1 -0
- data/test/demo/app/controllers/application_controller.rb +5 -0
- data/test/demo/app/controllers/concerns/.keep +0 -0
- data/test/demo/app/controllers/homepage_controller.rb +4 -0
- data/test/demo/app/helpers/application_helper.rb +2 -0
- data/test/demo/app/mailers/.keep +0 -0
- data/test/demo/app/models/.keep +0 -0
- data/test/demo/app/models/blog_post.rb +43 -0
- data/test/demo/app/models/footnote.rb +5 -0
- data/test/demo/app/models/image.rb +19 -0
- data/test/demo/app/models/legal_page.rb +24 -0
- data/test/demo/app/models/miscellany.rb +12 -0
- data/test/demo/app/models/topic.rb +22 -0
- data/test/demo/app/models/video.rb +16 -0
- data/test/demo/app/views/admin/blog_posts/_form.html.erb +48 -0
- data/test/demo/app/views/admin/blog_posts/_search.html.erb +5 -0
- data/test/demo/app/views/admin/help/markdown-help.md +95 -0
- data/test/demo/app/views/admin/images/_form.html.erb +26 -0
- data/test/demo/app/views/admin/legal_pages/_form.html.erb +15 -0
- data/test/demo/app/views/admin/topics/_form.html.erb +3 -0
- data/test/demo/app/views/admin/videos/_form.html.erb +11 -0
- data/test/demo/app/views/homepage/homepage.html.erb +3 -0
- data/test/demo/app/views/layouts/application.html.erb +14 -0
- data/test/demo/bin/bundle +3 -0
- data/test/demo/bin/rails +4 -0
- data/test/demo/bin/rake +4 -0
- data/test/demo/bin/setup +29 -0
- data/test/demo/config.ru +4 -0
- data/test/demo/config/application.rb +26 -0
- data/test/demo/config/boot.rb +4 -0
- data/test/demo/config/database.yml +18 -0
- data/test/demo/config/environment.rb +3 -0
- data/test/demo/config/environments/development.rb +43 -0
- data/test/demo/config/environments/test.rb +44 -0
- data/test/demo/config/initializers/assets.rb +11 -0
- data/test/demo/config/initializers/cookies_serializer.rb +2 -0
- data/test/demo/config/initializers/filter_parameter_logging.rb +3 -0
- data/test/demo/config/initializers/inflections.rb +17 -0
- data/test/demo/config/initializers/markdown.rb +44 -0
- data/test/demo/config/initializers/secret_token.rb +2 -0
- data/test/demo/config/initializers/session_store.rb +2 -0
- data/test/demo/config/initializers/tolaria.rb +17 -0
- data/test/demo/config/initializers/wrap_parameters.rb +14 -0
- data/test/demo/config/routes.rb +4 -0
- data/test/demo/db/migrate/20150601202901_create_administrators.rb +31 -0
- data/test/demo/db/migrate/20150603204006_add_testing_models.rb +27 -0
- data/test/demo/db/migrate/20150609232013_create_footnotes.rb +10 -0
- data/test/demo/db/migrate/20150610135235_create_additional_demo_objects.rb +50 -0
- data/test/demo/db/schema.rb +112 -0
- data/test/demo/log/.keep +0 -0
- data/test/demo/public/404.html +67 -0
- data/test/demo/public/422.html +67 -0
- data/test/demo/public/500.html +66 -0
- data/test/demo/public/favicon.ico +0 -0
- data/test/integration/help_link_test.rb +73 -0
- data/test/integration/interface_test.rb +63 -0
- data/test/integration/router_test.rb +73 -0
- data/test/integration/session_test.rb +88 -0
- data/test/test_helper.rb +58 -0
- data/test/unit/configuration_test.rb +21 -0
- data/test/unit/managed_classes_test.rb +54 -0
- data/test/unit/markdown_test.rb +12 -0
- data/test/unit/menu_test.rb +32 -0
- data/test/unit/random_tokens_test.rb +13 -0
- data/tolaria.gemspec +35 -0
- metadata +499 -0
@@ -0,0 +1,45 @@
|
|
1
|
+
ComposerButtons = {
|
2
|
+
|
3
|
+
"header": {
|
4
|
+
vanilla: "# Header",
|
5
|
+
before: "# ",
|
6
|
+
after: ""
|
7
|
+
},
|
8
|
+
|
9
|
+
"em": {
|
10
|
+
vanilla: "*emphasized text*",
|
11
|
+
before: "*",
|
12
|
+
after: "*"
|
13
|
+
},
|
14
|
+
|
15
|
+
"strong": {
|
16
|
+
vanilla: "**strong text**",
|
17
|
+
before: "**",
|
18
|
+
after: "**"
|
19
|
+
},
|
20
|
+
|
21
|
+
"link": {
|
22
|
+
vanilla: "[link text](http://example.com/)",
|
23
|
+
before: "[",
|
24
|
+
after: "](http://example.com)"
|
25
|
+
},
|
26
|
+
|
27
|
+
"ordered-list": {
|
28
|
+
vanilla: "\n1. Numeric list",
|
29
|
+
before: "1. ",
|
30
|
+
after: ""
|
31
|
+
},
|
32
|
+
|
33
|
+
"unordered-list": {
|
34
|
+
vanilla: "\n- Bulleted list",
|
35
|
+
before: "- ",
|
36
|
+
after: ""
|
37
|
+
},
|
38
|
+
|
39
|
+
"blockquote": {
|
40
|
+
vanilla: "\n> quoted text",
|
41
|
+
before: "> ",
|
42
|
+
after: ""
|
43
|
+
}
|
44
|
+
|
45
|
+
}
|
@@ -0,0 +1,19 @@
|
|
1
|
+
var FieldWithErrorsView = Backbone.View.extend({
|
2
|
+
|
3
|
+
implode: function() {
|
4
|
+
this.$el.removeClass("field_with_errors");
|
5
|
+
this.unbind();
|
6
|
+
},
|
7
|
+
|
8
|
+
events: {
|
9
|
+
"input focus": "implode",
|
10
|
+
"select focus": "implode",
|
11
|
+
"textarea focus": "implode",
|
12
|
+
"click": "implode"
|
13
|
+
}
|
14
|
+
|
15
|
+
});
|
16
|
+
|
17
|
+
$(".field_with_errors").each(function() {
|
18
|
+
new FieldWithErrorsView({el:this});
|
19
|
+
});
|
@@ -0,0 +1,32 @@
|
|
1
|
+
var AttachmentFieldView = Backbone.View.extend({
|
2
|
+
|
3
|
+
initialize: function() {
|
4
|
+
this.$fileInput = this.$("input[type=file]");
|
5
|
+
this.$label = this.$(".attachment-field-label");
|
6
|
+
this.$icon = this.$(".icon");
|
7
|
+
this.$preview = this.$(".attachment-field-preview");
|
8
|
+
},
|
9
|
+
|
10
|
+
activateFileInput: function(event) {
|
11
|
+
event.preventDefault();
|
12
|
+
this.$fileInput.focus().click()
|
13
|
+
},
|
14
|
+
|
15
|
+
refreshLabel: function() {
|
16
|
+
if (!!this.$fileInput.val()) {
|
17
|
+
this.$label.html("Ready to upload");
|
18
|
+
this.$preview.hide();
|
19
|
+
this.$icon.show().removeClass("icon-file-text-o icon-paperclip").addClass("icon-check-circle-o");
|
20
|
+
this.$el.addClass("-ready");
|
21
|
+
}
|
22
|
+
},
|
23
|
+
|
24
|
+
events: {
|
25
|
+
"click button": "activateFileInput",
|
26
|
+
"change input": "refreshLabel"
|
27
|
+
}
|
28
|
+
|
29
|
+
});
|
30
|
+
|
31
|
+
FormOrchestrator.register(".attachment-field", "AttachmentFieldView");
|
32
|
+
|
@@ -0,0 +1,64 @@
|
|
1
|
+
var HasManyView = Backbone.View.extend({
|
2
|
+
|
3
|
+
initialize: function() {
|
4
|
+
this.$button = $(".has-many-create").first();
|
5
|
+
this.template = this.$button.data("template");
|
6
|
+
this.templateID = this.$button.data("id");
|
7
|
+
},
|
8
|
+
|
9
|
+
addFieldgroup: function(event) {
|
10
|
+
event.preventDefault();
|
11
|
+
// We need to make up a new array index
|
12
|
+
var time = new Date().getTime();
|
13
|
+
var regexp = new RegExp(this.templateID, "g");
|
14
|
+
// Duplicate the template into the form
|
15
|
+
var elements = $(this.template.replace(regexp, time));
|
16
|
+
// Initialize any Backbone Views by asking FormOrchestrator
|
17
|
+
FormOrchestrator.initializeViewsOver(elements);
|
18
|
+
this.$button.before(elements);
|
19
|
+
},
|
20
|
+
|
21
|
+
removeFieldgroup: function(event) {
|
22
|
+
|
23
|
+
event.preventDefault();
|
24
|
+
|
25
|
+
var $parentHeader = $(event.currentTarget).parents(".has-many-header").first();
|
26
|
+
var $fieldgroup = $parentHeader.nextUntil(".has-many-header, .has-many-create");
|
27
|
+
var $destroyInput = $fieldgroup.filter("input[name*='_destroy']").first()
|
28
|
+
|
29
|
+
if (!!$destroyInput.length) {
|
30
|
+
// The model is already persisted, set the destruction flag
|
31
|
+
// and present the undo button/confirmation.
|
32
|
+
$destroyInput.val("1");
|
33
|
+
$fieldgroup.filter(":not(.has-many-undo)").slideUp(150);
|
34
|
+
$fieldgroup.filter(".has-many-undo").first().slideDown(150);
|
35
|
+
}
|
36
|
+
else {
|
37
|
+
// This model wasn't persisted, just discard the form fields.
|
38
|
+
$fieldgroup.remove();
|
39
|
+
$parentHeader.remove();
|
40
|
+
}
|
41
|
+
|
42
|
+
},
|
43
|
+
|
44
|
+
restoreFieldgroup: function(event) {
|
45
|
+
|
46
|
+
var $undoControl = $(event.currentTarget)
|
47
|
+
var $fieldgroup = $undoControl.nextUntil(".has-many-header, .has-many-create");
|
48
|
+
var $destroyInput = $fieldgroup.filter("input[name*='_destroy']").first();
|
49
|
+
|
50
|
+
$destroyInput.val("0");
|
51
|
+
$fieldgroup.filter(":not(.has-many-header, .has-many-undo)").show();
|
52
|
+
$undoControl.hide();
|
53
|
+
|
54
|
+
},
|
55
|
+
|
56
|
+
events: {
|
57
|
+
"click .has-many-create": "addFieldgroup",
|
58
|
+
"click .has-many-group-remove": "removeFieldgroup",
|
59
|
+
"click .has-many-undo": "restoreFieldgroup",
|
60
|
+
}
|
61
|
+
|
62
|
+
});
|
63
|
+
|
64
|
+
FormOrchestrator.register(".has-many", "HasManyView");
|
@@ -0,0 +1,31 @@
|
|
1
|
+
var ImageAssociationSelectView = Backbone.View.extend({
|
2
|
+
|
3
|
+
initialize: function() {
|
4
|
+
this.$select = this.$el.find("select")
|
5
|
+
this.$previewImage = this.$el.find(".image-association-select-image");
|
6
|
+
this.hiddenClass = "-hidden";
|
7
|
+
|
8
|
+
if (this.$select.val() > 0) {
|
9
|
+
var src = this.$select.find(":selected").data("url");
|
10
|
+
this.$previewImage.removeClass(this.hiddenClass).attr("src", src);
|
11
|
+
}
|
12
|
+
},
|
13
|
+
|
14
|
+
events: {
|
15
|
+
"change select": "previewImage"
|
16
|
+
},
|
17
|
+
|
18
|
+
previewImage: function() {
|
19
|
+
var src = this.$select.find(":selected").data("url");
|
20
|
+
|
21
|
+
if (typeof src === "undefined"){
|
22
|
+
this.$previewImage.addClass(this.hiddenClass);
|
23
|
+
} else {
|
24
|
+
this.$previewImage.attr("src", src);
|
25
|
+
this.$previewImage.removeClass(this.hiddenClass);
|
26
|
+
}
|
27
|
+
}
|
28
|
+
|
29
|
+
});
|
30
|
+
|
31
|
+
FormOrchestrator.register(".image-association-select", "ImageAssociationSelectView");
|
@@ -0,0 +1,167 @@
|
|
1
|
+
var MarkdownComposerView = Backbone.View.extend({
|
2
|
+
|
3
|
+
fullscreen: false, // Currently expanded to fullscreen
|
4
|
+
livePreview: false, // The preview block is currently updating on keyup
|
5
|
+
|
6
|
+
initialize: function() {
|
7
|
+
this.$textarea = this.$("textarea");
|
8
|
+
this.$preview = this.$(".markdown-composer-preview");
|
9
|
+
this.$fullscreenButtonLabel = this.$(".-fullscreen-toggle span");
|
10
|
+
this.$fullscreenButtonIcon = this.$(".-fullscreen-toggle .icon");
|
11
|
+
},
|
12
|
+
|
13
|
+
// Brighten and highlight the composer UI
|
14
|
+
brightenSelf: function() {
|
15
|
+
this.$el.addClass("-focused");
|
16
|
+
},
|
17
|
+
|
18
|
+
// Dim the composer. Cannot be dimmed at fullscreen.
|
19
|
+
dimSelf: function() {
|
20
|
+
this.$el.removeClass("-focused");
|
21
|
+
},
|
22
|
+
|
23
|
+
toggleFullscreen: function(event) {
|
24
|
+
event.preventDefault();
|
25
|
+
if (!this.fullscreen) {
|
26
|
+
this.fullscreen = true;
|
27
|
+
this.livePreview = true;
|
28
|
+
this.updatePreview();
|
29
|
+
this.$preview.show();
|
30
|
+
this.$el.addClass("-fullscreen");
|
31
|
+
$("body").addClass("-modal-open");
|
32
|
+
this.$fullscreenButtonLabel.html("Close Fullscreen");
|
33
|
+
this.$fullscreenButtonIcon.removeClass("icon-arrows-alt").addClass("icon-compress");
|
34
|
+
this.$textarea.focus();
|
35
|
+
}
|
36
|
+
else {
|
37
|
+
this.fullscreen = false;
|
38
|
+
this.livePreview = false;
|
39
|
+
this.$preview.hide();
|
40
|
+
this.$el.removeClass("-fullscreen");
|
41
|
+
$("body").removeClass("-modal-open");
|
42
|
+
this.$fullscreenButtonLabel.html("Fullscreen");
|
43
|
+
this.$fullscreenButtonIcon.removeClass("icon-compress").addClass("icon-arrows-alt");
|
44
|
+
this.$textarea.focus();
|
45
|
+
}
|
46
|
+
},
|
47
|
+
|
48
|
+
// Update the preview on keyup if it is currently live-updating
|
49
|
+
keyupCallback: function() {
|
50
|
+
if (this.livePreview) {
|
51
|
+
this.updatePreview();
|
52
|
+
}
|
53
|
+
},
|
54
|
+
|
55
|
+
updatePreview: function() {
|
56
|
+
var trimmedDocument = $.trim(this.$textarea.val());
|
57
|
+
if (!trimmedDocument) {
|
58
|
+
this.presentErrorMessage("A preview of what you type will be shown here.");
|
59
|
+
return true;
|
60
|
+
}
|
61
|
+
this.renderMarkdown(trimmedDocument);
|
62
|
+
return true;
|
63
|
+
},
|
64
|
+
|
65
|
+
// Send the Markdown to the server for converting into HTML
|
66
|
+
|
67
|
+
renderMarkdown: function(markdownDocument) {
|
68
|
+
|
69
|
+
var self = this;
|
70
|
+
|
71
|
+
$.ajax({
|
72
|
+
|
73
|
+
type: "POST",
|
74
|
+
url: "/admin/api/markdown",
|
75
|
+
data: markdownDocument,
|
76
|
+
contentType: "text/plain",
|
77
|
+
|
78
|
+
beforeSend: function(xhr) {
|
79
|
+
xhr.setRequestHeader("X-CSRF-Token", RailsMeta.csrfToken);
|
80
|
+
},
|
81
|
+
|
82
|
+
dataType: "html",
|
83
|
+
processData: false,
|
84
|
+
|
85
|
+
statusCode: {
|
86
|
+
200: function(data, xstatus, xhr) {
|
87
|
+
self.$preview.html(data);
|
88
|
+
},
|
89
|
+
404: function(xhr, status, error) {
|
90
|
+
self.presentErrorMessage("The server refused to send you a preview. Please sign in and out of the admin panel and try again.");
|
91
|
+
},
|
92
|
+
500: function(xhr, status, error) {
|
93
|
+
self.presentErrorMessage("An unexpected server error occurred. Developers have been notified. Please try again\xA0later.")
|
94
|
+
}
|
95
|
+
},
|
96
|
+
|
97
|
+
timeout: 3000,
|
98
|
+
error: function(xhr, status, error) {
|
99
|
+
self.presentErrorMessage("Could not connect to the server. Please check your network connection and try\xA0again.");
|
100
|
+
}
|
101
|
+
|
102
|
+
});
|
103
|
+
|
104
|
+
},
|
105
|
+
|
106
|
+
// Act on a formatting button by either inserting the example
|
107
|
+
// syntax or wrapping the text selection in the chosen button's syntax
|
108
|
+
|
109
|
+
formatButton: function(event, mode) {
|
110
|
+
|
111
|
+
event.preventDefault();
|
112
|
+
|
113
|
+
var selectedText = this.$textarea.selection("get");
|
114
|
+
var buttonOps = ComposerButtons[mode];
|
115
|
+
|
116
|
+
if (selectedText.length > 0) {
|
117
|
+
// Wrap the selected text in the syntax
|
118
|
+
this.$textarea.selection("insert", {
|
119
|
+
mode: "before",
|
120
|
+
text: buttonOps.before,
|
121
|
+
caret: "keep"
|
122
|
+
});
|
123
|
+
this.$textarea.selection("insert", {
|
124
|
+
mode: "after",
|
125
|
+
text: buttonOps.after,
|
126
|
+
caret: "keep"
|
127
|
+
});
|
128
|
+
}
|
129
|
+
else {
|
130
|
+
// Insert some example text with the syntax
|
131
|
+
this.$textarea.selection("replace", {
|
132
|
+
text: buttonOps.vanilla,
|
133
|
+
caret: "keep"
|
134
|
+
});
|
135
|
+
}
|
136
|
+
|
137
|
+
this.updatePreview();
|
138
|
+
|
139
|
+
},
|
140
|
+
|
141
|
+
// Show an error message in the preview with dimmed text
|
142
|
+
presentErrorMessage: function(message) {
|
143
|
+
this.$preview.html("<p class='dim'>" + message + "</p>");
|
144
|
+
},
|
145
|
+
|
146
|
+
events: {
|
147
|
+
|
148
|
+
"keyup": "updatePreview",
|
149
|
+
"focus textarea": "brightenSelf",
|
150
|
+
"blur textarea": "dimSelf",
|
151
|
+
|
152
|
+
"click .-fullscreen-toggle": "toggleFullscreen",
|
153
|
+
|
154
|
+
// Formatting buttons
|
155
|
+
"click .-header": function(event) {this.formatButton(event, "header")},
|
156
|
+
"click .-em": function(event) {this.formatButton(event, "em")},
|
157
|
+
"click .-strong": function(event) {this.formatButton(event, "strong")},
|
158
|
+
"click .-link": function(event) {this.formatButton(event, "link")},
|
159
|
+
"click .-ordered-list": function(event) {this.formatButton(event, "ordered-list")},
|
160
|
+
"click .-unordered-list": function(event) {this.formatButton(event, "unordered-list")},
|
161
|
+
"click .-blockquote": function(event) {this.formatButton(event, "blockquote")}
|
162
|
+
|
163
|
+
}
|
164
|
+
|
165
|
+
});
|
166
|
+
|
167
|
+
FormOrchestrator.register(".markdown-composer", "MarkdownComposerView");
|
@@ -0,0 +1,70 @@
|
|
1
|
+
var SearchableSelectView = Backbone.View.extend({
|
2
|
+
|
3
|
+
// See http://harvesthq.github.io/chosen/options.html
|
4
|
+
// for help with these options
|
5
|
+
chosenOptions: {
|
6
|
+
allow_single_deselect: false,
|
7
|
+
disable_search: false,
|
8
|
+
disable_search_threshold: 5,
|
9
|
+
enable_split_word_search: true,
|
10
|
+
inherit_select_classes: true,
|
11
|
+
max_selected_options: Infinity,
|
12
|
+
no_results_text: "Nothing matched",
|
13
|
+
placeholder_text_multiple: "Select one or many",
|
14
|
+
placeholder_text_single: "Select one",
|
15
|
+
search_contains: true,
|
16
|
+
single_backstroke_delete: true,
|
17
|
+
display_disabled_options: true,
|
18
|
+
display_selected_options: true,
|
19
|
+
include_group_label_in_selected: false,
|
20
|
+
width: "100%"
|
21
|
+
},
|
22
|
+
|
23
|
+
// This function is stolen from Chosen.js because it does
|
24
|
+
// not expose any kind of API for communicating that it will not run
|
25
|
+
chosenSupported: function() {
|
26
|
+
if (window.navigator.appName === "Microsoft Internet Explorer") {
|
27
|
+
return document.documentMode >= 8;
|
28
|
+
}
|
29
|
+
if (/iP(od|hone)/i.test(window.navigator.userAgent)) {
|
30
|
+
return false;
|
31
|
+
}
|
32
|
+
if (/Android/i.test(window.navigator.userAgent)) {
|
33
|
+
if (/Mobile/i.test(window.navigator.userAgent)) {
|
34
|
+
return false;
|
35
|
+
}
|
36
|
+
}
|
37
|
+
return true;
|
38
|
+
},
|
39
|
+
|
40
|
+
initialize: function() {
|
41
|
+
|
42
|
+
var self = this;
|
43
|
+
|
44
|
+
if (self.chosenSupported()) {
|
45
|
+
|
46
|
+
self.$select = self.$("select");
|
47
|
+
var placeholderValue = self.$select.attr("placeholder");
|
48
|
+
|
49
|
+
if (!!placeholderValue) {
|
50
|
+
self.chosenOptions.placeholder_text_multiple = placeholderValue;
|
51
|
+
self.chosenOptions.placeholder_text_single = placeholderValue;
|
52
|
+
}
|
53
|
+
|
54
|
+
self.$select.on("chosen:ready", function(event) {
|
55
|
+
self.$el.attr("style","");
|
56
|
+
});
|
57
|
+
|
58
|
+
self.$select.chosen(self.chosenOptions);
|
59
|
+
|
60
|
+
}
|
61
|
+
else {
|
62
|
+
// Chosen isn't going to run
|
63
|
+
self.$el.attr("style","");
|
64
|
+
}
|
65
|
+
|
66
|
+
}
|
67
|
+
|
68
|
+
});
|
69
|
+
|
70
|
+
FormOrchestrator.register(".searchable-select", "SearchableSelectView");
|
@@ -0,0 +1,38 @@
|
|
1
|
+
var SlugFieldView = Backbone.View.extend({
|
2
|
+
|
3
|
+
initialize: function() {
|
4
|
+
this.$previewFragment = this.$(".slug-field-preview-fragment");
|
5
|
+
this.$input = this.$("input");
|
6
|
+
this.refreshPreview();
|
7
|
+
},
|
8
|
+
|
9
|
+
refreshPreview: function() {
|
10
|
+
|
11
|
+
var val = $.trim(this.$input.val())
|
12
|
+
|
13
|
+
if (!!val) {
|
14
|
+
this.$previewFragment.html(this.parameterize(val))
|
15
|
+
}
|
16
|
+
else {
|
17
|
+
this.$previewFragment.html("*")
|
18
|
+
}
|
19
|
+
|
20
|
+
},
|
21
|
+
|
22
|
+
seperatorRegex: /(?:[^a-z0-9\-_]+|-{2,}|\s{1,})/gi,
|
23
|
+
badSeperatorRegex: /^-|-$/,
|
24
|
+
|
25
|
+
parameterize: function(string) {
|
26
|
+
return string.replace(this.seperatorRegex, "-")
|
27
|
+
.replace(this.badSeperatorRegex, "")
|
28
|
+
.toLowerCase();
|
29
|
+
},
|
30
|
+
|
31
|
+
events: {
|
32
|
+
"keyup": "refreshPreview",
|
33
|
+
"change input": "refreshPreview"
|
34
|
+
}
|
35
|
+
|
36
|
+
});
|
37
|
+
|
38
|
+
FormOrchestrator.register(".slug-field", "SlugFieldView");
|