lib/assets/javascripts/scrivito_sdk.js in scrivito_sdk-0.30.0.rc1 vs lib/assets/javascripts/scrivito_sdk.js in scrivito_sdk-0.30.0
- old
+ new
@@ -14800,16 +14800,11 @@
$.error('Can not call "scrivito" method on more than one tag');
}
};
var build_cms_element = function(dom_element) {
- var cms_element = scrivito.cms_element.from_dom_element(dom_element);
- if (cms_element) {
- return cms_element;
- } else {
- $.error('Can not call "scrivito" method on a non-cms tag');
- }
+ return scrivito.cms_element.from_dom_element(dom_element);
};
var save_content = function(dom_element, content) {
if (dom_element.length > 0) {
if (dom_element.length === 1) {
@@ -14844,23 +14839,28 @@
cms_element.set_menu(menu);
}
};
};
- // @api public
- $.fn.scrivito = function(method, content) {
- switch (method) {
- case 'save':
- return save_content($(this), content);
- case 'content':
- return get_original_content($(this));
- case 'menu':
- return get_menu($(this));
- default:
- $.error('Unknown method "' + method + '"');
+ $.extend(scrivito, {
+ // @api public
+ jquery_plugin: function(method, content) {
+ switch (method) {
+ case 'save':
+ return save_content($(this), content);
+ case 'content':
+ return get_original_content($(this));
+ case 'menu':
+ return get_menu($(this));
+ default:
+ $.error('Unknown method "' + method + '"');
+ }
}
- };
+ });
+
+ $.fn.scrivito = scrivito.jquery_plugin;
+
}());
(function() {
var callbacks = {};
// The callback has to be function that takes no arguments
@@ -15923,10 +15923,12 @@
$(function() {
scrivito.cms_element.definitions.push(scrivito.child_list_element);
});
(function() {
+ var expando = "scrivito_cms_element";
+
$.extend(scrivito, {
cms_element: {
create_instance: function(dom_element) {
var that = {
dom_element: function() {
@@ -15953,16 +15955,30 @@
return that;
},
from_dom_element: function(dom_element) {
- var cms_element = scrivito.cms_element.create_instance(dom_element);
+ if (!dom_element || !dom_element.jquery || dom_element.length === 0) {
+ $.error("Expected a jquery instance with exactly one element, " +
+ "instead got " + dom_element);
+ }
- var instance;
- _.find(scrivito.cms_element.definitions, function(definition) {
- instance = definition.create_instance(cms_element);
- return instance;
- });
+ var instance = dom_element[0][expando];
+
+ if (!instance) {
+ var cms_element = scrivito.cms_element.create_instance(dom_element);
+
+ _.find(scrivito.cms_element.definitions, function(definition) {
+ instance = definition.create_instance(cms_element);
+ return instance;
+ });
+
+ if (!instance) {
+ $.error("This dom element is not a scrivito tag.");
+ }
+
+ dom_element[0][expando] = instance;
+ }
return instance;
},
definitions: [],