Browse files

l10n support, fixes #48

  • Loading branch information...
1 parent 39a6e8e commit 34a26637e488771626a884424fb833e879881825 @bergie committed Sep 18, 2012
View
1 Cakefile
@@ -23,6 +23,7 @@ mergeDirs = (k) ->
(sh "cp src/*.js merged/")
(sh "cp src/collectionWidgets/*.js merged/")
(sh "cp src/editingWidgets/*.js merged/")
+ (sh "cp locale/*.js merged/")
], k
task 'build', 'generate unified JavaScript file for whole Create', ->
View
9 examples/create-min.js
@@ -1,7 +1,2 @@
-// Create.js 1.0.0alpha3 - On-site web editing interface
-// (c) 2011-2012 Henri Bergius, IKS Consortium
-// Create may be freely distributed under the MIT license.
-// For all details and documentation:
-// http://createjs.org/
-(function(a,b){"use strict",a.widget("Midgard.midgardCreate",{options:{toolbar:"full",saveButton:null,state:"browse",highlight:!0,highlightColor:"#67cc08",editorWidgets:{"default":"hallo"},editorOptions:{hallo:{widget:"halloWidget"}},collectionWidgets:{"default":"midgardCollectionAdd"},url:function(){},storagePrefix:"node",workflows:{url:null},notifications:{},vie:null,stanbolUrl:null,dbPediaUrl:null,tags:!1,buttonContainer:".create-ui-toolbar-statustoolarea .create-ui-statustools",templates:{buttonContent:'<%= label %> <i class="icon-<%= icon %>"></i>',button:'<li id="<%= id %>"><a class="create-ui-btn"><%= buttonContent %></a></li>'}},_create:function(){this.vie=this._setupVIE(this.options);var a=this;window.setTimeout(function(){a._checkSession()},10),this._enableToolbar(),this._saveButton(),this._editButton(),this._prepareStorage(),this.element.midgardWorkflows&&this.element.midgardWorkflows(this.options.workflows),this.element.midgardNotifications&&this.element.midgardNotifications(this.options.notifications)},destroy:function(){this.element.midgardStorage("destroy"),this.element.midgardToolbar("destroy"),a("[about]",this.element).each(function(){a(this).midgardEditable("destroy")}),this.element.midgardWorkflows&&this.element.midgardWorkflows("destroy"),this.element.midgardNotifications&&this.element.midgardNotifications("destroy"),this.options.tags&&this.element.midgardTags("destroy"),a.Widget.prototype.destroy.call(this)},_setupVIE:function(a){var b;return a.vie?b=a.vie:b=new VIE,b.hasService("rdfa")||b.use(new b.RdfaService),!b.hasService("stanbol")&&a.stanbolUrl&&b.use(new b.StanbolService({proxyDisabled:!0,url:a.stanbolUrl})),!b.hasService("dbpedia")&&a.dbPediaUrl&&b.use(new b.DBPediaService({proxyDisabled:!0,url:a.dbPediaUrl})),b},_prepareStorage:function(){this.element.midgardStorage({vie:this.vie,url:this.options.url});var b=this;this.element.bind("midgardstoragesave",function(){a("#midgardcreate-save a").html(_.template(b.options.templates.buttonContent,{label:"Saving",icon:"upload"}))}),this.element.bind("midgardstoragesaved midgardstorageerror",function(){a("#midgardcreate-save a").html(_.template(b.options.templates.buttonContent,{label:"Save",icon:"ok"}))})},_init:function(){this.setState(this.options.state)},setState:function(a){this._setOption("state",a),a==="edit"?this._enableEdit():this._disableEdit(),this._setEditButtonState(a)},setToolbar:function(a){this.options.toolbar=a,this.element.midgardToolbar("setDisplay",a)},showNotification:function(a){if(this.element.midgardNotifications)return this.element.midgardNotifications("create",a)},configureEditor:function(a,b,c){this.options.editorOptions[a]={widget:b,options:c}},setEditorForContentType:function(a,c){if(this.options.editorOptions[c]===b&&c!==null)throw new Error("No editor "+c+" configured");this.options.editorWidgets[a]=c},setEditorForProperty:function(a,c){if(this.options.editorOptions[c]===b&&c!==null)throw new Error("No editor "+c+" configured");this.options.editorWidgets[a]=c},_checkSession:function(){if(!window.sessionStorage)return;var a=this.options.storagePrefix+"Midgard.create.toolbar";window.sessionStorage.getItem(a)&&this.setToolbar(window.sessionStorage.getItem(a));var b=this.options.storagePrefix+"Midgard.create.state";window.sessionStorage.getItem(b)&&this.setState(window.sessionStorage.getItem(b)),this.element.bind("midgardcreatestatechange",function(a,c){window.sessionStorage.setItem(b,c.state)})},_saveButton:function(){return this.options.saveButton?this.options.saveButton:(a(this.options.buttonContainer,this.element).append(a(_.template(this.options.templates.button,{id:"midgardcreate-save",buttonContent:_.template(this.options.templates.buttonContent,{label:"Save",icon:"ok"})}))),this.options.saveButton=a("#midgardcreate-save",this.element),this.options.saveButton.hide(),this.options.saveButton)},_editButton:function(){var b=this;a(this.options.buttonContainer,this.element).append(a(_.template(this.options.templates.button,{id:"midgardcreate-edit",buttonContent:""}))),a("#midgardcreate-edit",this.element).bind("click",function(){if(b.options.state==="edit"){b.setState("browse");return}b.setState("edit")})},_setEditButtonState:function(b){var c={edit:_.template(this.options.templates.buttonContent,{label:"Cancel",icon:"remove"}),browse:_.template(this.options.templates.buttonContent,{label:"Edit",icon:"edit"})},d=a("#midgardcreate-edit a",this.element);if(!d)return;b==="edit"&&d.addClass("selected"),d.html(c[b])},_enableToolbar:function(){var a=this;this.element.bind("midgardtoolbarstatechange",function(b,c){a.setToolbar(c.display),window.sessionStorage&&window.sessionStorage.setItem(a.options.storagePrefix+"Midgard.create.toolbar",c.display)}),this.element.midgardToolbar({display:this.options.toolbar,vie:this.vie})},_enableEdit:function(){this._setOption("state","edit");var b=this,c={toolbarState:b.options.toolbar,disabled:!1,vie:b.vie,widgets:b.options.editorWidgets,editors:b.options.editorOptions,collectionWidgets:b.options.collectionWidgets};b.options.enableEditor&&(c.enableEditor=b.options.enableEditor),b.options.disableEditor&&(c.disableEditor=b.options.disableEditor),a("[about]",this.element).each(function(){var d=this;if(b.options.highlight){var e=function(c,e){if(!a(e.element).is(":visible"))return;if(e.entityElement.get(0)!==d)return;e.element.stop(!0,!0),e.element.effect("highlight",{color:b.options.highlightColor},3e3)};a(this).bind("midgardeditableenableproperty",e)}a(this).bind("midgardeditabledisable",function(){a(this).unbind("midgardeditableenableproperty",e)}),b.options.tags&&a(this).bind("midgardeditableenable",function(c,e){if(c.target!==d)return;a(this).midgardTags({vie:b.vie,entityElement:e.entityElement,entity:e.instance})}),a(this).midgardEditable(c)}),this._trigger("statechange",null,{state:"edit"})},_disableEdit:function(){var b=this,c={disabled:!0,vie:b.vie,editorOptions:b.options.editorOptions};a("[about]",this.element).each(function(){a(this).midgardEditable(c),a(this).removeClass("ui-state-disabled")}),this._setOption("state","browse"),this._trigger("statechange",null,{state:"browse"})}})})(jQuery),function(a,b){"use strict",a.widget("Midgard.midgardCollectionAdd",{options:{editingWidgets:null,collection:null,model:null,definition:null,view:null,disabled:!1,vie:null,editableOptions:null,templates:{button:'<button class="btn"><i class="icon-<%= icon %>"></i> <%= label %></button>'}},_create:function(){this.addButtons=[];var a=this;if(!a.options.collection.localStorage)try{a.options.collection.url=a.options.model.url()}catch(b){window.console&&console.log(b)}a.options.collection.bind("add",function(b){b.primaryCollection=a.options.collection,a.options.vie.entities.add(b),b.collection=a.options.collection}),a.options.collection.bind("add remove reset",a.checkCollectionConstraints,a),a._bindCollectionView(a.options.view)},_bindCollectionView:function(a){var b=this;a.bind("add",function(a){a.$el.effect("slide",function(){b._makeEditable(a)})})},_makeEditable:function(a){this.options.editableOptions.disabled=this.options.disabled,this.options.editableOptions.model=a.model,a.$el.midgardEditable(this.options.editableOptions)},_init:function(){if(this.options.disabled){this.disable();return}this.enable()},hideButtons:function(){_.each(this.addButtons,function(a){a.hide()})},showButtons:function(){_.each(this.addButtons,function(a){a.show()})},checkCollectionConstraints:function(){if(this.options.disabled)return;if(!this.options.view.canAdd()){this.hideButtons();return}if(!this.options.definition){this.showButtons();return}if(!this.options.definition.max||this.options.definition.max===-1){this.showButtons();return}if(this.options.collection.length<this.options.definition.max){this.showButtons();return}this.hideButtons()},enable:function(){var b=this,c=a(_.template(this.options.templates.button,{icon:"plus",label:"Add"})).button();c.addClass("midgard-create-add"),c.click(function(){b.addItem(c)}),a(b.options.view.el).after(c),b.addButtons.push(c),b.checkCollectionConstraints()},disable:function(){_.each(this.addButtons,function(a){a.remove()}),this.addButtons=[]},_getTypeActions:function(a){var b=this,c=[];return _.each(this.options.definition.range,function(d){var e=b.options.collection.vie.namespaces.uri(d);if(!b.options.view.canAdd(e))return;c.push({name:d,label:d,cb:function(){b.options.collection.add({"@type":d},a)},className:"create-ui-btn"})}),c},addItem:function(b,c){var d={};if(this.options.definition&&this.options.definition.range){if(this.options.definition.range.length!==1){a("body").midgardNotifications("create",{bindTo:b,gravity:"L",body:"Choose type to add",timeout:0,actions:this._getTypeActions(c)});return}d["@type"]=this.options.definition.range[0]}this.options.collection.add({},c)}})}(jQuery),function(a,b){"use strict",a.widget("Midgard.midgardCollectionAddBetween",a.Midgard.midgardCollectionAdd,{_bindCollectionView:function(a){var b=this;a.bind("add",function(a){b._makeEditable(a),b._refreshButtons()}),a.bind("remove",function(){b._refreshButtons()})},_refreshButtons:function(){var a=this;window.setTimeout(function(){a.disable(),a.enable()},1)},prepareButton:function(b){var c=this,d=a(_.template(this.options.templates.button,{icon:"plus",label:""})).button();return d.addClass("midgard-create-add"),d.click(function(){c.addItem(d,{at:b})}),d},enable:function(){var b=this,c=b.prepareButton(0);a(b.options.view.el).prepend(c),b.addButtons.push(c),a.each(b.options.view.entityViews,function(c,d){var e=b.options.collection.indexOf(d.model),f=b.prepareButton(e+1);a(d.el).append(f),b.addButtons.push(f)}),this.checkCollectionConstraints()},disable:function(){var b=this;a.each(b.addButtons,function(a,b){b.remove()}),b.addButtons=[]}})}(jQuery),function(a,b){"use strict",a.widget("Midgard.midgardEditable",{options:{editables:[],collections:[],model:null,editors:{hallo:{widget:"halloWidget",options:{}}},widgets:{"default":"hallo"},collectionWidgets:{"default":"midgardCollectionAdd"},toolbarState:"full",vie:null,disabled:!1},_create:function(){this.vie=this.options.vie;if(!this.options.model){var a=this;this.vie.load({element:this.element}).from("rdfa").execute().done(function(b){a.options.model=b[0]})}},_init:function(){if(this.options.disabled){this.disable();return}this.enable()},findEditableElements:function(b){this.vie.service("rdfa").findPredicateElements(this.options.model.id,a("[property]",this.element),!1).each(b)},enable:function(){var b=this;if(!this.options.model)return;this.findEditableElements(function(){return b._enableProperty(a(this))}),this._trigger("enable",null,{instance:this.options.model,entityElement:this.element});if(!this.vie.services.rdfa)return;_.each(this.vie.service("rdfa").views,function(a){if(a instanceof b.vie.view.Collection&&b.options.model===a.owner){var c=a.collection.predicate,d=b.enableCollection({model:b.options.model,collection:a.collection,property:c,definition:b.getAttributeDefinition(c),view:a,element:a.el,vie:b.vie,editableOptions:b.options});b.options.collections.push(d)}})},disable:function(){var b=this;a.each(this.options.editables,function(c,d){b.disableEditor({widget:b,editable:d,entity:b.options.model,element:a(this)})}),this.options.editables=[],a.each(this.options.collections,function(a,c){b.disableCollection({widget:b,model:b.options.model,element:c,vie:b.vie,editableOptions:b.options})}),this.options.collections=[],this._trigger("disable",null,{instance:this.options.model,entityElement:this.element})},getElementPredicate:function(a){return this.vie.service("rdfa").getElementPredicate(a)},_enableProperty:function(a){var b=this,c=this.getElementPredicate(a);if(!c)return!0;if(this.options.model.get(c)instanceof Array)return!0;var d=this.enableEditor({widget:this,element:a,entity:this.options.model,property:c,vie:this.vie,modified:function(d){var e={};e[c]=d,b.options.model.set(e,{silent:!0}),b._trigger("changed",null,{property:c,instance:b.options.model,element:a,entityElement:b.element})},activated:function(){b._trigger("activated",null,{property:c,instance:b.options.model,element:a,entityElement:b.element})},deactivated:function(){b._trigger("deactivated",null,{property:c,instance:b.options.model,element:a,entityElement:b.element})}});d&&this._trigger("enableproperty",null,{editable:d,property:c,instance:this.options.model,element:a,entityElement:this.element}),this.options.editables.push(d)},_editorName:function(a){if(this.options.widgets[a.property]!==b)return this.options.widgets[a.property];var c="default",d=this.getAttributeDefinition(a.property);return d&&(c=d.range[0]),this.options.widgets[c]!==b?this.options.widgets[c]:this.options.widgets["default"]},_editorWidget:function(a){return this.options.editors[a].widget},_editorOptions:function(a){return this.options.editors[a].options},getAttributeDefinition:function(a){var b=this.options.model.get("@type");if(!b)return;if(!b.attributes)return;return b.attributes.get(a)},enableEditor:function(b){var c=this._editorName(b);if(c===null)return;var d=this._editorWidget(c);b.editorOptions=this._editorOptions(c),b.toolbarState=this.options.toolbarState,b.disabled=!1;if(typeof a(b.element)[d]!="function")throw new Error(d+" widget is not available");return a(b.element)[d](b),a(b.element).data("createWidgetName",d),a(b.element)},disableEditor:function(b){var c=a(b.element).data("createWidgetName");b.disabled=!0,c&&(a(b.element)[c](b),a(b.element).removeClass("ui-state-disabled"))},collectionWidgetName:function(a){if(this.options.collectionWidgets[a.property]!==b)return this.options.collectionWidgets[a.property];var c="default",d=this.getAttributeDefinition(a.property);return d&&(c=d.range[0]),this.options.collectionWidgets[c]!==b?this.options.collectionWidgets[c]:this.options.collectionWidgets["default"]},enableCollection:function(b){var c=this.collectionWidgetName(b);if(c===null)return;b.disabled=!1;if(typeof a(b.element)[c]!="function")throw new Error(c+" widget is not available");return a(b.element)[c](b),a(b.element).data("createCollectionWidgetName",c),a(b.element)},disableCollection:function(b){var c=a(b.element).data("createCollectionWidgetName");if(c===null)return;b.disabled=!0,c&&(a(b.element)[c](b),a(b.element).removeClass("ui-state-disabled"))}})}(jQuery),function(a,b){"use strict",a.widget("Create.editWidget",{options:{disabled:!1,vie:null},enable:function(){this.element.attr("contenteditable","true")},disable:function(a){this.element.attr("contenteditable","false")},_create:function(){this._registerWidget(),this._initialize()},_init:function(){if(this.options.disabled){this.disable();return}this.enable()},_initialize:function(){var b=this,c=this.element.html();this.element.bind("blur keyup paste",function(d){if(b.options.disabled)return;var e=a(this).html();c!==e&&(c=e,b.options.modified(e))})},_registerWidget:function(){this.element.data("createWidgetName",this.widgetName)}})}(jQuery),function(a,b){"use strict",a.widget("Create.alohaWidget",a.Create.editWidget,{enable:function(){this._initialize(),this.options.disabled=!1},disable:function(){Aloha.jQuery(this.options.element.get(0)).mahalo(),this.options.disabled=!0},_initialize:function(){var a=this.options,b,c=Aloha.jQuery(a.element.get(0)).aloha();_.each(Aloha.editables,function(a){a.obj.get(0)===c.get(0)&&(b=a)});if(!b)return;b.vieEntity=a.entity,Aloha.bind("aloha-editable-activated",function(c,d){if(d.editable!==b)return;a.activated()}),Aloha.bind("aloha-editable-deactivated",function(c,d){if(d.editable!==b)return;a.deactivated()}),Aloha.bind("aloha-smart-content-changed",function(c,d){if(d.editable!==b)return;if(!d.editable.isModified())return!0;a.modified(d.editable.getContents()),d.editable.setUnmodified()})}})}(jQuery),function(a,b){"use strict",a.widget("Create.halloWidget",a.Create.editWidget,{options:{editorOptions:{},disabled:!0,toolbarState:"full",vie:null,entity:null},enable:function(){a(this.element).hallo({editable:!0}),this.options.disabled=!1},disable:function(){a(this.element).hallo({editable:!1}),this.options.disabled=!0},_initialize:function(){a(this.element).hallo(this.getHalloOptions());var b=this;a(this.element).bind("halloactivated",function(a,c){b.options.activated()}),a(this.element).bind("hallodeactivated",function(a,c){b.options.deactivated()}),a(this.element).bind("hallomodified",function(a,c){b.options.modified(c.content),c.editable.setUnmodified()}),a(document).bind("midgardtoolbarstatechange",function(a,c){if(c.display===b.options.toolbarState)return;b.options.toolbarState=c.display;var d=b.getHalloOptions();b.element.hallo("changeToolbar",d.parentElement,d.toolbar,!0)})},getHalloOptions:function(){var b={plugins:{halloformat:{},halloblock:{},hallolists:{},hallolink:{},halloimage:{entity:this.options.entity}},buttonCssClass:"create-ui-btn-small",placeholder:"["+this.options.property+"]"};return typeof this.element.annotate=="function"&&this.options.vie.services.stanbol&&(b.plugins.halloannotate={vie:this.options.vie}),this.options.toolbarState==="full"?(b.parentElement=a(".create-ui-toolbar-dynamictoolarea .create-ui-tool-freearea"),b.toolbar="halloToolbarFixed"):(b.parentElement="body",b.toolbar="halloToolbarContextual"),_.extend(b,this.options.editorOptions)}})}(jQuery),function(a,b){"use strict",a.widget("Create.redactorWidget",a.Create.editWidget,{editor:null,options:{editorOptions:{},disabled:!0},enable:function(){a(this.element).redactor(this.getRedactorOptions()),this.options.disabled=!1},disable:function(){a(this.element).destroyEditor(),this.options.disabled=!0},_initialize:function(){var b=this;a(this.element).bind("focus",function(a){b.options.activated()})},getRedactorOptions:function(){var b=this,c={keyupCallback:function(c,d){b.options.modified(a(b.element).getCode())},execCommandCallback:function(c,d){b.options.modified(a(b.element).getCode())}};return _.extend(b.options.editorOptions,c)}})}(jQuery),function(a,b){"use strict";var c=[],d=function(b,d){var e={class_prefix:"midgardNotifications",timeout:3e3,auto_show:!0,body:"",bindTo:null,gravity:"T",effects:{onShow:function(a,b){a.animate({opacity:"show"},600,b)},onHide:function(a,b){a.animate({opacity:"hide"},600,b)}},actions:[],callbacks:{}},f={},g={},h=null,i=null,j=null,k=b,l=null,m={constructor:function(a){f=_.extend(e,a||{}),g={container:f.class_prefix+"-container",item:{wrapper:f.class_prefix+"-item",arrow:f.class_prefix+"-arrow",disregard:f.class_prefix+"-disregard",content:f.class_prefix+"-content",actions:f.class_prefix+"-actions",action:f.class_prefix+"-action"}},this._generate()},getId:function(){return i},getElement:function(){return h},_generate:function(){var b=this,d,e,j=null;h=d=a('<div class="'+g.item.wrapper+'-outer"/>'),d.css({display:"none"}),e=a('<div class="'+g.item.wrapper+'-inner"/>'),e.appendTo(d);if(f.bindTo){d.addClass(g.item.wrapper+"-binded");var m=a('<div class="'+g.item.arrow+'"/>');m.appendTo(d)}else d.addClass(g.item.wrapper+"-normal");j=a('<div class="'+g.item.content+'"/>'),j.html(f.body),j.appendTo(e);if(f.actions.length){var n=a('<div class="'+g.item.actions+'"/>');n.appendTo(e),a.each(f.actions,function(c,d){var e=a('<button name="'+d.name+'" class="button-'+d.name+'">'+d.label+"</button>").button();e.bind("click",function(a){l?d.cb(a,l,b):d.cb(a,b)}),d.className&&e.addClass(d.className),n.append(e)})}h.bind("click",function(a){f.callbacks.onClick?f.callbacks.onClick(a,b):l||b.close()}),f.auto_show&&this.show(),this._setPosition(),i=c.push(this),k.append(h)},_calculatePositionForGravity:function(a,b,c,d){a.find("."+g.item.arrow).addClass(g.item.arrow+"_"+b);switch(b){case"TL":return{left:c.left,top:c.top+c.height+"px"};case"TR":return{left:c.left+c.width-d.width+"px",top:c.top+c.height+"px"};case"BL":return{left:c.left+"px",top:c.top-d.height+"px"};case"BR":return{left:c.left+c.width-d.width+"px",top:c.top-d.height+"px"};case"LT":return{left:c.left+c.width+"px",top:c.top+"px"};case"LB":return{left:c.left+c.width+"px",top:c.top+c.height-d.height+"px"};case"RT":return{left:c.left-d.width+"px",top:c.top+"px"};case"RB":return{left:c.left-d.width+"px",top:c.top+c.height-d.height+"px"};case"T":return{left:c.left+c.width/2-d.width/2+"px",top:c.top+c.height+"px"};case"R":return{left:c.left-d.width+"px",top:c.top+c.height/2-d.height/2+"px"};case"B":return{left:c.left+c.width/2-d.width/2+"px",top:c.top-d.height+"px"};case"L":return{left:c.left+c.width+"px",top:c.top+c.height/2-d.height/2+"px"}}},_isFixed:function(a){if(a===document)return!1;if(a.css("position")==="fixed")return!0;var b=a.offsetParent();return b.get(0)===a.get(0)?!1:this._isFixed(b)},_setPosition:function(){var b;if(f.bindTo){var d={width:h.width()?h.width():280,height:h.height()?h.height():109};j=a(f.bindTo);var e={},g={width:j.outerWidth(),height:j.outerHeight()};this._isFixed(j)?(e.position="fixed",g.left=j.offset().left,g.top=j.position().top):(e.position="absolute",g.left=j.offset().left,g.top=j.offset().top),b=this._calculatePositionForGravity(h,f.gravity,g,d),e.top=b.top,e.left=b.left,h.css(e);return}f.position||(f.position="top right");var i=a(".create-ui-toolbar-wrapper").outerHeight(!0)+6;b={position:"fixed"};var k,l=function(b){var c=0;return a.each(b,function(a,b){if(!b)return;c+=b.getElement().height()}),c};f.position.match(/top/)&&(b.top=i+l(c)+"px"),f.position.match(/bottom/)&&(b.bottom=c.length-1*k.height()+k.height()+10+"px"),f.position.match(/right/)&&(b.right="20px"),f.position.match(/left/)&&(b.left="20px"),h.css(b)},show:function(){var b=this,c,d,e,g,i,j;f.callbacks.beforeShow&&f.callbacks.beforeShow(b);if(f.bindTo){var k=a(f.bindTo);c=a(window).scrollTop(),d=a(window).scrollTop()+a(window).height(),g=parseFloat(h.offset().top,10),i=k.offset().top,j=k.outerHeight(),i<g&&(g=i),e=parseFloat(h.offset().top,10)+h.height(),i+j>e&&(e=i+j)}f.timeout>0&&!f.actions.length&&window.setTimeout(function(){b.close()},f.timeout),f.bindTo&&(g<c||g>d)||e<c||e>d?a("html, body").stop().animate({scrollTop:g},500,"easeInOutExpo",function(){f.effects.onShow(h,function(){f.callbacks.afterShow&&f.callbacks.afterShow(b)})}):f.effects.onShow(h,function(){f.callbacks.afterShow&&f.callbacks.afterShow(b)})},close:function(){var a=this;f.callbacks.beforeClose&&f.callbacks.beforeClose(a),f.effects.onHide(h,function(){f.callbacks.afterClose&&f.callbacks.afterClose(a),a.destroy()})},destroy:function(){var b=this;a.each(c,function(a,d){d&&d.getId()==b.getId()&&delete c[a]}),a(h).remove()},setStory:function(a){l=a},setName:function(a){h.addClass(g.item.wrapper+"-custom-"+a),this.name=a}};return m.constructor(d),delete m.constructor,m},e=function(b,c){var e={},f={},g={},h={},i=null,j=null,k=null,l=null,m={constructor:function(a){f=_.extend(e,a||{})},setStoryline:function(b){var c={content:"",actions:[],show_actions:!0,notification:{},back:null,back_label:null,forward:null,forward_label:null,beforeShow:null,afterShow:null,beforeClose:null,afterClose:null};g={},l=null,i=null,j=null,k=null;var d=this;return a.each(b,function(b,e){var f=a.extend({},c,e);f.name=b;var h=a.extend({},c.notification,e.notification||{});h.body=f.content,h.auto_show=!1,f.actions.length&&(h.delay=0),h.callbacks={beforeShow:function(a){f.beforeShow&&f.beforeShow(a,d)},afterShow:function(a){f.afterShow&&f.afterShow(a,d)},beforeClose:function(a){f.beforeClose&&f.beforeClose(a,d)},afterClose:function(a){f.afterClose&&f.afterClose(a,d),i=a.name}},h.actions=[];if(f.show_actions){if(f.back){var l=f.back_label;l||(l="Back"),h.actions.push({name:"back",label:l,cb:function(a,b,c){b.previous()}})}if(f.forward){var m=f.forward_label;m||(m="Back"),h.actions.push({name:"forward",label:m,cb:function(a,b,c){b.next()}})}f.actions.length&&a.each(f.actions,function(a,b){h.actions.push(f.actions[a])})}j||(j=b),k=b,f.notification=h,g[b]=f}),g},start:function(){this._showNotification(g[j])},stop:function(){l.close(),l=null,i=null},next:function(){l.close();if(g[l.name].forward){var a=g[l.name].forward;this._showNotification(g[a])}else this._showNotification(g[k])},previous:function(){if(i){l.close();if(g[l.name].back){var a=g[l.name].back;this._showNotification(g[a])}else this._showNotification(g[i])}else this.stop()},_showNotification:function(b){return l=new d(a("body"),b.notification),l.setStory(this),l.setName(b.name),l.show(),l}};return m.constructor(b),delete m.constructor,c&&m.setStoryline(c),m},f={start:{content:"Welcome to CreateJS tutorial!",forward:"toolbar_toggle",forward_label:"Start tutorial",actions:[{name:"quit",label:"Quit",cb:function(a,b,c){b.stop()}}]},toolbar_toggle:{content:"This is the CreateJS toolbars toggle button.<br />You can hide and show the full toolbar by clicking here.<br />Try it now.",forward:"edit_button",show_actions:!1,afterShow:function(b,c){a("body").bind("midgardtoolbarstatechange",function(b,d){d.display=="full"&&(c.next(),a("body").unbind("midgardtoolbarstatechange"))})},notification:{bindTo:"#midgard-bar-hidebutton",timeout:0,gravity:"TL"}},edit_button:{content:"This is the edit button.<br />Try it now.",show_actions:!1,afterShow:function(b,c){a("body").bind("midgardcreatestatechange",function(b,d){d.state=="edit"&&(c.next(),a("body").unbind("midgardcreatestatechange"))})},notification:{bindTo:".ui-button[for=midgardcreate-edit]",timeout:0,gravity:"TL"}},end:{content:"Thank you for watching!<br />Happy content editing times await you!"}};a.widget("Midgard.midgardNotifications",{options:{notification_defaults:{class_prefix:"midgardNotifications",position:"top right"}},_create:function(){this.classes={container:this.options.notification_defaults.class_prefix+"-container"},a("."+this.classes.container,this.element).length?(this.container=a("."+this.classes.container,this.element),this._parseFromDOM()):(this.container=a('<div class="'+this.classes.container+'" />'),this.element.append(this.container))},destroy:function(){this.container.remove(),a.Widget.prototype.destroy.call(this)},_init:function(){},_parseFromDOM:function(a){},showStory:function(a,b){var c=new e(a,b);return c.start(),c},create:function(b){b=a.extend({},this.options.notification_defaults,b||{});var c=new d(this.container,b);return c.show(),c},showTutorial:function(){this.showStory({},f)}})}(jQuery),function(a,b){"use strict",a.widget("Midgard.midgardStorage",{saveEnabled:!0,options:{localStorage:!1,removeLocalstorageOnIgnore:!0,vie:null,url:"",autoSave:!1,autoSaveInterval:5e3,saveReferencedNew:!1,saveReferencedChanged:!1,editableNs:"midgardeditable",editSelector:"#midgardcreate-edit a",saveSelector:"#midgardcreate-save",templates:{localModifications:"<%= number %> items on this page have local modifications",saveSuccess:'Item "<%= label %>" saved successfully',saveSuccessMultiple:"<%= number %> items saved successfully",saveError:"Error occurred while saving<br /><%= error %>"}},_create:function(){var b=this;this.changedModels=[],window.localStorage&&(this.options.localStorage=!0),this.vie=this.options.vie,this.vie.entities.bind("add",function(a){a.url=b.options.url,a.toJSON=a.toJSONLD}),a(b.options.saveSelector).click(function(){b.saveRemote({success:function(){a(b.options.saveSelector).button({disabled:!0})},error:function(){}})}),b._bindEditables(),b.options.autoSave&&b._autoSave()},_autoSave:function(){var b=this;b.saveEnabled=!0;var c=function(){if(!b.saveEnabled)return;if(b.changedModels.length===0)return;b.saveRemote({success:function(){a(b.options.saveSelector).button({disabled:!0})},error:function(){}})},d=window.setInterval(c,b.options.autoSaveInterval);this.element.bind("startPreventSave",function(){d&&(window.clearInterval(d),d=null),b.disableSave()}),this.element.bind("stopPreventSave",function(){d||(d=window.setInterval(c,b.options.autoSaveInterval)),b.enableSave()})},enableSave:function(){this.saveEnabled=!0},disableSave:function(){this.saveEnabled=!1},_bindEditables:function(){var b=this;this.restorables=[];var c;b.element.bind(b.options.editableNs+"changed",function(c,d){_.indexOf(b.changedModels,d.instance)===-1&&b.changedModels.push(d.instance),b._saveLocal(d.instance),a(b.options.saveSelector).button({disabled:!1})}),b.element.bind(b.options.editableNs+"disable",function(c,d){b._restoreLocal(d.instance),a(b.options.saveSelector).hide()}),b.element.bind(b.options.editableNs+"enable",function(c,d){a(b.options.saveSelector).button({disabled:!0}),a(b.options.saveSelector).show(),d.instance._originalAttributes||(d.instance._originalAttributes=_.clone(d.instance.attributes)),!d.instance.isNew()&&b._checkLocal(d.instance)&&b.restorables.push(d.instance)}),b.element.bind("midgardcreatestatechange",function(a,d){if(d.state==="browse"||b.restorables.length===0){b.restorables=[],c&&c.close();return}c=b.checkRestore()}),b.element.bind("midgardstorageloaded",function(c,d){_.indexOf(b.changedModels,d.instance)===-1&&b.changedModels.push(d.instance),a(b.options.saveSelector).button({disabled:!1})})},checkRestore:function(){var b=this;if(b.restorables.length===0)return;var c=a("body").midgardNotifications("create",{bindTo:b.options.editSelector,gravity:"TR",body:_.template(b.options.templates.localModifications,{number:b.restorables.length}),timeout:0,actions:[{name:"restore",label:"Restore",cb:function(){_.each(b.restorables,function(a){b._readLocal(a)}),b.restorables=[]},className:"create-ui-btn"},{name:"ignore",label:"Ignore",cb:function(a,c){b.options.removeLocalstorageOnIgnore&&_.each(b.restorables,function(a){b._removeLocal(a)}),c.close(),b.restorables=[]},className:"create-ui-btn"}]});return c},saveRemote:function(b){var c=this;if(c.changedModels.length===0)return;c._trigger("save",null,{models:c.changedModels});var d,e=c.changedModels.length;e>1?d=_.template(c.options.templates.saveSuccessMultiple,{number:e}):d=_.template(c.options.templates.saveSuccess,{label:c.changedModels[0].getSubjectUri()}),c.disableSave(),_.each(c.changedModels,function(f){_.each(f.attributes,function(a,b){if(!a||!a.isCollection)return;a.each(function(a){if(c.changedModels.indexOf(a)!==-1)return;if(a.isNew()&&c.options.saveReferencedNew)return a.save();if(a.hasChanged()&&c.options.saveReferencedChanged)return a.save()})}),f.save(null,{success:function(){f._originalAttributes=_.clone(f.attributes),c._removeLocal(f),window.setTimeout(function(){c.changedModels.splice(c.changedModels.indexOf(f),1)},0),e--,e<=0&&(c._trigger("saved",null,{}),b.success(),a("body").midgardNotifications("create",{body:d}),c.enableSave())},error:function(d,e){b.error(),a("body").midgardNotifications("create",{body:_.template(c.options.templates.saveError,{error:e.responseText||""}),timeout:0}),c._trigger("error",null,{instance:f})}})})},_saveLocal:function(a){if(!this.options.localStorage)return;if(a.isNew()){if(!a.primaryCollection)return;return this._saveLocalReferences(a.primaryCollection.subject,a.primaryCollection.predicate,a)}window.localStorage.setItem(a.getSubjectUri(),JSON.stringify(a.toJSONLD()))},_getReferenceId:function(a,b){return a.id+":"+b},_saveLocalReferences:function(a,b,c){if(!this.options.localStorage)return;if(!a||!b)return;var d=this,e=a+":"+b,f=c.toJSONLD();if(window.localStorage.getItem(e)){var g=JSON.parse(window.localStorage.getItem(e)),h=_.pluck(g,"@").indexOf(f["@"]);h!==-1?g[h]=f:g.push(f),window.localStorage.setItem(e,JSON.stringify(g));return}window.localStorage.setItem(e,JSON.stringify([f]))},_checkLocal:function(a){if(!this.options.localStorage)return!1;var b=window.localStorage.getItem(a.getSubjectUri());return b?!0:!1},_readLocal:function(a){if(!this.options.localStorage)return;var b=window.localStorage.getItem(a.getSubjectUri());if(!b)return;a._originalAttributes||(a._originalAttributes=_.clone(a.attributes));var c=JSON.parse(b),d=this.vie.entities.addOrUpdate(c,{overrideAttributes:!0});this._trigger("loaded",null,{instance:d})},_readLocalReferences:function(a,b,c){if(!this.options.localStorage)return;var d=this._getReferenceId(a,b),e=window.localStorage.getItem(d);if(!e)return;c.add(JSON.parse(e))},_restoreLocal:function(a){var b=this;if(!a)return;_.each(a.attributes,function(a,c){if(a instanceof b.vie.Collection){var d=[];a.forEach(function(a){a.isNew()&&d.push(a)}),a.remove(d)}});if(!a.changedAttributes()){a._originalAttributes&&a.set(a._originalAttributes);return}a.set(a.previousAttributes())},_removeLocal:function(a){if(!this.options.localStorage)return;window.localStorage.removeItem(a.getSubjectUri())}})}(jQuery),function(a,b){"use strict",a.widget("Midgard.midgardTags",{enhanced:!1,options:{vie:null,entity:null,element:null,entityElement:null,parentElement:".create-ui-tool-metadataarea",predicate:"skos:related",templates:{button:'<button class="create-ui-btn"><i class="icon-<%= icon %>"></i> <%= label %></button>'
-,contentArea:'<div class="dropdown-menu"></div>',tags:'<div class="create-ui-tags <%= type %>Tags"><h3><%= label %></h3><input type="text" class="tags" value="" /></div>'}},_init:function(){var b=this;this.vie=this.options.vie,this.entity=this.options.entity,this.element=this.options.element,a(this.options.entityElement).bind("midgardeditableactivated",function(a,c){if(c.instance!==b.options.entity)return;b._renderWidget(),b.loadTags()}),a(this.options.entityElement).bind("midgardeditablechanged",function(a,c){if(c.instance!==b.options.entity)return;b.enhanced=!1}),this._listenAnnotate(this.options.entityElement)},_normalizeSubject:function(a){return this.entity.isReference(a)?a:(a.substr(0,7)!=="http://"&&(a="urn:tag:"+a),a=this.entity.toReference(a),a)},_tagLabel:function(a){return a=this.entity.fromReference(a),a.substr(0,8)==="urn:tag:"&&(a=a.substr(8,a.length-1)),a.substring(0,7)=="http://"&&(a=a.substr(a.lastIndexOf("/")+1,a.length-1),a=a.replace(/_/g," ")),a},addTag:function(a,c,d){c===b&&(c=this._tagLabel(a)),a=this._normalizeSubject(a),d&&!this.entity.isReference(d)&&(d=this.entity.toReference(d));var e=this.vie.entities.addOrUpdate({"@subject":a,"rdfs:label":c,"@type":d}),f=this.options.entity.get(this.options.predicate);f?f.isCollection||(f=new this.vie.Collection(_.map(f,function(a){return a.isEntity?a:{"@subject":a}})),f.vie=this.options.vie,this.options.entity.set(this.options.predicate,f)):(f=new this.vie.Collection,f.vie=this.options.vie,this.options.entity.set(this.options.predicate,f)),f.addOrUpdate(e),this.options.entityElement.trigger("midgardeditablechanged",{instance:this.options.entity})},removeTag:function(a){var b=this.options.entity.get(this.options.predicate);if(!b)return;a=this._normalizeSubject(a);var c=b.get(a);if(!c)return;b.remove(a),this.options.entityElement.trigger("midgardeditablechanged",{instance:this.options.entity})},_listenAnnotate:function(a){var b=this;a.bind("annotateselect",function(a,c){b.addTag(c.linkedEntity.uri,c.linkedEntity.label,c.linkedEntity.type[0])}),a.bind("annotateremove",function(a,c){b.removeTag(c.linkedEntity.uri)})},_prepareEditor:function(b){var c=a(_.template(this.options.templates.contentArea,{})),d=a(_.template(this.options.templates.tags,{type:"article",label:"Item tags"})),e=a(_.template(this.options.templates.tags,{type:"suggested",label:"Suggested tags"}));a("input",d).attr("id","articleTags-"+this.entity.cid),a("input",e).attr("id","suggestedTags-"+this.entity.cid),c.append(d),c.append(e),c.hide();var f=b.position();return c.css("position","absolute"),c.css("left",f.left),c},_renderWidget:function(){var b=this,c=this.entity.getSubject(),d=a(_.template(this.options.templates.button,{icon:"tags",label:"Tags"})),e=a(this.options.parentElement);e.empty(),e.append(d),e.show();var f=this._prepareEditor(d);d.after(f),this.articleTags=a(".articleTags input",f).tagsInput({width:"auto",height:"auto",onAddTag:function(a){b.addTag(a)},onRemoveTag:function(a){b.removeTag(a)}});var g=function(){var c=a.trim(a(this).text());b.articleTags.addTag(c),b.suggestedTags.removeTag(c)};this.suggestedTags=a(".suggestedTags input",f).tagsInput({width:"auto",height:"auto",interactive:!1,onAddTag:function(b){a(".suggestedTags .tag span",f).unbind("click",g),a(".suggestedTags .tag span",f).bind("click",g)},onRemoveTag:function(b){a(".suggestedTags .tag span",f).unbind("click",g),a(".suggestedTags .tag span",f).bind("click",g)},remove:!1}),d.bind("click",function(){f.toggle()})},loadTags:function(){var b=this,c=this.entity.get(this.options.predicate);c&&(_.isString(c)?b.articleTags.addTag(b._tagLabel(c)):c.isCollection?c.each(function(a){b.articleTags.addTag(a.get("rdfs:label"))}):_.each(c,function(a){b.articleTags.addTag(b._tagLabel(a))})),this.vie.services.stanbol?b.enhance():a(".suggestedTags",b.element).hide()},_getLabelLang:function(a){if(!_.isArray(a))return null;var b;return _.each(a,function(a){a["@language"]==="en"&&(b=a["@value"])}),b},_addEnhancement:function(a){if(!a.isEntity)return;var b=this._getLabelLang(a.get("rdfs:label"));if(!b)return;var c=this.options.entity.get(this.options.predicate);if(c&&c.isCollection&&c.indexOf(a)!==-1)return;this.suggestedTags.addTag(b)},enhance:function(){if(this.enhanced)return;this.enhanced=!0;var b=this;this.vie.analyze({element:a("[property]",this.options.entityElement)}).using(["stanbol"]).execute().success(function(a){_.each(a,function(a){b._addEnhancement(a)})}).fail(function(a){})}})}(jQuery),function(a,b){"use strict",a.widget("Midgard.midgardToolbar",{options:{display:"full",templates:{minimized:'<div class="create-ui-logo"><a class="create-ui-toggle" id="create-ui-toggle-toolbar"></a></div>',full:'<div class="create-ui-toolbar-wrapper"><div class="create-ui-toolbar-toolarea"><%= dynamic %><%= status %></div></div>',toolcontainer:'<div class="create-ui-toolbar-<%= name %>toolarea"><ul class="create-ui-<%= name %>tools"><%= content %></ul></div>',toolarea:'<li class="create-ui-tool-<%= name %>area"></li>'}},_create:function(){this.element.append(this._getMinimized()),this.element.append(this._getFull());var b=this;a(".create-ui-toggle",this.element).click(function(){b.options.display==="full"?b.setDisplay("minimized"):b.setDisplay("full")}),a(this.element).bind("midgardcreatestatechange",function(a,c){c.state=="browse"&&(b._clearWorkflows(),b._clearMetadata())}),a(this.element).bind("midgardworkflowschanged",function(c,d){b._clearWorkflows(),d.workflows.length&&d.workflows.each(function(c){var e=a("body").data().midgardWorkflows.prepareItem(d.instance,c,function(a,c){b._clearWorkflows();if(a)return});a(".create-ui-tool-workflowarea",this.element).append(e)})})},_init:function(){this.setDisplay(this.options.display)},setDisplay:function(a){if(a===this.options.display)return;a==="minimized"?(this.hide(),this.options.display="minimized"):(this.show(),this.options.display="full"),this._trigger("statechange",null,this.options)},hide:function(){a("div.create-ui-toolbar-wrapper").fadeToggle("fast","linear")},show:function(){a("div.create-ui-toolbar-wrapper").fadeToggle("fast","linear")},_getMinimized:function(){return a(_.template(this.options.templates.minimized,{}))},_getFull:function(){return a(_.template(this.options.templates.full,{dynamic:_.template(this.options.templates.toolcontainer,{name:"dynamic",content:_.template(this.options.templates.toolarea,{name:"metadata"})+_.template(this.options.templates.toolarea,{name:"workflow"})+_.template(this.options.templates.toolarea,{name:"free"})}),status:_.template(this.options.templates.toolcontainer,{name:"status",content:""})}))},_clearWorkflows:function(){a(".create-ui-tool-workflowarea",this.element).empty()},_clearMetadata:function(){a(".create-ui-tool-metadataarea",this.element).empty()}})}(jQuery),function(a,b){"use strict",a.widget("Midgard.midgardWorkflows",{options:{url:function(a){},templates:{button:'<button class="create-ui-btn" id="<%= id %>"><%= label %></button>'},renderers:{button:function(b,c,d,e){var f="midgardcreate-workflow_"+c.get("name"),g=a(_.template(this.options.templates.button,{id:f,label:c.get("label")})).button();return g.bind("click",function(a){d(b,c,e)}),g}},action_types:{backbone_save:function(a,b,c){var d=a.url,e=a.clone();e.url=d;var f=b.get("action");f.url&&(a.url=f.url),e.save(null,{success:function(b){a.url=d,a.change(),c(null,a)},error:function(b,e){a.url=d,a.change(),c(e,a)}})},backbone_destroy:function(a,b,c){var d=a.url,e=a.clone();e.url=d;var f=b.get("action");f.url&&(a.url=f.url),a.destroy({success:function(b){a.url=d,a.change(),c(null,b)},error:function(b,e){a.url=d,a.change(),c(e,a)}})},http:function(b,c,d){var e=c.get("action");if(!e.url)return d("No action url defined!");var f={};e.http&&(f=e.http);var g=a.extend({url:e.url,type:"POST",data:b.toJSON(),success:function(){b.fetch({success:function(a){d(null,a)},error:function(a,b){d(b,a)}})}},f);a.ajax(g)}}},_init:function(){this._renderers={},this._action_types={},this._parseRenderersAndTypes(),this._last_instance=null,this.ModelWorkflowModel=Backbone.Model.extend({defaults:{name:"",label:"",type:"button",action:{type:"backbone_save"}}}),this.workflows={};var b=this;a(this.element).bind("midgardeditableactivated",function(a,c){b._fetchWorkflows(c.instance)})},_fetchWorkflows:function(a){var b=this;if(a.isNew()){b._trigger("changed",null,{instance:a,workflows:[]});return}if(b._last_instance==a){b.workflows[a.cid]&&b._trigger("changed",null,{instance:a,workflows:b.workflows[a.cid]});return}b._last_instance=a;if(b.workflows[a.cid]){b._trigger("changed",null,{instance:a,workflows:b.workflows[a.cid]});return}if(b.options.url)b._fetchModelWorkflows(a);else{var c=new(b._generateCollectionFor(a))([],{});b._trigger("changed",null,{instance:a,workflows:c})}},_parseRenderersAndTypes:function(){var b=this;a.each(this.options.renderers,function(a,c){b.setRenderer(a,c)}),a.each(this.options.action_types,function(a,c){b.setActionType(a,c)})},setRenderer:function(a,b){this._renderers[a]=b},getRenderer:function(a){return this._renderers[a]?this._renderers[a]:!1},setActionType:function(a,b){this._action_types[a]=b},getActionType:function(a){return this._action_types[a]},prepareItem:function(a,b,c){var d=this,e=this.getRenderer(b.get("type")),f=this.getActionType(b.get("action").type);return e.call(this,a,b,f,function(e,f){delete d.workflows[a.cid],d._last_instance=null,b.get("action").type!=="backbone_destroy"&&d._fetchModelWorkflows(a),c(e,f)})},_generateCollectionFor:function(a){var b={model:this.ModelWorkflowModel};return this.options.url&&(b.url=this.options.url(a)),Backbone.Collection.extend(b)},_fetchModelWorkflows:function(a){if(a.isNew())return;var b=this;b.workflows[a.cid]=new(this._generateCollectionFor(a))([],{}),b.workflows[a.cid].fetch({success:function(c){b.workflows[a.cid].reset(c.models),b._trigger("changed",null,{instance:a,workflows:b.workflows[a.cid]})},error:function(a,b){}})}})}(jQuery);
+window.midgardCreate===undefined&&(window.midgardCreate={}),window.midgardCreate.locale===undefined&&(window.midgardCreate.locale={}),window.midgardCreate.locale.en={Save:"Save",Saving:"Saving",Cancel:"Cancel",Edit:"Edit",localModifications:"<%= number %> items on this page have local modifications",Restore:"Restore",Ignore:"Ignore",saveSuccess:'Item "<%= label %>" saved successfully',saveSuccessMultiple:"<%= number %> items saved successfully",saveError:"Error occurred while saving<br /><%= error %>","Item tags":"Item tags","Suggested tags":"Suggested tags",Tags:"Tags","add a tag":"add a tag",Add:"Add","Choose type to add":"Choose type to add"},window.midgardCreate===undefined&&(window.midgardCreate={}),window.midgardCreate.locale===undefined&&(window.midgardCreate.locale={}),window.midgardCreate.locale.fi={Save:"Tallenna",Saving:"Tallennetaan",Cancel:"Peruuta",Edit:"Muokkaa",localModifications:"<%= number %> oliota sivulla omaa paikallisia muutoksia",Restore:"Palauta",Ignore:"Poista",saveSuccess:'Olio "<%= label %>" tallennettu',saveSuccessMultiple:"<%= number %> oliota tallennettu",saveError:"Virhe tallennettaessa<br /><%= error %>","Item tags":"Avainsanat","Suggested tags":"Ehdotukset",Tags:"Avainsanat","add a tag":"lisää avainsana",Add:"Lisää","Choose type to add":"Mitä haluat lisätä?"},function(a,b){"use strict",a.widget("Midgard.midgardCreate",{options:{toolbar:"full",saveButton:null,state:"browse",highlight:!0,highlightColor:"#67cc08",editorWidgets:{"default":"hallo"},editorOptions:{hallo:{widget:"halloWidget"}},collectionWidgets:{"default":"midgardCollectionAdd"},url:function(){},storagePrefix:"node",workflows:{url:null},notifications:{},vie:null,stanbolUrl:null,dbPediaUrl:null,tags:!1,buttonContainer:".create-ui-toolbar-statustoolarea .create-ui-statustools",templates:{buttonContent:'<%= label %> <i class="icon-<%= icon %>"></i>',button:'<li id="<%= id %>"><a class="create-ui-btn"><%= buttonContent %></a></li>'},localize:function(a,b){return window.midgardCreate.localize(a,b)},language:null},_create:function(){this.vie=this._setupVIE(this.options);var b=this;window.setTimeout(function(){b._checkSession()},10),this.options.language||(this.options.language=a("html").attr("lang")),this._enableToolbar(),this._saveButton(),this._editButton(),this._prepareStorage(),this.element.midgardWorkflows&&this.element.midgardWorkflows(this.options.workflows),this.element.midgardNotifications&&this.element.midgardNotifications(this.options.notifications)},destroy:function(){this.element.midgardStorage("destroy"),this.element.midgardToolbar("destroy"),a("[about]",this.element).each(function(){a(this).midgardEditable("destroy")}),this.element.midgardWorkflows&&this.element.midgardWorkflows("destroy"),this.element.midgardNotifications&&this.element.midgardNotifications("destroy"),this.options.tags&&this.element.midgardTags("destroy"),a.Widget.prototype.destroy.call(this)},_setupVIE:function(a){var b;return a.vie?b=a.vie:b=new VIE,b.hasService("rdfa")||b.use(new b.RdfaService),!b.hasService("stanbol")&&a.stanbolUrl&&b.use(new b.StanbolService({proxyDisabled:!0,url:a.stanbolUrl})),!b.hasService("dbpedia")&&a.dbPediaUrl&&b.use(new b.DBPediaService({proxyDisabled:!0,url:a.dbPediaUrl})),b},_prepareStorage:function(){this.element.midgardStorage({vie:this.vie,url:this.options.url,localize:this.options.localize,language:this.options.language});var b=this;this.element.bind("midgardstoragesave",function(){a("#midgardcreate-save a").html(_.template(b.options.templates.buttonContent,{label:b.options.localize("Saving",b.options.language),icon:"upload"}))}),this.element.bind("midgardstoragesaved midgardstorageerror",function(){a("#midgardcreate-save a").html(_.template(b.options.templates.buttonContent,{label:b.options.localize("Save",b.options.language),icon:"ok"}))})},_init:function(){this.setState(this.options.state)},setState:function(a){this._setOption("state",a),a==="edit"?this._enableEdit():this._disableEdit(),this._setEditButtonState(a)},setToolbar:function(a){this.options.toolbar=a,this.element.midgardToolbar("setDisplay",a)},showNotification:function(a){if(this.element.midgardNotifications)return this.element.midgardNotifications("create",a)},configureEditor:function(a,b,c){this.options.editorOptions[a]={widget:b,options:c}},setEditorForContentType:function(a,c){if(this.options.editorOptions[c]===b&&c!==null)throw new Error("No editor "+c+" configured");this.options.editorWidgets[a]=c},setEditorForProperty:function(a,c){if(this.options.editorOptions[c]===b&&c!==null)throw new Error("No editor "+c+" configured");this.options.editorWidgets[a]=c},_checkSession:function(){if(!window.sessionStorage)return;var a=this.options.storagePrefix+"Midgard.create.toolbar";window.sessionStorage.getItem(a)&&this.setToolbar(window.sessionStorage.getItem(a));var b=this.options.storagePrefix+"Midgard.create.state";window.sessionStorage.getItem(b)&&this.setState(window.sessionStorage.getItem(b)),this.element.bind("midgardcreatestatechange",function(a,c){window.sessionStorage.setItem(b,c.state)})},_saveButton:function(){if(this.options.saveButton)return this.options.saveButton;var b=this;return a(this.options.buttonContainer,this.element).append(a(_.template(this.options.templates.button,{id:"midgardcreate-save",buttonContent:_.template(this.options.templates.buttonContent,{label:b.options.localize("Save",b.options.language),icon:"ok"})}))),this.options.saveButton=a("#midgardcreate-save",this.element),this.options.saveButton.hide(),this.options.saveButton},_editButton:function(){var b=this;a(this.options.buttonContainer,this.element).append(a(_.template(this.options.templates.button,{id:"midgardcreate-edit",buttonContent:""}))),a("#midgardcreate-edit",this.element).bind("click",function(){if(b.options.state==="edit"){b.setState("browse");return}b.setState("edit")})},_setEditButtonState:function(b){var c=this,d={edit:_.template(this.options.templates.buttonContent,{label:c.options.localize("Cancel",c.options.language),icon:"remove"}),browse:_.template(this.options.templates.buttonContent,{label:c.options.localize("Edit",c.options.language),icon:"edit"})},e=a("#midgardcreate-edit a",this.element);if(!e)return;b==="edit"&&e.addClass("selected"),e.html(d[b])},_enableToolbar:function(){var a=this;this.element.bind("midgardtoolbarstatechange",function(b,c){a.setToolbar(c.display),window.sessionStorage&&window.sessionStorage.setItem(a.options.storagePrefix+"Midgard.create.toolbar",c.display)}),this.element.midgardToolbar({display:this.options.toolbar,vie:this.vie})},_enableEdit:function(){this._setOption("state","edit");var b=this,c={toolbarState:b.options.toolbar,disabled:!1,vie:b.vie,widgets:b.options.editorWidgets,editors:b.options.editorOptions,collectionWidgets:b.options.collectionWidgets,localize:b.options.localize,language:b.options.language};b.options.enableEditor&&(c.enableEditor=b.options.enableEditor),b.options.disableEditor&&(c.disableEditor=b.options.disableEditor),a("[about]",this.element).each(function(){var d=this;if(b.options.highlight){var e=function(c,e){if(!a(e.element).is(":visible"))return;if(e.entityElement.get(0)!==d)return;e.element.stop(!0,!0),e.element.effect("highlight",{color:b.options.highlightColor},3e3)};a(this).bind("midgardeditableenableproperty",e)}a(this).bind("midgardeditabledisable",function(){a(this).unbind("midgardeditableenableproperty",e)}),b.options.tags&&a(this).bind("midgardeditableenable",function(c,e){if(c.target!==d)return;a(this).midgardTags({vie:b.vie,entityElement:e.entityElement,entity:e.instance,localize:b.options.localize,language:b.options.language})}),a(this).midgardEditable(c)}),this._trigger("statechange",null,{state:"edit"})},_disableEdit:function(){var b=this,c={disabled:!0,vie:b.vie,editorOptions:b.options.editorOptions,localize:b.options.localize,language:b.options.language};a("[about]",this.element).each(function(){a(this).midgardEditable(c),a(this).removeClass("ui-state-disabled")}),this._setOption("state","browse"),this._trigger("statechange",null,{state:"browse"})}})}(jQuery),function(a,b){"use strict",a.widget("Midgard.midgardCollectionAdd",{options:{editingWidgets:null,collection:null,model:null,definition:null,view:null,disabled:!1,vie:null,editableOptions:null,templates:{button:'<button class="btn"><i class="icon-<%= icon %>"></i> <%= label %></button>'}},_create:function(){this.addButtons=[];var a=this;if(!a.options.collection.localStorage)try{a.options.collection.url=a.options.model.url()}catch(b){window.console&&console.log(b)}a.options.collection.bind("add",function(b){b.primaryCollection=a.options.collection,a.options.vie.entities.add(b),b.collection=a.options.collection}),a.options.collection.bind("add remove reset",a.checkCollectionConstraints,a),a._bindCollectionView(a.options.view)},_bindCollectionView:function(a){var b=this;a.bind("add",function(a){a.$el.effect("slide",function(){b._makeEditable(a)})})},_makeEditable:function(a){this.options.editableOptions.disabled=this.options.disabled,this.options.editableOptions.model=a.model,a.$el.midgardEditable(this.options.editableOptions)},_init:function(){if(this.options.disabled){this.disable();return}this.enable()},hideButtons:function(){_.each(this.addButtons,function(a){a.hide()})},showButtons:function(){_.each(this.addButtons,function(a){a.show()})},checkCollectionConstraints:function(){if(this.options.disabled)return;if(!this.options.view.canAdd()){this.hideButtons();return}if(!this.options.definition){this.showButtons();return}if(!this.options.definition.max||this.options.definition.max===-1){this.showButtons();return}if(this.options.collection.length<this.options.definition.max){this.showButtons();return}this.hideButtons()},enable:function(){var b=this,c=a(_.template(this.options.templates.button,{icon:"plus",label:this.options.editableOptions.localize("Add",this.options.editableOptions.language)})).button();c.addClass("midgard-create-add"),c.click(function(){b.addItem(c)}),a(b.options.view.el).after(c),b.addButtons.push(c),b.checkCollectionConstraints()},disable:function(){_.each(this.addButtons,function(a){a.remove()}),this.addButtons=[]},_getTypeActions:function(a){var b=this,c=[];return _.each(this.options.definition.range,function(d){var e=b.options.collection.vie.namespaces.uri(d);if(!b.options.view.canAdd(e))return;c.push({name:d,label:d,cb:function(){b.options.collection.add({"@type":d},a)},className:"create-ui-btn"})}),c},addItem:function(b,c){var d={};if(this.options.definition&&this.options.definition.range){if(this.options.definition.range.length!==1){a("body").midgardNotifications("create",{bindTo:b,gravity:"L",body:this.options.editableOptions.localize("Choose type to add",this.options.editableOptions.language),timeout:0,actions:this._getTypeActions(c)});return}d["@type"]=this.options.definition.range[0]}this.options.collection.add({},c)}})}(jQuery),function(a,b){"use strict",a.widget("Midgard.midgardCollectionAddBetween",a.Midgard.midgardCollectionAdd,{_bindCollectionView:function(a){var b=this;a.bind("add",function(a){b._makeEditable(a),b._refreshButtons()}),a.bind("remove",function(){b._refreshButtons()})},_refreshButtons:function(){var a=this;window.setTimeout(function(){a.disable(),a.enable()},1)},prepareButton:function(b){var c=this,d=a(_.template(this.options.templates.button,{icon:"plus",label:""})).button();return d.addClass("midgard-create-add"),d.click(function(){c.addItem(d,{at:b})}),d},enable:function(){var b=this,c=b.prepareButton(0);a(b.options.view.el).prepend(c),b.addButtons.push(c),a.each(b.options.view.entityViews,function(c,d){var e=b.options.collection.indexOf(d.model),f=b.prepareButton(e+1);a(d.el).append(f),b.addButtons.push(f)}),this.checkCollectionConstraints()},disable:function(){var b=this;a.each(b.addButtons,function(a,b){b.remove()}),b.addButtons=[]}})}(jQuery),function(a,b){"use strict",a.widget("Midgard.midgardEditable",{options:{editables:[],collections:[],model:null,editors:{hallo:{widget:"halloWidget",options:{}}},widgets:{"default":"hallo"},collectionWidgets:{"default":"midgardCollectionAdd"},toolbarState:"full",vie:null,disabled:!1,localize:function(a,b){return window.midgardCreate.localize(a,b)},language:null},_create:function(){this.vie=this.options.vie;if(!this.options.model){var a=this;this.vie.load({element:this.element}).from("rdfa").execute().done(function(b){a.options.model=b[0]})}},_init:function(){if(this.options.disabled){this.disable();return}this.enable()},findEditableElements:function(b){this.vie.service("rdfa").findPredicateElements(this.options.model.id,a("[property]",this.element),!1).each(b)},enable:function(){var b=this;if(!this.options.model)return;this.findEditableElements(function(){return b._enableProperty(a(this))}),this._trigger("enable",null,{instance:this.options.model,entityElement:this.element});if(!this.vie.services.rdfa)return;_.each(this.vie.service("rdfa").views,function(a){if(a instanceof b.vie.view.Collection&&b.options.model===a.owner){var c=a.collection.predicate,d=b.enableCollection({model:b.options.model,collection:a.collection,property:c,definition:b.getAttributeDefinition(c),view:a,element:a.el,vie:b.vie,editableOptions:b.options});b.options.collections.push(d)}})},disable:function(){var b=this;a.each(this.options.editables,function(c,d){b.disableEditor({widget:b,editable:d,entity:b.options.model,element:a(this)})}),this.options.editables=[],a.each(this.options.collections,function(a,c){b.disableCollection({widget:b,model:b.options.model,element:c,vie:b.vie,editableOptions:b.options})}),this.options.collections=[],this._trigger("disable",null,{instance:this.options.model,entityElement:this.element})},getElementPredicate:function(a){return this.vie.service("rdfa").getElementPredicate(a)},_enableProperty:function(a){var b=this,c=this.getElementPredicate(a);if(!c)return!0;if(this.options.model.get(c)instanceof Array)return!0;var d=this.enableEditor({widget:this,element:a,entity:this.options.model,property:c,vie:this.vie,modified:function(d){var e={};e[c]=d,b.options.model.set(e,{silent:!0}),b._trigger("changed",null,{property:c,instance:b.options.model,element:a,entityElement:b.element})},activated:function(){b._trigger("activated",null,{property:c,instance:b.options.model,element:a,entityElement:b.element})},deactivated:function(){b._trigger("deactivated",null,{property:c,instance:b.options.model,element:a,entityElement:b.element})}});d&&this._trigger("enableproperty",null,{editable:d,property:c,instance:this.options.model,element:a,entityElement:this.element}),this.options.editables.push(d)},_editorName:function(a){if(this.options.widgets[a.property]!==b)return this.options.widgets[a.property];var c="default",d=this.getAttributeDefinition(a.property);return d&&(c=d.range[0]),this.options.widgets[c]!==b?this.options.widgets[c]:this.options.widgets["default"]},_editorWidget:function(a){return this.options.editors[a].widget},_editorOptions:function(a){return this.options.editors[a].options},getAttributeDefinition:function(a){var b=this.options.model.get("@type");if(!b)return;if(!b.attributes)return;return b.attributes.get(a)},enableEditor:function(b){var c=this._editorName(b);if(c===null)return;var d=this._editorWidget(c);b.editorOptions=this._editorOptions(c),b.toolbarState=this.options.toolbarState,b.disabled=!1;if(typeof a(b.element)[d]!="function")throw new Error(d+" widget is not available");return a(b.element)[d](b),a(b.element).data("createWidgetName",d),a(b.element)},disableEditor:function(b){var c=a(b.element).data("createWidgetName");b.disabled=!0,c&&(a(b.element)[c](b),a(b.element).removeClass("ui-state-disabled"))},collectionWidgetName:function(a){if(this.options.collectionWidgets[a.property]!==b)return this.options.collectionWidgets[a.property];var c="default",d=this.getAttributeDefinition(a.property);return d&&(c=d.range[0]),this.options.collectionWidgets[c]!==b?this.options.collectionWidgets[c]:this.options.collectionWidgets["default"]},enableCollection:function(b){var c=this.collectionWidgetName(b);if(c===null)return;b.disabled=!1;if(typeof a(b.element)[c]!="function")throw new Error(c+" widget is not available");return a(b.element)[c](b),a(b.element).data("createCollectionWidgetName",c),a(b.element)},disableCollection:function(b){var c=a(b.element).data("createCollectionWidgetName");if(c===null)return;b.disabled=!0,c&&(a(b.element)[c](b),a(b.element).removeClass("ui-state-disabled"))}})}(jQuery),function(a,b){"use strict",a.widget("Create.editWidget",{options:{disabled:!1,vie:null},enable:function(){this.element.attr("contenteditable","true")},disable:function(a){this.element.attr("contenteditable","false")},_create:function(){this._registerWidget(),this._initialize()},_init:function(){if(this.options.disabled){this.disable();return}this.enable()},_initialize:function(){var b=this,c=this.element.html();this.element.bind("blur keyup paste",function(d){if(b.options.disabled)return;var e=a(this).html();c!==e&&(c=e,b.options.modified(e))})},_registerWidget:function(){this.element.data("createWidgetName",this.widgetName)}})}(jQuery),function(a,b){"use strict",a.widget("Create.alohaWidget",a.Create.editWidget,{enable:function(){this._initialize(),this.options.disabled=!1},disable:function(){Aloha.jQuery(this.options.element.get(0)).mahalo(),this.options.disabled=!0},_initialize:function(){var a=this.options,b,c=Aloha.jQuery(a.element.get(0)).aloha();_.each(Aloha.editables,function(a){a.obj.get(0)===c.get(0)&&(b=a)});if(!b)return;b.vieEntity=a.entity,Aloha.bind("aloha-editable-activated",function(c,d){if(d.editable!==b)return;a.activated()}),Aloha.bind("aloha-editable-deactivated",function(c,d){if(d.editable!==b)return;a.deactivated()}),Aloha.bind("aloha-smart-content-changed",function(c,d){if(d.editable!==b)return;if(!d.editable.isModified())return!0;a.modified(d.editable.getContents()),d.editable.setUnmodified()})}})}(jQuery),function(a,b){"use strict",a.widget("Create.halloWidget",a.Create.editWidget,{options:{editorOptions:{},disabled:!0,toolbarState:"full",vie:null,entity:null},enable:function(){a(this.element).hallo({editable:!0}),this.options.disabled=!1},disable:function(){a(this.element).hallo({editable:!1}),this.options.disabled=!0},_initialize:function(){a(this.element).hallo(this.getHalloOptions());var b=this;a(this.element).bind("halloactivated",function(a,c){b.options.activated()}),a(this.element).bind("hallodeactivated",function(a,c){b.options.deactivated()}),a(this.element).bind("hallomodified",function(a,c){b.options.modified(c.content),c.editable.setUnmodified()}),a(document).bind("midgardtoolbarstatechange",function(a,c){if(c.display===b.options.toolbarState)return;b.options.toolbarState=c.display;var d=b.getHalloOptions();b.element.hallo("changeToolbar",d.parentElement,d.toolbar,!0)})},getHalloOptions:function(){var b={plugins:{halloformat:{},halloblock:{},hallolists:{},hallolink:{},halloimage:{entity:this.options.entity}},buttonCssClass:"create-ui-btn-small",placeholder:"["+this.options.property+"]"};return typeof this.element.annotate=="function"&&this.options.vie.services.stanbol&&(b.plugins.halloannotate={vie:this.options.vie}),this.options.toolbarState==="full"?(b.parentElement=a(".create-ui-toolbar-dynamictoolarea .create-ui-tool-freearea"),b.toolbar="halloToolbarFixed"):(b.parentElement="body",b.toolbar="halloToolbarContextual"),_.extend(b,this.options.editorOptions)}})}(jQuery),function(a,b){"use strict",a.widget("Create.redactorWidget",a.Create.editWidget,{editor:null,options:{editorOptions:{},disabled:!0},enable:function(){a(this.element).redactor(this.getRedactorOptions()),this.options.disabled=!1},disable:function(){a(this.element).destroyEditor(),this.options.disabled=!0},_initialize:function(){var b=this;a(this.element).bind("focus",function(a){b.options.activated()})},getRedactorOptions:function(){var b=this,c={keyupCallback:function(c,d){b.options.modified(a(b.element).getCode())},execCommandCallback:function(c,d){b.options.modified(a(b.element).getCode())}};return _.extend(b.options.editorOptions,c)}})}(jQuery),function(a,b){"use strict";var c=[],d=function(b,d){var e={class_prefix:"midgardNotifications",timeout:3e3,auto_show:!0,body:"",bindTo:null,gravity:"T",effects:{onShow:function(a,b){a.animate({opacity:"show"},600,b)},onHide:function(a,b){a.animate({opacity:"hide"},600,b)}},actions:[],callbacks:{}},f={},g={},h=null,i=null,j=null,k=b,l=null,m={constructor:function(a){f=_.extend(e,a||{}),g={container:f.class_prefix+"-container",item:{wrapper:f.class_prefix+"-item",arrow:f.class_prefix+"-arrow",disregard:f.class_prefix+"-disregard",content:f.class_prefix+"-content",actions:f.class_prefix+"-actions",action:f.class_prefix+"-action"}},this._generate()},getId:function(){return i},getElement:function(){return h},_generate:function(){var b=this,d,e,j=null;h=d=a('<div class="'+g.item.wrapper+'-outer"/>'),d.css({display:"none"}),e=a('<div class="'+g.item.wrapper+'-inner"/>'),e.appendTo(d);if(f.bindTo){d.addClass(g.item.wrapper+"-binded");var m=a('<div class="'+g.item.arrow+'"/>');m.appendTo(d)}else d.addClass(g.item.wrapper+"-normal");j=a('<div class="'+g.item.content+'"/>'),j.html(f.body),j.appendTo(e);if(f.actions.length){var n=a('<div class="'+g.item.actions+'"/>');n.appendTo(e),a.each(f.actions,function(c,d){var e=a('<button name="'+d.name+'" class="button-'+d.name+'">'+d.label+"</button>").button();e.bind("click",function(a){l?d.cb(a,l,b):d.cb(a,b)}),d.className&&e.addClass(d.className),n.append(e)})}h.bind("click",function(a){f.callbacks.onClick?f.callbacks.onClick(a,b):l||b.close()}),f.auto_show&&this.show(),this._setPosition(),i=c.push(this),k.append(h)},_calculatePositionForGravity:function(a,b,c,d){a.find("."+g.item.arrow).addClass(g.item.arrow+"_"+b);switch(b){case"TL":return{left:c.left,top:c.top+c.height+"px"};case"TR":return{left:c.left+c.width-d.width+"px",top:c.top+c.height+"px"};case"BL":return{left:c.left+"px",top:c.top-d.height+"px"};case"BR":return{left:c.left+c.width-d.width+"px",top:c.top-d.height+"px"};case"LT":return{left:c.left+c.width+"px",top:c.top+"px"};case"LB":return{left:c.left+c.width+"px",top:c.top+c.height-d.height+"px"};case"RT":return{left:c.left-d.width+"px",top:c.top+"px"};case"RB":return{left:c.left-d.width+"px",top:c.top+c.height-d.height+"px"};case"T":return{left:c.left+c.width/2-d.width/2+"px",top:c.top+c.height+"px"};case"R":return{left:c.left-d.width+"px",top:c.top+c.height/2-d.height/2+"px"};case"B":return{left:c.left+c.width/2-d.width/2+"px",top:c.top-d.height+"px"};case"L":return{left:c.left+c.width+"px",top:c.top+c.height/2-d.height/2+"px"}}},_isFixed:function(a){if(a===document)return!1;if(a.css("position")==="fixed")return!0;var b=a.offsetParent();return b.get(0)===a.get(0)?!1:this._isFixed(b)},_setPosition:function(){var b;if(f.bindTo){var d={width:h.width()?h.width():280,height:h.height()?h.height():109};j=a(f.bindTo);var e={},g={width:j.outerWidth(),height:j.outerHeight()};this._isFixed(j)?(e.position="fixed",g.left=j.offset().left,g.top=j.position().top):(e.position="absolute",g.left=j.offset().left,g.top=j.offset().top),b=this._calculatePositionForGravity(h,f.gravity,g,d),e.top=b.top,e.left=b.left,h.css(e);return}f.position||(f.position="top right");var i=a(".create-ui-toolbar-wrapper").outerHeight(!0)+6;b={position:"fixed"};var k,l=function(b){var c=0;return a.each(b,function(a,b){if(!b)return;c+=b.getElement().height()}),c};f.position.match(/top/)&&(b.top=i+l(c)+"px"),f.position.match(/bottom/)&&(b.bottom=c.length-1*k.height()+k.height()+10+"px"),f.position.match(/right/)&&(b.right="20px"),f.position.match(/left/)&&(b.left="20px"),h.css(b)},show:function(){var b=this,c,d,e,g,i,j;f.callbacks.beforeShow&&f.callbacks.beforeShow(b);if(f.bindTo){var k=a(f.bindTo);c=a(window).scrollTop(),d=a(window).scrollTop()+a(window).height(),g=parseFloat(h.offset().top,10),i=k.offset().top,j=k.outerHeight(),i<g&&(g=i),e=parseFloat(h.offset().top,10)+h.height(),i+j>e&&(e=i+j)}f.timeout>0&&!f.actions.length&&window.setTimeout(function(){b.close()},f.timeout),f.bindTo&&(g<c||g>d)||e<c||e>d?a("html, body").stop().animate({scrollTop:g},500,"easeInOutExpo",function(){f.effects.onShow(h,function(){f.callbacks.afterShow&&f.callbacks.afterShow(b)})}):f.effects.onShow(h,function(){f.callbacks.afterShow&&f.callbacks.afterShow(b)})},close:function(){var a=this;f.callbacks.beforeClose&&f.callbacks.beforeClose(a),f.effects.onHide(h,function(){f.callbacks.afterClose&&f.callbacks.afterClose(a),a.destroy()})},destroy:function(){var b=this;a.each(c,function(a,d){d&&d.getId()==b.getId()&&delete c[a]}),a(h).remove()},setStory:function(a){l=a},setName:function(a){h.addClass(g.item.wrapper+"-custom-"+a),this.name=a}};return m.constructor(d),delete m.constructor,m},e=function(b,c){var e={},f={},g={},h={},i=null,j=null,k=null,l=null,m={constructor:function(a){f=_.extend(e,a||{})},setStoryline:function(b){var c={content:"",actions:[],show_actions:!0,notification:{},back:null,back_label:null,forward:null,forward_label:null,beforeShow:null,afterShow:null,beforeClose:null,afterClose:null};g={},l=null,i=null,j=null,k=null;var d=this;return a.each(b,function(b,e){var f=a.extend({},c,e);f.name=b;var h=a.extend({},c.notification,e.notification||{});h.body=f.content,h.auto_show=!1,f.actions.length&&(h.delay=0),h.callbacks={beforeShow:function(a){f.beforeShow&&f.beforeShow(a,d)},afterShow:function(a){f.afterShow&&f.afterShow(a,d)},beforeClose:function(a){f.beforeClose&&f.beforeClose(a,d)},afterClose:function(a){f.afterClose&&f.afterClose(a,d),i=a.name}},h.actions=[];if(f.show_actions){if(f.back){var l=f.back_label;l||(l="Back"),h.actions.push({name:"back",label:l,cb:function(a,b,c){b.previous()}})}if(f.forward){var m=f.forward_label;m||(m="Back"),h.actions.push({name:"forward",label:m,cb:function(a,b,c){b.next()}})}f.actions.length&&a.each(f.actions,function(a,b){h.actions.push(f.actions[a])})}j||(j=b),k=b,f.notification=h,g[b]=f}),g},start:function(){this._showNotification(g[j])},stop:function(){l.close(),l=null,i=null},next:function(){l.close();if(g[l.name].forward){var a=g[l.name].forward;this._showNotification(g[a])}else this._showNotification(g[k])},previous:function(){if(i){l.close();if(g[l.name].back){var a=g[l.name].back;this._showNotification(g[a])}else this._showNotification(g[i])}else this.stop()},_showNotification:function(b){return l=new d(a("body"),b.notification),l.setStory(this),l.setName(b.name),l.show(),l}};return m.constructor(b),delete m.constructor,c&&m.setStoryline(c),m},f={start:{content:"Welcome to CreateJS tutorial!",forward:"toolbar_toggle",forward_label:"Start tutorial",actions:[{name:"quit",label:"Quit",cb:function(a,b,c){b.stop()}}]},toolbar_toggle:{content:"This is the CreateJS toolbars toggle button.<br />You can hide and show the full toolbar by clicking here.<br />Try it now.",forward:"edit_button",show_actions:!1,afterShow:function(b,c){a("body").bind("midgardtoolbarstatechange",function(b,d){d.display=="full"&&(c.next(),a("body").unbind("midgardtoolbarstatechange"))})},notification:{bindTo:"#midgard-bar-hidebutton",timeout:0,gravity:"TL"}},edit_button:{content:"This is the edit button.<br />Try it now.",show_actions:!1,afterShow:function(b,c){a("body").bind("midgardcreatestatechange",function(b,d){d.state=="edit"&&(c.next(),a("body").unbind("midgardcreatestatechange"))})},notification:{bindTo:".ui-button[for=midgardcreate-edit]",timeout:0,gravity:"TL"}},end:{content:"Thank you for watching!<br />Happy content editing times await you!"}};a.widget("Midgard.midgardNotifications",{options:{notification_defaults:{class_prefix:"midgardNotifications",position:"top right"}},_create:function(){this.classes={container:this.options.notification_defaults.class_prefix+"-container"},a("."+this.classes.container,this.element).length?(this.container=a("."+this.classes.container,this.element),this._parseFromDOM()):(this.container=a('<div class="'+this.classes.container+'" />'),this.element.append(this.container))},destroy:function(){this.container.remove(),a.Widget.prototype.destroy.call(this)},_init:function(){},_parseFromDOM:function(a){},showStory:function(a,b){var c=new e(a,b);return c.start(),c},create:function(b){b=a.extend({},this.options.notification_defaults,b||{});var c=new d(this.container,b);return c.show(),c},showTutorial:function(){this.showStory({},f)}})}(jQuery),function(a,b){"use strict",a.widget("Midgard.midgardStorage",{saveEnabled:!0,options:{localStorage:!1,removeLocalstorageOnIgnore:!0,vie:null,url:"",autoSave:!1,autoSaveInterval:5e3,saveReferencedNew:!1,saveReferencedChanged:!1,editableNs:"midgardeditable",editSelector:"#midgardcreate-edit a",saveSelector:"#midgardcreate-save",localize:function(a,b){return window.midgardCreate.localize(a,b)},language:null},_create:function(){var b=this;this.changedModels=[],window.localStorage&&(this.options.localStorage=!0),this.vie=this.options.vie,this.vie.entities.bind("add",function(a){a.url=b.options.url,a.toJSON=a.toJSONLD}),a(b.options.saveSelector).click(function(){b.saveRemote({success:function(){a(b.options.saveSelector).button({disabled:!0})},error:function(){}})}),b._bindEditables(),b.options.autoSave&&b._autoSave()},_autoSave:function(){var b=this;b.saveEnabled=!0;var c=function(){if(!b.saveEnabled)return;if(b.changedModels.length===0)return;b.saveRemote({success:function(){a(b.options.saveSelector).button({disabled:!0})},error:function(){}})},d=window.setInterval(c,b.options.autoSaveInterval);this.element.bind("startPreventSave",function(){d&&(window.clearInterval(d),d=null),b.disableSave()}),this.element.bind("stopPreventSave",function(){d||(d=window.setInterval(c,b.options.autoSaveInterval)),b.enableSave()})},enableSave:function(){this.saveEnabled=!0},disableSave:function(){this.saveEnabled=!1},_bindEditables:function(){var b=this;this.restorables=[];var c;b.element.bind(b.options.editableNs+"changed",function(c,d){_.indexOf(b.changedModels,d.instance)===-1&&b.changedModels.push(d.instance),b._saveLocal(d.instance),a(b.options.saveSelector).button({disabled:!1})}),b.element.bind(b.options.editableNs+"disable",function(c,d){b._restoreLocal(d.instance),a(b.options.saveSelector).hide()}),b.element.bind(b.options.editableNs+"enable",function(c,d){a(b.options.saveSelector).button({disabled:!0}),a(b.options.saveSelector).show(),d.instance._originalAttributes||(d.instance._originalAttributes=_.clone(d.instance.attributes)),!d.instance.isNew()&&b._checkLocal(d.instance)&&b.restorables.push(d.instance)}),b.element.bind("midgardcreatestatechange",function(a,d){if(d.state==="browse"||b.restorables.length===0){b.restorables=[],c&&c.close();return}c=b.checkRestore()}),b.element.bind("midgardstorageloaded",function(c,d){_.indexOf(b.changedModels,d.instance)===-1&&b.changedModels.push(d.instance),a(b.options.saveSelector).button({disabled:!1})})},checkRestore:function(){var b=this;if(b.restorables.length===0)return;var c=a("body").midgardNotifications("create",{bindTo:b.options.editSelector,gravity:"TR",body:_.template(b.options.localize("localModifications",b.options.language),{number:b.restorables.length}),timeout:0,actions:[{name:"restore",label:b.options.localize("Restore",b.options.language),cb:function(){_.each(b.restorables,function(a){b._readLocal(a)}),b.restorables=[]},className:"create-ui-btn"},{name:"ignore",label:b.options.localize("Ignore",b.options.language),cb:function(a,c){b.options.removeLocalstorageOnIgnore&&_.each(b.restorables,function(a){b._removeLocal(a)}),c.close(),b.restorables=[]},className:"create-ui-btn"}]});return c},saveRemote:function(b){var c=this;if(c.changedModels.length===0)return;c._trigger("save",null,{models:c.changedModels});var d,e=c.changedModels.length;e>1?d=_.template(c.options.localize("saveSuccessMultiple",c.options.language),{number:e}):d=_.template(c.options.localize("saveSuccess",c.options.language),{label:c.changedModels[0].getSubjectUri()}),c.disableSave(),_.each(c.changedModels,function(f){_.each(f.attributes,function(a,b){if(!a||!a.isCollection)return;a.each(function(a){if(c.changedModels.indexOf(a)!==-1)return;if(a.isNew()&&c.options.saveReferencedNew)return a.save();if(a.hasChanged()&&c.options.saveReferencedChanged)return a.save()})}),f.save(null,{success:function(){f._originalAttributes=_.clone(f.attributes),c._removeLocal(f),window.setTimeout(function(){c.changedModels.splice(c.changedModels.indexOf(f),1)},0),e--,e<=0&&(c._trigger("saved",null,{}),b.success(),a("body").midgardNotifications("create",{body:d}),c.enableSave())},error:function(d,e){b.error(),a("body").midgardNotifications("create",{body:_.template(c.options.localize("saveError",c.options.language),{error:e.responseText||""}),timeout:0}),c._trigger("error",null,{instance:f})}})})},_saveLocal:function(a){if(!this.options.localStorage)return;if(a.isNew()){if(!a.primaryCollection)return;return this._saveLocalReferences(a.primaryCollection
+.subject,a.primaryCollection.predicate,a)}window.localStorage.setItem(a.getSubjectUri(),JSON.stringify(a.toJSONLD()))},_getReferenceId:function(a,b){return a.id+":"+b},_saveLocalReferences:function(a,b,c){if(!this.options.localStorage)return;if(!a||!b)return;var d=this,e=a+":"+b,f=c.toJSONLD();if(window.localStorage.getItem(e)){var g=JSON.parse(window.localStorage.getItem(e)),h=_.pluck(g,"@").indexOf(f["@"]);h!==-1?g[h]=f:g.push(f),window.localStorage.setItem(e,JSON.stringify(g));return}window.localStorage.setItem(e,JSON.stringify([f]))},_checkLocal:function(a){if(!this.options.localStorage)return!1;var b=window.localStorage.getItem(a.getSubjectUri());return b?!0:!1},_readLocal:function(a){if(!this.options.localStorage)return;var b=window.localStorage.getItem(a.getSubjectUri());if(!b)return;a._originalAttributes||(a._originalAttributes=_.clone(a.attributes));var c=JSON.parse(b),d=this.vie.entities.addOrUpdate(c,{overrideAttributes:!0});this._trigger("loaded",null,{instance:d})},_readLocalReferences:function(a,b,c){if(!this.options.localStorage)return;var d=this._getReferenceId(a,b),e=window.localStorage.getItem(d);if(!e)return;c.add(JSON.parse(e))},_restoreLocal:function(a){var b=this;if(!a)return;_.each(a.attributes,function(a,c){if(a instanceof b.vie.Collection){var d=[];a.forEach(function(a){a.isNew()&&d.push(a)}),a.remove(d)}});if(!a.changedAttributes()){a._originalAttributes&&a.set(a._originalAttributes);return}a.set(a.previousAttributes())},_removeLocal:function(a){if(!this.options.localStorage)return;window.localStorage.removeItem(a.getSubjectUri())}})}(jQuery),function(a,b){"use strict",a.widget("Midgard.midgardTags",{enhanced:!1,options:{vie:null,entity:null,element:null,entityElement:null,parentElement:".create-ui-tool-metadataarea",predicate:"skos:related",templates:{button:'<button class="create-ui-btn"><i class="icon-<%= icon %>"></i> <%= label %></button>',contentArea:'<div class="dropdown-menu"></div>',tags:'<div class="create-ui-tags <%= type %>Tags"><h3><%= label %></h3><input type="text" class="tags" value="" /></div>'},localize:function(a,b){return window.midgardCreate.localize(a,b)},language:null},_init:function(){var b=this;this.vie=this.options.vie,this.entity=this.options.entity,this.element=this.options.element,a(this.options.entityElement).bind("midgardeditableactivated",function(a,c){if(c.instance!==b.options.entity)return;b._renderWidget(),b.loadTags()}),a(this.options.entityElement).bind("midgardeditablechanged",function(a,c){if(c.instance!==b.options.entity)return;b.enhanced=!1}),this._listenAnnotate(this.options.entityElement)},_normalizeSubject:function(a){return this.entity.isReference(a)?a:(a.substr(0,7)!=="http://"&&(a="urn:tag:"+a),a=this.entity.toReference(a),a)},_tagLabel:function(a){return a=this.entity.fromReference(a),a.substr(0,8)==="urn:tag:"&&(a=a.substr(8,a.length-1)),a.substring(0,7)=="http://"&&(a=a.substr(a.lastIndexOf("/")+1,a.length-1),a=a.replace(/_/g," ")),a},addTag:function(a,c,d){c===b&&(c=this._tagLabel(a)),a=this._normalizeSubject(a),d&&!this.entity.isReference(d)&&(d=this.entity.toReference(d));var e=this.vie.entities.addOrUpdate({"@subject":a,"rdfs:label":c,"@type":d}),f=this.options.entity.get(this.options.predicate);f?f.isCollection||(f=new this.vie.Collection(_.map(f,function(a){return a.isEntity?a:{"@subject":a}})),f.vie=this.options.vie,this.options.entity.set(this.options.predicate,f)):(f=new this.vie.Collection,f.vie=this.options.vie,this.options.entity.set(this.options.predicate,f)),f.addOrUpdate(e),this.options.entityElement.trigger("midgardeditablechanged",{instance:this.options.entity})},removeTag:function(a){var b=this.options.entity.get(this.options.predicate);if(!b)return;a=this._normalizeSubject(a);var c=b.get(a);if(!c)return;b.remove(a),this.options.entityElement.trigger("midgardeditablechanged",{instance:this.options.entity})},_listenAnnotate:function(a){var b=this;a.bind("annotateselect",function(a,c){b.addTag(c.linkedEntity.uri,c.linkedEntity.label,c.linkedEntity.type[0])}),a.bind("annotateremove",function(a,c){b.removeTag(c.linkedEntity.uri)})},_prepareEditor:function(b){var c=a(_.template(this.options.templates.contentArea,{})),d=a(_.template(this.options.templates.tags,{type:"article",label:this.options.localize("Item tags",this.options.language)})),e=a(_.template(this.options.templates.tags,{type:"suggested",label:this.options.localize("Suggested tags",this.options.language)}));a("input",d).attr("id","articleTags-"+this.entity.cid),a("input",e).attr("id","suggestedTags-"+this.entity.cid),c.append(d),c.append(e),c.hide();var f=b.position();return c.css("position","absolute"),c.css("left",f.left),c},_renderWidget:function(){var b=this,c=this.entity.getSubject(),d=a(_.template(this.options.templates.button,{icon:"tags",label:this.options.localize("Tags",this.options.language)})),e=a(this.options.parentElement);e.empty(),e.append(d),e.show();var f=this._prepareEditor(d);d.after(f),this.articleTags=a(".articleTags input",f).tagsInput({width:"auto",height:"auto",onAddTag:function(a){b.addTag(a)},onRemoveTag:function(a){b.removeTag(a)},defaultText:this.options.localize("add a tag",this.options.language)});var g=function(){var c=a.trim(a(this).text());b.articleTags.addTag(c),b.suggestedTags.removeTag(c)};this.suggestedTags=a(".suggestedTags input",f).tagsInput({width:"auto",height:"auto",interactive:!1,onAddTag:function(b){a(".suggestedTags .tag span",f).unbind("click",g),a(".suggestedTags .tag span",f).bind("click",g)},onRemoveTag:function(b){a(".suggestedTags .tag span",f).unbind("click",g),a(".suggestedTags .tag span",f).bind("click",g)},remove:!1}),d.bind("click",function(){f.toggle()})},loadTags:function(){var b=this,c=this.entity.get(this.options.predicate);c&&(_.isString(c)?b.articleTags.addTag(b._tagLabel(c)):c.isCollection?c.each(function(a){b.articleTags.addTag(a.get("rdfs:label"))}):_.each(c,function(a){b.articleTags.addTag(b._tagLabel(a))})),this.vie.services.stanbol?b.enhance():a(".suggestedTags",b.element).hide()},_getLabelLang:function(a){if(!_.isArray(a))return null;var b;return _.each(a,function(a){a["@language"]==="en"&&(b=a["@value"])}),b},_addEnhancement:function(a){if(!a.isEntity)return;var b=this._getLabelLang(a.get("rdfs:label"));if(!b)return;var c=this.options.entity.get(this.options.predicate);if(c&&c.isCollection&&c.indexOf(a)!==-1)return;this.suggestedTags.addTag(b)},enhance:function(){if(this.enhanced)return;this.enhanced=!0;var b=this;this.vie.analyze({element:a("[property]",this.options.entityElement)}).using(["stanbol"]).execute().success(function(a){_.each(a,function(a){b._addEnhancement(a)})}).fail(function(a){})}})}(jQuery),function(a,b){"use strict",a.widget("Midgard.midgardToolbar",{options:{display:"full",templates:{minimized:'<div class="create-ui-logo"><a class="create-ui-toggle" id="create-ui-toggle-toolbar"></a></div>',full:'<div class="create-ui-toolbar-wrapper"><div class="create-ui-toolbar-toolarea"><%= dynamic %><%= status %></div></div>',toolcontainer:'<div class="create-ui-toolbar-<%= name %>toolarea"><ul class="create-ui-<%= name %>tools"><%= content %></ul></div>',toolarea:'<li class="create-ui-tool-<%= name %>area"></li>'}},_create:function(){this.element.append(this._getMinimized()),this.element.append(this._getFull());var b=this;a(".create-ui-toggle",this.element).click(function(){b.options.display==="full"?b.setDisplay("minimized"):b.setDisplay("full")}),a(this.element).bind("midgardcreatestatechange",function(a,c){c.state=="browse"&&(b._clearWorkflows(),b._clearMetadata())}),a(this.element).bind("midgardworkflowschanged",function(c,d){b._clearWorkflows(),d.workflows.length&&d.workflows.each(function(c){var e=a("body").data().midgardWorkflows.prepareItem(d.instance,c,function(a,c){b._clearWorkflows();if(a)return});a(".create-ui-tool-workflowarea",this.element).append(e)})})},_init:function(){this.setDisplay(this.options.display)},setDisplay:function(a){if(a===this.options.display)return;a==="minimized"?(this.hide(),this.options.display="minimized"):(this.show(),this.options.display="full"),this._trigger("statechange",null,this.options)},hide:function(){a("div.create-ui-toolbar-wrapper").fadeToggle("fast","linear")},show:function(){a("div.create-ui-toolbar-wrapper").fadeToggle("fast","linear")},_getMinimized:function(){return a(_.template(this.options.templates.minimized,{}))},_getFull:function(){return a(_.template(this.options.templates.full,{dynamic:_.template(this.options.templates.toolcontainer,{name:"dynamic",content:_.template(this.options.templates.toolarea,{name:"metadata"})+_.template(this.options.templates.toolarea,{name:"workflow"})+_.template(this.options.templates.toolarea,{name:"free"})}),status:_.template(this.options.templates.toolcontainer,{name:"status",content:""})}))},_clearWorkflows:function(){a(".create-ui-tool-workflowarea",this.element).empty()},_clearMetadata:function(){a(".create-ui-tool-metadataarea",this.element).empty()}})}(jQuery),function(a,b){"use strict",a.widget("Midgard.midgardWorkflows",{options:{url:function(a){},templates:{button:'<button class="create-ui-btn" id="<%= id %>"><%= label %></button>'},renderers:{button:function(b,c,d,e){var f="midgardcreate-workflow_"+c.get("name"),g=a(_.template(this.options.templates.button,{id:f,label:c.get("label")})).button();return g.bind("click",function(a){d(b,c,e)}),g}},action_types:{backbone_save:function(a,b,c){var d=a.url,e=a.clone();e.url=d;var f=b.get("action");f.url&&(a.url=f.url),e.save(null,{success:function(b){a.url=d,a.change(),c(null,a)},error:function(b,e){a.url=d,a.change(),c(e,a)}})},backbone_destroy:function(a,b,c){var d=a.url,e=a.clone();e.url=d;var f=b.get("action");f.url&&(a.url=f.url),a.destroy({success:function(b){a.url=d,a.change(),c(null,b)},error:function(b,e){a.url=d,a.change(),c(e,a)}})},http:function(b,c,d){var e=c.get("action");if(!e.url)return d("No action url defined!");var f={};e.http&&(f=e.http);var g=a.extend({url:e.url,type:"POST",data:b.toJSON(),success:function(){b.fetch({success:function(a){d(null,a)},error:function(a,b){d(b,a)}})}},f);a.ajax(g)}}},_init:function(){this._renderers={},this._action_types={},this._parseRenderersAndTypes(),this._last_instance=null,this.ModelWorkflowModel=Backbone.Model.extend({defaults:{name:"",label:"",type:"button",action:{type:"backbone_save"}}}),this.workflows={};var b=this;a(this.element).bind("midgardeditableactivated",function(a,c){b._fetchWorkflows(c.instance)})},_fetchWorkflows:function(a){var b=this;if(a.isNew()){b._trigger("changed",null,{instance:a,workflows:[]});return}if(b._last_instance==a){b.workflows[a.cid]&&b._trigger("changed",null,{instance:a,workflows:b.workflows[a.cid]});return}b._last_instance=a;if(b.workflows[a.cid]){b._trigger("changed",null,{instance:a,workflows:b.workflows[a.cid]});return}if(b.options.url)b._fetchModelWorkflows(a);else{var c=new(b._generateCollectionFor(a))([],{});b._trigger("changed",null,{instance:a,workflows:c})}},_parseRenderersAndTypes:function(){var b=this;a.each(this.options.renderers,function(a,c){b.setRenderer(a,c)}),a.each(this.options.action_types,function(a,c){b.setActionType(a,c)})},setRenderer:function(a,b){this._renderers[a]=b},getRenderer:function(a){return this._renderers[a]?this._renderers[a]:!1},setActionType:function(a,b){this._action_types[a]=b},getActionType:function(a){return this._action_types[a]},prepareItem:function(a,b,c){var d=this,e=this.getRenderer(b.get("type")),f=this.getActionType(b.get("action").type);return e.call(this,a,b,f,function(e,f){delete d.workflows[a.cid],d._last_instance=null,b.get("action").type!=="backbone_destroy"&&d._fetchModelWorkflows(a),c(e,f)})},_generateCollectionFor:function(a){var b={model:this.ModelWorkflowModel};return this.options.url&&(b.url=this.options.url(a)),Backbone.Collection.extend(b)},_fetchModelWorkflows:function(a){if(a.isNew())return;var b=this;b.workflows[a.cid]=new(this._generateCollectionFor(a))([],{}),b.workflows[a.cid].fetch({success:function(c){b.workflows[a.cid].reset(c.models),b._trigger("changed",null,{instance:a,workflows:b.workflows[a.cid]})},error:function(a,b){}})}})}(jQuery),window.midgardCreate===undefined&&(window.midgardCreate={}),window.midgardCreate.localize=function(a,b){return window.midgardCreate.locale?window.midgardCreate.locale[b]&&window.midgardCreate.locale[b][a]?window.midgardCreate.locale[b][a]:window.midgardCreate.locale.en[a]?window.midgardCreate.locale.en[a]:a:a};
View
165 examples/create.js
@@ -1,3 +1,61 @@
+if (window.midgardCreate === undefined) {
+ window.midgardCreate = {};
+}
+if (window.midgardCreate.locale === undefined) {
+ window.midgardCreate.locale = {};
+}
+
+window.midgardCreate.locale.en = {
+ // Session-state buttons for the main toolbar
+ 'Save': 'Save',
+ 'Saving': 'Saving',
+ 'Cancel': 'Cancel',
+ 'Edit': 'Edit',
+ // Storage status messages
+ 'localModifications': '<%= number %> items on this page have local modifications',
+ 'Restore': 'Restore',
+ 'Ignore': 'Ignore',
+ 'saveSuccess': 'Item "<%= label %>" saved successfully',
+ 'saveSuccessMultiple': '<%= number %> items saved successfully',
+ 'saveError': 'Error occurred while saving<br /><%= error %>',
+ // Tagging
+ 'Item tags': 'Item tags',
+ 'Suggested tags': 'Suggested tags',
+ 'Tags': 'Tags',
+ 'add a tag': 'add a tag',
+ // Collection widgets
+ 'Add': 'Add',
+ 'Choose type to add': 'Choose type to add'
+};
+if (window.midgardCreate === undefined) {
+ window.midgardCreate = {};
+}
+if (window.midgardCreate.locale === undefined) {
+ window.midgardCreate.locale = {};
+}
+
+window.midgardCreate.locale.fi = {
+ // Session-state buttons for the main toolbar
+ 'Save': 'Tallenna',
+ 'Saving': 'Tallennetaan',
+ 'Cancel': 'Peruuta',
+ 'Edit': 'Muokkaa',
+ // Storage status messages
+ 'localModifications': '<%= number %> oliota sivulla omaa paikallisia muutoksia',
+ 'Restore': 'Palauta',
+ 'Ignore': 'Poista',
+ 'saveSuccess': 'Olio "<%= label %>" tallennettu',
+ 'saveSuccessMultiple': '<%= number %> oliota tallennettu',
+ 'saveError': 'Virhe tallennettaessa<br /><%= error %>',
+ // Tagging
+ 'Item tags': 'Avainsanat',
+ 'Suggested tags': 'Ehdotukset',
+ 'Tags': 'Avainsanat',
+ 'add a tag': 'lisää avainsana',
+ // Collection widgets
+ 'Add': 'Lisää',
+ 'Choose type to add': 'Mitä haluat lisätä?'
+};
// Create.js 1.0.0alpha3 - On-site web editing interface
// (c) 2011-2012 Henri Bergius, IKS Consortium
// Create may be freely distributed under the MIT license.
@@ -80,7 +138,15 @@
templates: {
buttonContent: '<%= label %> <i class="icon-<%= icon %>"></i>',
button: '<li id="<%= id %>"><a class="create-ui-btn"><%= buttonContent %></a></li>'
- }
+ },
+ // Localization callback function. Will be run in the widget context.
+ // Override to connect Create.js with your own localization system
+ localize: function (id, language) {
+ return window.midgardCreate.localize(id, language);
+ },
+ // Language used for Create.js. Will be retrieved from page lang attrib
+ // if left blank
+ language: null
},
_create: function () {
@@ -91,6 +157,10 @@
widget._checkSession();
}, 10);
+ if (!this.options.language) {
+ this.options.language = jQuery('html').attr('lang');
+ }
+
this._enableToolbar();
this._saveButton();
this._editButton();
@@ -161,20 +231,22 @@
_prepareStorage: function () {
this.element.midgardStorage({
vie: this.vie,
- url: this.options.url
+ url: this.options.url,
+ localize: this.options.localize,
+ language: this.options.language
});
var widget = this;
this.element.bind('midgardstoragesave', function () {
jQuery('#midgardcreate-save a').html(_.template(widget.options.templates.buttonContent, {
- label: 'Saving',
+ label: widget.options.localize('Saving', widget.options.language),
icon: 'upload'
}));
});
this.element.bind('midgardstoragesaved midgardstorageerror', function () {
jQuery('#midgardcreate-save a').html(_.template(widget.options.templates.buttonContent, {
- label: 'Save',
+ label: widget.options.localize('Save', widget.options.language),
icon: 'ok'
}));
});
@@ -252,10 +324,11 @@
if (this.options.saveButton) {
return this.options.saveButton;
}
+ var widget = this;
jQuery(this.options.buttonContainer, this.element).append(jQuery(_.template(this.options.templates.button, {
id: 'midgardcreate-save',
buttonContent: _.template(this.options.templates.buttonContent, {
- label: 'Save',
+ label: widget.options.localize('Save', widget.options.language),
icon: 'ok'
})
})));
@@ -280,13 +353,14 @@
},
_setEditButtonState: function (state) {
+ var widget = this;
var buttonContents = {
edit: _.template(this.options.templates.buttonContent, {
- label: 'Cancel',
+ label: widget.options.localize('Cancel', widget.options.language),
icon: 'remove'
}),
browse: _.template(this.options.templates.buttonContent, {
- label: 'Edit',
+ label: widget.options.localize('Edit', widget.options.language),
icon: 'edit'
})
};
@@ -324,7 +398,9 @@
vie: widget.vie,
widgets: widget.options.editorWidgets,
editors: widget.options.editorOptions,
- collectionWidgets: widget.options.collectionWidgets
+ collectionWidgets: widget.options.collectionWidgets,
+ localize: widget.options.localize,
+ language: widget.options.language
};
if (widget.options.enableEditor) {
editableOptions.enableEditor = widget.options.enableEditor;
@@ -368,7 +444,9 @@
jQuery(this).midgardTags({
vie: widget.vie,
entityElement: options.entityElement,
- entity: options.instance
+ entity: options.instance,
+ localize: widget.options.localize,
+ language: widget.options.language
});
});
}
@@ -386,7 +464,9 @@
var editableOptions = {
disabled: true,
vie: widget.vie,
- editorOptions: widget.options.editorOptions
+ editorOptions: widget.options.editorOptions,
+ localize: widget.options.localize,
+ language: widget.options.language
};
jQuery('[about]', this.element).each(function () {
jQuery(this).midgardEditable(editableOptions);
@@ -520,7 +600,7 @@
var addButton = jQuery(_.template(this.options.templates.button, {
icon: 'plus',
- label: 'Add'
+ label: this.options.editableOptions.localize('Add', this.options.editableOptions.language)
})).button();
addButton.addClass('midgard-create-add');
addButton.click(function () {
@@ -572,7 +652,7 @@
jQuery('body').midgardNotifications('create', {
bindTo: button,
gravity: 'L',
- body: 'Choose type to add',
+ body: this.options.editableOptions.localize('Choose type to add', this.options.editableOptions.language),
timeout: 0,
actions: this._getTypeActions(options)
});
@@ -686,7 +766,11 @@
},
toolbarState: 'full',
vie: null,
- disabled: false
+ disabled: false,
+ localize: function (id, language) {
+ return window.midgardCreate.localize(id, language);
+ },
+ language: null
},
_create: function () {
@@ -1958,13 +2042,10 @@
editSelector: '#midgardcreate-edit a',
// CSS selector for the Save button
saveSelector: '#midgardcreate-save',
- // Templates used for dialog output
- templates: {
- localModifications: '<%= number %> items on this page have local modifications',
- saveSuccess: 'Item "<%= label %>" saved successfully',
- saveSuccessMultiple: '<%= number %> items saved successfully',
- saveError: 'Error occurred while saving<br /><%= error %>'
- }
+ localize: function (id, language) {
+ return window.midgardCreate.localize(id, language);
+ },
+ language: null
},
_create: function () {
@@ -2117,14 +2198,14 @@
var restorer = jQuery('body').midgardNotifications('create', {
bindTo: widget.options.editSelector,
gravity: 'TR',
- body: _.template(widget.options.templates.localModifications, {
+ body: _.template(widget.options.localize('localModifications', widget.options.language), {
number: widget.restorables.length
}),
timeout: 0,
actions: [
{
name: 'restore',
- label: 'Restore',
+ label: widget.options.localize('Restore', widget.options.language),
cb: function() {
_.each(widget.restorables, function (instance) {
widget._readLocal(instance);
@@ -2135,7 +2216,7 @@
},
{
name: 'ignore',
- label: 'Ignore',
+ label: widget.options.localize('Ignore', widget.options.language),
cb: function(event, notification) {
if (widget.options.removeLocalstorageOnIgnore) {
_.each(widget.restorables, function (instance) {
@@ -2165,11 +2246,11 @@
var notification_msg;
var needed = widget.changedModels.length;
if (needed > 1) {
- notification_msg = _.template(widget.options.templates.saveSuccessMultiple, {
+ notification_msg = _.template(widget.options.localize('saveSuccessMultiple', widget.options.language), {
number: needed
});
} else {
- notification_msg = _.template(widget.options.templates.saveSuccess, {
+ notification_msg = _.template(widget.options.localize('saveSuccess', widget.options.language), {
label: widget.changedModels[0].getSubjectUri()
});
}
@@ -2222,7 +2303,7 @@
error: function (m, err) {
options.error();
jQuery('body').midgardNotifications('create', {
- body: _.template(widget.options.templates.saveError, {
+ body: _.template(widget.options.localize('saveError', widget.options.language), {
error: err.responseText || ''
}),
timeout: 0
@@ -2390,7 +2471,11 @@
button: '<button class="create-ui-btn"><i class="icon-<%= icon %>"></i> <%= label %></button>',
contentArea: '<div class="dropdown-menu"></div>',
tags: '<div class="create-ui-tags <%= type %>Tags"><h3><%= label %></h3><input type="text" class="tags" value="" /></div>'
- }
+ },
+ localize: function (id, language) {
+ return window.midgardCreate.localize(id, language);
+ },
+ language: null
},
_init: function () {
@@ -2526,11 +2611,11 @@
var contentArea = jQuery(_.template(this.options.templates.contentArea, {}));
var articleTags = jQuery(_.template(this.options.templates.tags, {
type: 'article',
- label: 'Item tags'
+ label: this.options.localize('Item tags', this.options.language)
}));
var suggestedTags = jQuery(_.template(this.options.templates.tags, {
type: 'suggested',
- label: 'Suggested tags'
+ label: this.options.localize('Suggested tags', this.options.language)
}));
// Tags plugin requires IDs to exist
@@ -2554,7 +2639,7 @@
var button = jQuery(_.template(this.options.templates.button, {
icon: 'tags',
- label: 'Tags'
+ label: this.options.localize('Tags', this.options.language)
}));
var parentElement = jQuery(this.options.parentElement);
@@ -2573,7 +2658,8 @@
},
onRemoveTag: function (tag) {
widget.removeTag(tag);
- }
+ },
+ defaultText: this.options.localize('add a tag', this.options.language)
});
var selectSuggested = function () {
@@ -3053,3 +3139,20 @@
}
});
})(jQuery);
+if (window.midgardCreate === undefined) {
+ window.midgardCreate = {};
+}
+
+window.midgardCreate.localize = function (id, language) {
+ if (!window.midgardCreate.locale) {
+ // No localization files loaded, return as-is
+ return id;
+ }
+ if (window.midgardCreate.locale[language] && window.midgardCreate.locale[language][id]) {
+ return window.midgardCreate.locale[language][id];
+ }
+ if (window.midgardCreate.locale.en[id]) {
+ return window.midgardCreate.locale.en[id];
+ }
+ return id;
+};
View
2 examples/example.html
@@ -1,5 +1,5 @@
<!DOCTYPE html>
-<html>
+<html lang="fi">
<head>
<meta charset="utf-8" />
<title>Midgard Create example</title>
View
29 locale/en.js
@@ -0,0 +1,29 @@
+if (window.midgardCreate === undefined) {
+ window.midgardCreate = {};
+}
+if (window.midgardCreate.locale === undefined) {
+ window.midgardCreate.locale = {};
+}
+
+window.midgardCreate.locale.en = {
+ // Session-state buttons for the main toolbar
+ 'Save': 'Save',
+ 'Saving': 'Saving',
+ 'Cancel': 'Cancel',
+ 'Edit': 'Edit',
+ // Storage status messages
+ 'localModifications': '<%= number %> items on this page have local modifications',
+ 'Restore': 'Restore',
+ 'Ignore': 'Ignore',
+ 'saveSuccess': 'Item "<%= label %>" saved successfully',
+ 'saveSuccessMultiple': '<%= number %> items saved successfully',
+ 'saveError': 'Error occurred while saving<br /><%= error %>',
+ // Tagging
+ 'Item tags': 'Item tags',
+ 'Suggested tags': 'Suggested tags',
+ 'Tags': 'Tags',
+ 'add a tag': 'add a tag',
+ // Collection widgets
+ 'Add': 'Add',
+ 'Choose type to add': 'Choose type to add'
+};
View
29 locale/fi.js
@@ -0,0 +1,29 @@
+if (window.midgardCreate === undefined) {
+ window.midgardCreate = {};
+}
+if (window.midgardCreate.locale === undefined) {
+ window.midgardCreate.locale = {};
+}
+
+window.midgardCreate.locale.fi = {
+ // Session-state buttons for the main toolbar
+ 'Save': 'Tallenna',
+ 'Saving': 'Tallennetaan',
+ 'Cancel': 'Peruuta',
+ 'Edit': 'Muokkaa',
+ // Storage status messages
+ 'localModifications': '<%= number %> oliota sivulla omaa paikallisia muutoksia',
+ 'Restore': 'Palauta',
+ 'Ignore': 'Poista',
+ 'saveSuccess': 'Olio "<%= label %>" tallennettu',
+ 'saveSuccessMultiple': '<%= number %> oliota tallennettu',
+ 'saveError': 'Virhe tallennettaessa<br /><%= error %>',
+ // Tagging
+ 'Item tags': 'Avainsanat',
+ 'Suggested tags': 'Ehdotukset',
+ 'Tags': 'Avainsanat',
+ 'add a tag': 'lisää avainsana',
+ // Collection widgets
+ 'Add': 'Lisää',
+ 'Choose type to add': 'Mitä haluat lisätä?'
+};
View
4 src/collectionWidgets/jquery.Midgard.midgardCreateCollectionAdd.js
@@ -119,7 +119,7 @@
var addButton = jQuery(_.template(this.options.templates.button, {
icon: 'plus',
- label: 'Add'
+ label: this.options.editableOptions.localize('Add', this.options.editableOptions.language)
})).button();
addButton.addClass('midgard-create-add');
addButton.click(function () {
@@ -171,7 +171,7 @@
jQuery('body').midgardNotifications('create', {
bindTo: button,
gravity: 'L',
- body: 'Choose type to add',
+ body: this.options.editableOptions.localize('Choose type to add', this.options.editableOptions.language),
timeout: 0,
actions: this._getTypeActions(options)
});
View
42 src/jquery.Midgard.midgardCreate.js
@@ -80,7 +80,15 @@
templates: {
buttonContent: '<%= label %> <i class="icon-<%= icon %>"></i>',
button: '<li id="<%= id %>"><a class="create-ui-btn"><%= buttonContent %></a></li>'
- }
+ },
+ // Localization callback function. Will be run in the widget context.
+ // Override to connect Create.js with your own localization system
+ localize: function (id, language) {
+ return window.midgardCreate.localize(id, language);
+ },
+ // Language used for Create.js. Will be retrieved from page lang attrib
+ // if left blank
+ language: null
},
_create: function () {
@@ -91,6 +99,10 @@
widget._checkSession();
}, 10);
+ if (!this.options.language) {
+ this.options.language = jQuery('html').attr('lang');
+ }
+
this._enableToolbar();
this._saveButton();
this._editButton();
@@ -161,20 +173,22 @@
_prepareStorage: function () {
this.element.midgardStorage({
vie: this.vie,
- url: this.options.url
+ url: this.options.url,
+ localize: this.options.localize,
+ language: this.options.language
});
var widget = this;
this.element.bind('midgardstoragesave', function () {
jQuery('#midgardcreate-save a').html(_.template(widget.options.templates.buttonContent, {
- label: 'Saving',
+ label: widget.options.localize('Saving', widget.options.language),
icon: 'upload'
}));
});
this.element.bind('midgardstoragesaved midgardstorageerror', function () {
jQuery('#midgardcreate-save a').html(_.template(widget.options.templates.buttonContent, {
- label: 'Save',
+ label: widget.options.localize('Save', widget.options.language),
icon: 'ok'
}));
});
@@ -252,10 +266,11 @@
if (this.options.saveButton) {
return this.options.saveButton;
}
+ var widget = this;
jQuery(this.options.buttonContainer, this.element).append(jQuery(_.template(this.options.templates.button, {
id: 'midgardcreate-save',
buttonContent: _.template(this.options.templates.buttonContent, {
- label: 'Save',
+ label: widget.options.localize('Save', widget.options.language),
icon: 'ok'
})
})));
@@ -280,13 +295,14 @@
},
_setEditButtonState: function (state) {
+ var widget = this;
var buttonContents = {
edit: _.template(this.options.templates.buttonContent, {
- label: 'Cancel',
+ label: widget.options.localize('Cancel', widget.options.language),
icon: 'remove'
}),
browse: _.template(this.options.templates.buttonContent, {
- label: 'Edit',
+ label: widget.options.localize('Edit', widget.options.language),
icon: 'edit'
})
};
@@ -324,7 +340,9 @@
vie: widget.vie,
widgets: widget.options.editorWidgets,
editors: widget.options.editorOptions,
- collectionWidgets: widget.options.collectionWidgets
+ collectionWidgets: widget.options.collectionWidgets,
+ localize: widget.options.localize,
+ language: widget.options.language
};
if (widget.options.enableEditor) {
editableOptions.enableEditor = widget.options.enableEditor;
@@ -368,7 +386,9 @@
jQuery(this).midgardTags({
vie: widget.vie,
entityElement: options.entityElement,
- entity: options.instance
+ entity: options.instance,
+ localize: widget.options.localize,
+ language: widget.options.language
});
});
}
@@ -386,7 +406,9 @@
var editableOptions = {
disabled: true,
vie: widget.vie,
- editorOptions: widget.options.editorOptions
+ editorOptions: widget.options.editorOptions,
+ localize: widget.options.localize,
+ language: widget.options.language
};
jQuery('[about]', this.element).each(function () {
jQuery(this).midgardEditable(editableOptions);
View
6 src/jquery.Midgard.midgardEditable.js
@@ -29,7 +29,11 @@
},
toolbarState: 'full',
vie: null,
- disabled: false
+ disabled: false,
+ localize: function (id, language) {
+ return window.midgardCreate.localize(id, language);
+ },
+ language: null
},
_create: function () {
View
23 src/jquery.Midgard.midgardStorage.js
@@ -33,13 +33,10 @@
editSelector: '#midgardcreate-edit a',
// CSS selector for the Save button
saveSelector: '#midgardcreate-save',
- // Templates used for dialog output
- templates: {
- localModifications: '<%= number %> items on this page have local modifications',
- saveSuccess: 'Item "<%= label %>" saved successfully',
- saveSuccessMultiple: '<%= number %> items saved successfully',
- saveError: 'Error occurred while saving<br /><%= error %>'
- }
+ localize: function (id, language) {
+ return window.midgardCreate.localize(id, language);
+ },
+ language: null
},
_create: function () {
@@ -192,14 +189,14 @@
var restorer = jQuery('body').midgardNotifications('create', {
bindTo: widget.options.editSelector,
gravity: 'TR',
- body: _.template(widget.options.templates.localModifications, {
+ body: _.template(widget.options.localize('localModifications', widget.options.language), {
number: widget.restorables.length
}),
timeout: 0,
actions: [
{
name: 'restore',
- label: 'Restore',
+ label: widget.options.localize('Restore', widget.options.language),
cb: function() {
_.each(widget.restorables, function (instance) {
widget._readLocal(instance);
@@ -210,7 +207,7 @@
},
{
name: 'ignore',
- label: 'Ignore',
+ label: widget.options.localize('Ignore', widget.options.language),
cb: function(event, notification) {
if (widget.options.removeLocalstorageOnIgnore) {
_.each(widget.restorables, function (instance) {
@@ -240,11 +237,11 @@
var notification_msg;
var needed = widget.changedModels.length;
if (needed > 1) {
- notification_msg = _.template(widget.options.templates.saveSuccessMultiple, {
+ notification_msg = _.template(widget.options.localize('saveSuccessMultiple', widget.options.language), {
number: needed
});
} else {
- notification_msg = _.template(widget.options.templates.saveSuccess, {
+ notification_msg = _.template(widget.options.localize('saveSuccess', widget.options.language), {
label: widget.changedModels[0].getSubjectUri()
});
}
@@ -297,7 +294,7 @@
error: function (m, err) {
options.error();
jQuery('body').midgardNotifications('create', {
- body: _.template(widget.options.templates.saveError, {
+ body: _.template(widget.options.localize('saveError', widget.options.language), {
error: err.responseText || ''
}),
timeout: 0
View
15 src/jquery.Midgard.midgardTags.js
@@ -22,7 +22,11 @@
button: '<button class="create-ui-btn"><i class="icon-<%= icon %>"></i> <%= label %></button>',
contentArea: '<div class="dropdown-menu"></div>',
tags: '<div class="create-ui-tags <%= type %>Tags"><h3><%= label %></h3><input type="text" class="tags" value="" /></div>'
- }
+ },
+ localize: function (id, language) {
+ return window.midgardCreate.localize(id, language);
+ },
+ language: null
},
_init: function () {
@@ -158,11 +162,11 @@
var contentArea = jQuery(_.template(this.options.templates.contentArea, {}));
var articleTags = jQuery(_.template(this.options.templates.tags, {
type: 'article',
- label: 'Item tags'
+ label: this.options.localize('Item tags', this.options.language)
}));
var suggestedTags = jQuery(_.template(this.options.templates.tags, {
type: 'suggested',
- label: 'Suggested tags'
+ label: this.options.localize('Suggested tags', this.options.language)
}));
// Tags plugin requires IDs to exist
@@ -186,7 +190,7 @@
var button = jQuery(_.template(this.options.templates.button, {
icon: 'tags',
- label: 'Tags'
+ label: this.options.localize('Tags', this.options.language)
}));
var parentElement = jQuery(this.options.parentElement);
@@ -205,7 +209,8 @@
},
onRemoveTag: function (tag) {
widget.removeTag(tag);
- }
+ },
+ defaultText: this.options.localize('add a tag', this.options.language)
});
var selectSuggested = function () {
View
17 src/midgardCreate.localize.js
@@ -0,0 +1,17 @@
+if (window.midgardCreate === undefined) {
+ window.midgardCreate = {};
+}
+
+window.midgardCreate.localize = function (id, language) {
+ if (!window.midgardCreate.locale) {
+ // No localization files loaded, return as-is
+ return id;
+ }
+ if (window.midgardCreate.locale[language] && window.midgardCreate.locale[language][id]) {
+ return window.midgardCreate.locale[language][id];
+ }
+ if (window.midgardCreate.locale.en[id]) {
+ return window.midgardCreate.locale.en[id];
+ }
+ return id;
+};

0 comments on commit 34a2663

Please sign in to comment.