renames & refactors annotations.js into annotable.js

This commit is contained in:
kikito
2015-12-16 16:07:23 +01:00
parent 7996f5f816
commit f43248b174
5 changed files with 16035 additions and 28 deletions

View File

@@ -0,0 +1,20 @@
App.Annotable =
initialize: ->
$("[data-annotable-type]").each ->
$this = $(this)
ann_type = $this.data("annotable-type")
ann_id = $this.data("annotable-id")
ann_user_id = $this.data("annotable-user-id")
app = new annotator.App()
.include(annotator.ui.main, { element: this })
.include(annotator.storage.http, { prefix: "", urls: { search: "/annotations/search" } })
.include ->
beforeannotationCreated: (ann) ->
ann[ann_type + "_id"] = ann_id
ann.user_id = ann_user_id
app.start().then ->
options = {}
options[ann_type + "_id"] = ann_id
app.annotations.load(options)

View File

@@ -1,20 +0,0 @@
legislationSelector = ".annotate"
annotationsMetadata = ->
return {
beforeAnnotationCreated: (ann) ->
ann.legislation_id = $(legislationSelector).data("id");
ann.user_id = $(legislationSelector).data("user-id");
};
App.annotations =
initialize: ->
app = new annotator.App()
.include(annotator.ui.main, { element: $(legislationSelector)[0] })
.include(annotator.storage.http, { prefix: "", urls: { search: "/annotations/search" } })
.include(annotationsMetadata)
app.start()
.then( ->
app.annotations.load( { legislation_id: $(legislationSelector).data("id") } )
)

View File

@@ -29,11 +29,11 @@
//= require moderator_debates //= require moderator_debates
//= require moderator_proposals //= require moderator_proposals
//= require prevent_double_submission //= require prevent_double_submission
//= require annotator.min //= require annotator
//= require tags //= require tags
//= require users //= require users
//= require votes //= require votes
//= require annotations //= require annotable
var initialize_modules = function() { var initialize_modules = function() {
@@ -46,7 +46,7 @@ var initialize_modules = function() {
App.CheckAllNone.initialize(); App.CheckAllNone.initialize();
App.PreventDoubleSubmission.initialize(); App.PreventDoubleSubmission.initialize();
App.IeAlert.initialize(); App.IeAlert.initialize();
App.annotations.initialize(); App.Annotable.initialize();
}; };
$(function(){ $(function(){

View File

@@ -1,8 +1,6 @@
<% if current_user %> <section data-annotable-type="legislation"
<section class="annotate" data-id=<%= @legislation.id %> data-user-id=<%= current_user.id %>> data-annotable-id="<%= @legislation.id %>"
<% else %> data-annotable-user-id="<%= current_user.try(:id) %>">
<section>
<% end %>
<div><%= @legislation.title %></div> <div><%= @legislation.title %></div>
<div id="test"><%= @legislation.body %></div> <div id="test"><%= @legislation.body %></div>

16009
vendor/assets/javascripts/annotator.js vendored Normal file

File diff suppressed because one or more lines are too long