From 7111e37384bf192d4064601126be82fc39bb677c Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Martin=20Auswo=CC=88ger?= <martin@auswoeger.com>
Date: Mon, 16 Sep 2013 18:12:35 +0200
Subject: [PATCH] Fixed backward compatibility for Contao 3.0

---
 assets/js/be_main.js                      | 14 +++++++++++---
 src/MadeYourDay/Contao/CustomElements.php | 12 +++++++-----
 2 files changed, 18 insertions(+), 8 deletions(-)

diff --git a/assets/js/be_main.js b/assets/js/be_main.js
index d3d9222..bad57ad 100644
--- a/assets/js/be_main.js
+++ b/assets/js/be_main.js
@@ -115,13 +115,17 @@ var renameElement = function(element) {
 
 var initListSort = function(listInner) {
 
+	if (!listInner.getElements('.drag-handle').length) {
+		return;
+	}
+
 	var ds = new Scroller(document.body, {
 		onChange: function(x, y) {
 			this.element.scrollTo(this.element.getScroll().x, y);
 		}
 	});
 
-	var sort = listInner.retrieve('listSort', new Sortables(listInner, {
+	listInner.retrieve('listSort', new Sortables(listInner, {
 		contstrain: true,
 		opacity: 0.6,
 		handle: '.drag-handle',
@@ -198,7 +202,9 @@ var newElementAtPosition = function(listElement, position) {
 		renameElement(el);
 	});
 
-	listInner.retrieve('listSort').addItems(newItem);
+	if (listInner.retrieve('listSort')) {
+		listInner.retrieve('listSort').addItems(newItem);
+	}
 
 	try {
 		window.fireEvent('ajax_change');
@@ -230,7 +236,9 @@ var deleteElement = function(linkElement) {
 	var element = $(linkElement).getParent('.rsce_list_item');
 	var listInner = element.getParent('.rsce_list_inner');
 	var nextElements = element.getAllNext('.rsce_list_item');
-	listInner.retrieve('listSort').removeItems(element);
+	if (listInner.retrieve('listSort')) {
+		listInner.retrieve('listSort').removeItems(element);
+	}
 	element.destroy();
 	nextElements.each(function(nextElement) {
 		renameElement(nextElement);
diff --git a/src/MadeYourDay/Contao/CustomElements.php b/src/MadeYourDay/Contao/CustomElements.php
index 5716f2d..315bd85 100644
--- a/src/MadeYourDay/Contao/CustomElements.php
+++ b/src/MadeYourDay/Contao/CustomElements.php
@@ -447,11 +447,13 @@ protected function createDcaItem($fieldPrefix, $fieldName, $fieldConfig, &$palet
 		else {
 
 			// remap page and file picker to get them work without a database field
-			if ($fieldConfig['inputType'] === 'fileTree') {
-				$fieldConfig['inputType'] = 'rsce_file_tree';
-			}
-			if ($fieldConfig['inputType'] === 'pageTree') {
-				$fieldConfig['inputType'] = 'rsce_page_tree';
+			if (version_compare(VERSION, '3.1', '>=')) {
+				if ($fieldConfig['inputType'] === 'fileTree') {
+					$fieldConfig['inputType'] = 'rsce_file_tree';
+				}
+				if ($fieldConfig['inputType'] === 'pageTree') {
+					$fieldConfig['inputType'] = 'rsce_page_tree';
+				}
 			}
 
 			$GLOBALS['TL_DCA'][$dc->table]['fields'][$fieldPrefix . $fieldName] = $fieldConfig;