Skip to content

Commit 8fb7bf4

Browse files
committed
Merge branch 'tinymce4'
2 parents 45fa0ad + 9c0585c commit 8fb7bf4

9 files changed

Lines changed: 383 additions & 84 deletions

File tree

helpers/ProfileElementForm.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,9 @@ public function profileElementForm(Element $element, Omeka_Record_AbstractRecord
3333
if($isUserProfilesMultiElement) {
3434
$addInputComponent = '';
3535
} else {
36-
$addInputComponent = $this->view->formSubmit('add_element_' . $this->_element['id'],
36+
$addInputComponent = $this->view->formButton('add_element_' . $this->_element['id'],
3737
__('Add Input'),
38-
array('class'=>'add-element'));
38+
array('class'=>'user-profiles add-element'));
3939
}
4040

4141
$components = array(

plugin.ini

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@ name="User Profiles"
33
author="Roy Rosenzweig Center for History and New Media"
44
description="Adds configurable user profiles to omeka"
55
link="http://omeka.org/codex/Plugins/UserProfile_2.0"
6-
omeka_minimum_version="2.0"
7-
omeka_target_version="2.0.2"
6+
omeka_minimum_version="2.6"
7+
omeka_target_version="2.6"
88
support_link="http://omeka.org/forums/forum/plugins"
99
license="GPLv3"
1010
version="1.1.1"

views/public/javascripts/elements.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -132,9 +132,9 @@ Omeka.Elements = {};
132132
var textareaId = textarea.attr('id');
133133
var enableIfChecked = function () {
134134
if (this.checked) {
135-
tinyMCE.execCommand("mceAddControl", false, textareaId);
135+
tinyMCE.EditorManager.execCommand("mceAddEditor", false, textareaId);
136136
} else {
137-
tinyMCE.execCommand("mceRemoveControl", false, textareaId);
137+
tinyMCE.EditorManager.execCommand("mceRemoveEditor", false, textareaId);
138138
}
139139
};
140140

views/shared/css/profiles.css

Lines changed: 52 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,73 @@
11
div.user-profiles-profile {
2-
clear: both;
2+
clear: both;
33
}
44

55
div.element {
6-
clear:both;
6+
clear:both;
77
}
88

99
div.field {
10-
clear: both;
10+
clear: both;
1111
}
1212

1313
div.element-text {
14-
margin-top: 0px;
14+
margin-top: 0px;
1515
}
1616

1717
div.element-text > p {
18-
margin-top: 0px;
18+
margin-top: 0px;
1919
}
2020

21+
div.container-twelve div.ten.columns {
22+
width: 100%;
23+
}
24+
25+
div.container-twelve div.five.columns {
26+
width: auto;
27+
}
28+
29+
div#primary {
30+
box-shadow: none;
31+
border: none;
32+
}
33+
34+
#section-nav, #section-nav ul {
35+
margin: 0 0 16px;
36+
}
37+
38+
2139
div.container-twelve div.ten.columns {width: 100%;}
40+
ul#section-nav {margin: 0px;}
41+
div.container-twelve div.five.columns {width: auto; float: left;}
42+
div.inputs.five.columns.omega {float: left;}
43+
button.user-profiles.add-element {display: block; clear: both;}
44+
a.delete-confirm {padding: .6em; background-color: #ad6345; color: white !important;}
45+
ul.user-profiles.navigation {padding-left: 0px; list-style: none}
46+
ul.user-profiles.navigation li {margin-right: 5px; display: inline-block;}
2247

23-
ul#section-nav, #section-nav ul {margin: 0px;}
48+
ul.user-profiles.navigation ul {padding-left: 0px; list-style: none;}
49+
input[type='checkbox'] {margin: 5px;}
2450

25-
div.container-twelve div.five.columns {width: auto;}
51+
.mce-tinymce button {
52+
background: none;
53+
margin: 0;
54+
text-transform: none;
55+
}
2656

27-
/* Seasons override */
57+
.mce-tinymce [aria-haspopup='true']:after {
58+
content: none;
59+
}
2860

29-
div#primary {
30-
box-shadow: none;
31-
border: none;
61+
p.warning {clear: both;}
62+
63+
a.big.button.user-profiles {
64+
color: white;
65+
}
66+
67+
.user-profiles input.remove-element {
68+
float: left;
69+
}
70+
71+
.user-profiles label {
72+
margin-left: 5px;
3273
}
Lines changed: 156 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,156 @@
1+
if (!Omeka) {
2+
var Omeka = {};
3+
}
4+
5+
Omeka.Elements = {};
6+
7+
(function ($) {
8+
/**
9+
* Send an AJAX request to update a <div class="field"> that contains all
10+
* the form inputs for an element.
11+
*
12+
* @param {jQuery} fieldDiv
13+
* @param {Object} params Parameters to pass to AJAX URL.
14+
* @param {string} elementFormPartialUri AJAX URL.
15+
* @param {string} recordType Current record type.
16+
* @param {string} recordId Current record ID.
17+
*/
18+
Omeka.Elements.elementFormRequest = function (fieldDiv, params, elementFormPartialUri, recordType, recordId) {
19+
var elementId = fieldDiv.attr('id').replace(/element-/, '');
20+
21+
fieldDiv.find('input, textarea, select').each(function () {
22+
var element = $(this);
23+
// Workaround for annoying jQuery treatment of checkboxes.
24+
if (element.is('[type=checkbox]')) {
25+
params[this.name] = element.is(':checked') ? '1' : '0';
26+
} else {
27+
// Make sure TinyMCE saves to the textarea before we read
28+
// from it
29+
if (element.is('textarea')) {
30+
var mce = tinyMCE.get(this.id);
31+
if (mce) {
32+
mce.save();
33+
}
34+
}
35+
params[this.name] = element.val();
36+
}
37+
});
38+
39+
recordId = typeof recordId !== 'undefined' ? recordId : 0;
40+
41+
params.element_id = elementId;
42+
params.record_id = recordId;
43+
params.record_type = recordType;
44+
45+
$.ajax({
46+
url: elementFormPartialUri,
47+
type: 'POST',
48+
dataType: 'html',
49+
data: params,
50+
success: function (response) {
51+
fieldDiv.find('textarea').each(function () {
52+
tinyMCE.EditorManager.execCommand('mceRemoveEditor', false, this.id);
53+
});
54+
fieldDiv.html(response);
55+
fieldDiv.trigger('omeka:elementformload');
56+
}
57+
});
58+
};
59+
60+
/**
61+
* Set up add/remove element buttons for ElementText inputs.
62+
*
63+
* @param {Element} element The element to search at and below.
64+
* @param {string} elementFormPartialUrl AJAX URL for form inputs.
65+
* @param {string} recordType Current record type.
66+
* @param {string} recordId Current record ID.
67+
*/
68+
Omeka.Elements.makeElementControls = function (element, elementFormPartialUrl, recordType, recordId) {
69+
var addSelector = '.add-element';
70+
var removeSelector = '.remove-element';
71+
var fieldSelector = 'div.field';
72+
var inputBlockSelector = 'div.input-block';
73+
var context = $(element);
74+
var fields;
75+
76+
if (context.is(fieldSelector)) {
77+
fields = context;
78+
} else {
79+
fields = context.find(fieldSelector);
80+
}
81+
82+
// Show remove buttons for fields with 2 or more inputs.
83+
fields.each(function () {
84+
var removeButtons = $(this).find(removeSelector);
85+
if (removeButtons.length > 1) {
86+
removeButtons.show();
87+
} else {
88+
removeButtons.hide();
89+
}
90+
});
91+
92+
// When an add button is clicked, make an AJAX request to add another input.
93+
context.find(addSelector).click(function (event) {
94+
event.preventDefault();
95+
var fieldDiv = $(this).parents(fieldSelector);
96+
97+
Omeka.Elements.elementFormRequest(fieldDiv, {add: '1'}, elementFormPartialUrl, recordType, recordId);
98+
});
99+
100+
// When a remove button is clicked, remove that input from the form.
101+
context.find(removeSelector).click(function (event) {
102+
event.preventDefault();
103+
var removeButton = $(this);
104+
105+
// Don't delete the last input block for an element.
106+
if (removeButton.parents(fieldSelector).find(inputBlockSelector).length === 1) {
107+
return;
108+
}
109+
110+
if (!confirm('Do you want to delete this input?')) {
111+
return;
112+
}
113+
114+
var inputBlock = removeButton.parents(inputBlockSelector);
115+
inputBlock.find('textarea').each(function () {
116+
tinyMCE.EditorManager.execCommand('mceRemoveEditor', false, this.id);
117+
});
118+
inputBlock.remove();
119+
120+
// Hide remove buttons for fields with one input.
121+
$(fieldSelector).each(function () {
122+
var removeButtons = $(this).find(removeSelector);
123+
if (removeButtons.length === 1) {
124+
removeButtons.hide();
125+
}
126+
});
127+
});
128+
};
129+
130+
/**
131+
* Enable the WYSIWYG editor for "html-editor" fields on the form, and allow
132+
* checkboxes to create editors for more fields.
133+
*
134+
* @param {Element} element The element to search at and below.
135+
*/
136+
Omeka.Elements.enableWysiwyg = function (element) {
137+
$(element).find('div.inputs .use-html-checkbox').each(function () {
138+
var textarea = $(this).parents('.input-block').find('textarea');
139+
if (textarea.length) {
140+
var textareaId = textarea.attr('id');
141+
var enableIfChecked = function () {
142+
if (this.checked) {
143+
tinyMCE.EditorManager.execCommand("mceAddEditor", false, textareaId);
144+
} else {
145+
tinyMCE.EditorManager.execCommand("mceRemoveEditor", false, textareaId);
146+
}
147+
};
148+
149+
enableIfChecked.call(this);
150+
151+
// Whenever the checkbox is toggled, toggle the WYSIWYG editor.
152+
$(this).click(enableIfChecked);
153+
}
154+
});
155+
};
156+
})(jQuery);

0 commit comments

Comments
 (0)