Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Module metadata #22

Merged
merged 9 commits into from
Mar 3, 2014
1 change: 1 addition & 0 deletions scripts/configs/aloha.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ define ['jquery'], ($) ->
'oer/multipart'
'oer/copy'
'oer/cleanup'
'oer/metadata'
]

# This whole thing is what's needed to:
Expand Down
26 changes: 26 additions & 0 deletions scripts/views/workspace/content/content-edit.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,29 @@ define [

# **NOTE:** This template is not wrapped in an element
template: contentEditTemplate

initialize: () ->
Aloha.settings.plugins.metadata = Aloha.settings.plugins.metadata || {}
Aloha.settings.plugins.metadata.supplement = ''

Aloha.settings.plugins.metadata.setMetadata = (metadata) =>
@model.set('title', metadata.title, {triggeredByMetadata: true})
head = '<title>'+metadata.title+'</title>'
head += '<meta data-type="language" itemprop="inLanguage" content="'+metadata.language+ '" />'
@model.set('head', head)

Aloha.settings.plugins.metadata.filterMetadata = (metadata) =>
delete metadata.language if metadata.language
metadata

@listenTo @model, "change:title", (model, value, options) =>
Aloha.settings.plugins.metadata.extendMetadata({title: value}) if not options.triggeredByMetadata

@listenTo @model, "change:head", (model, value, options) =>
# sometimes there is no head. which is dumb.
if @model.get('head')
Aloha.settings.plugins.metadata.supplement = @model.get('head')
else
Aloha.settings.plugins.metadata.supplement = "<title>" + @model.get("title") + "</title>"

super()
4 changes: 4 additions & 0 deletions scripts/views/workspace/content/layouts/editor.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@ define [
@$el.parent().parent().parent().parent().find(
'#module-title-indicator').text(@model.get('title'))

@listenTo @model, "change:title", =>
@$el.parent().parent().parent().parent().find(
'#module-title-indicator').text(@model.get('title'))

# Focus the editor. This has to be done here, because @$el isn't attached
# to the DOM before this. We also have to wait until the content is
# loaded and the editor is actually activated.
Expand Down
2 changes: 1 addition & 1 deletion scripts/views/workspace/sidebar/toc-branch.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -277,6 +277,6 @@ define [
# TocPointerNodes which inherit their title if it is not overridden
title = prompt('Edit Title:', @model.toJSON().title)
if title and title != @model.toJSON().title
@model.set('title', title)
(@model.dereferencePointer?() or @model).set('title', title)

@renderModelOnly()