camaleon_media_paperclip 0.1.1 → 0.1.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/app/assets/javascripts/admin/custom_fields.js +167 -0
- data/app/assets/javascripts/admin/data.js +74 -0
- data/app/assets/javascripts/admin/elfinder/upload_elfinder.js +0 -1
- data/app/assets/javascripts/admin/libraries.js +266 -0
- data/app/assets/javascripts/admin/post.js +273 -0
- data/app/assets/javascripts/admin/tinymce/plugins/filemanager/plugin.min.js +31 -0
- data/config/camaleon_plugin.json +1 -1
- data/lib/camaleon_media_paperclip/version.rb +1 -1
- metadata +7 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4efda6106e098ad2175d2c985b5d0e04dc39d8a8
|
4
|
+
data.tar.gz: b7b5628191d60b6210dec70e9a64e6b889f12a05
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ffd825440fcc700e7ba0a44ad59ba9d8a76c5ac9ca39fb076e5fed361f63e579fa9861dca4939db0f7538fd8aa18cc914090ff366343be9ee82cf1801fd303fd
|
7
|
+
data.tar.gz: b36ca5fb76c774b35e6740d2ce75d0f8b009e911f3101616630b0ca68f98a49f88577ea40a8ef548ca76c9631c066b0516138e039244b74cf31ca6a12a42cbf5
|
@@ -0,0 +1,167 @@
|
|
1
|
+
function build_custom_field(values, multiple, field_key, rand, default_value){
|
2
|
+
var $content = $("#content-field-"+rand);
|
3
|
+
var $sortable = $("#sortable-"+rand);
|
4
|
+
var callback = $content.find('.clone-field .group-input-fields-content').attr('data-callback-function');
|
5
|
+
var callback_set_value = $content.find('.clone-field .group-input-fields-content').attr('data-callback-set-value');
|
6
|
+
var $field = $('<li>' + $content.find('.clone-field').html() + '</li>');
|
7
|
+
|
8
|
+
function add_field(value){
|
9
|
+
var field = $field.clone(true);
|
10
|
+
if(value) field.find('.input-value').val(value);
|
11
|
+
$sortable.append(field);
|
12
|
+
if(value && callback_set_value)eval(callback_set_value+"(field, value);")
|
13
|
+
else if(callback) eval(callback+"(field);")
|
14
|
+
}
|
15
|
+
|
16
|
+
if(values.length > 0) {
|
17
|
+
if(field_key == 'checkboxes'){
|
18
|
+
add_field(values);
|
19
|
+
}else{
|
20
|
+
if(!multiple && values.length > 1) values = [values[0]];
|
21
|
+
$.each(values, function(i, value){
|
22
|
+
add_field(value);
|
23
|
+
});
|
24
|
+
}
|
25
|
+
} else add_field(default_value);
|
26
|
+
|
27
|
+
if(multiple) {
|
28
|
+
$content.find('.btn-add-field').click(function(){
|
29
|
+
add_field(default_value);
|
30
|
+
return false;
|
31
|
+
});
|
32
|
+
$sortable.delegate('.actions .fa-times', "click", function(){
|
33
|
+
var parent = $(this).parents('li');
|
34
|
+
if(confirm(I18n("msg.delete_item"))){
|
35
|
+
parent.remove();
|
36
|
+
}
|
37
|
+
return false;
|
38
|
+
});
|
39
|
+
$sortable.find('li:first .fa-times').hide();
|
40
|
+
$sortable.sortable({
|
41
|
+
handle: ".fa-arrows"
|
42
|
+
});
|
43
|
+
}
|
44
|
+
|
45
|
+
$content.find('.clone-field').remove();
|
46
|
+
}
|
47
|
+
|
48
|
+
function custom_field_colorpicker($field){ if($field){ $field.find(".my-colorpicker").colorpicker(); } }
|
49
|
+
function custom_field_colorpicker_val($field, value){ if($field){ $field.find(".my-colorpicker").attr('data-color', value).colorpicker(); } }
|
50
|
+
function custom_field_checkbox_val($field, values){
|
51
|
+
if($field){
|
52
|
+
$field.find('input[value="'+values+'"]').prop('checked', true);
|
53
|
+
}
|
54
|
+
}
|
55
|
+
function custom_field_checkboxs_val($field, values){
|
56
|
+
if($field){
|
57
|
+
var selector = values.map(function(value){
|
58
|
+
return "input[value='"+value+"']"
|
59
|
+
}).join(',');
|
60
|
+
$field.find('input').prop('checked', false);
|
61
|
+
$field.find(selector).prop('checked', true);
|
62
|
+
}
|
63
|
+
}
|
64
|
+
function custom_field_date($field){
|
65
|
+
if($field){
|
66
|
+
var box = $field.find(".date-input-box");
|
67
|
+
if(box.hasClass('is_datetimepicker')){
|
68
|
+
box.datetimepicker({
|
69
|
+
language: 'es',
|
70
|
+
pick12HourFormat: true,
|
71
|
+
format: 'yyyy-MM-dd hh:mm'
|
72
|
+
});
|
73
|
+
}else{
|
74
|
+
box.datepicker({
|
75
|
+
language: 'es',
|
76
|
+
format: 'yyyy-mm-dd',
|
77
|
+
autoclose: true,
|
78
|
+
todayBtn: "linked"
|
79
|
+
});
|
80
|
+
}
|
81
|
+
}
|
82
|
+
}
|
83
|
+
function custom_field_editor($field){
|
84
|
+
if($field){
|
85
|
+
var id = "t_" + Math.floor((Math.random() * 100000) + 1) + "_area";
|
86
|
+
var textarea = $field.find('textarea').attr('id', id);
|
87
|
+
if(textarea.hasClass('is_translate')) {
|
88
|
+
textarea.addClass('translatable').Translatable(ADMIN_TRANSLATIONS);
|
89
|
+
var inputs = textarea.data("translation_inputs");
|
90
|
+
if(inputs){ // multiples languages
|
91
|
+
for(var lang in inputs){
|
92
|
+
tinymce.init(cama_get_tinymce_settings({selector: '#' + inputs[lang].attr("id"), height: 120}));
|
93
|
+
}
|
94
|
+
return;
|
95
|
+
}
|
96
|
+
}
|
97
|
+
tinymce.init(cama_get_tinymce_settings({selector: '#' + id, height: 120}));
|
98
|
+
}
|
99
|
+
}
|
100
|
+
function custom_field_field_attrs_val($field, value){
|
101
|
+
if($field){
|
102
|
+
var data = $.parseJSON(value);
|
103
|
+
$field.find('.input-attr').val(data.attr);
|
104
|
+
$field.find('.input-value').val(data.value)
|
105
|
+
}
|
106
|
+
}
|
107
|
+
function custom_field_radio_val($field, value){
|
108
|
+
if($field){
|
109
|
+
$field.find('input').prop('checked', false);
|
110
|
+
$field.find("input[value='"+value+"']").prop('checked', true);
|
111
|
+
}
|
112
|
+
}
|
113
|
+
function custom_field_text_area($field){
|
114
|
+
if($field){
|
115
|
+
if($field.find('textarea').hasClass('is_translate')) {
|
116
|
+
$field.find('textarea').addClass('translatable').Translatable(ADMIN_TRANSLATIONS);
|
117
|
+
}
|
118
|
+
}
|
119
|
+
}
|
120
|
+
function custom_field_text_box($field){
|
121
|
+
if($field){
|
122
|
+
if($field.find('input').hasClass('is_translate')) {
|
123
|
+
$field.find('input').addClass('translatable').Translatable(ADMIN_TRANSLATIONS);
|
124
|
+
}
|
125
|
+
}
|
126
|
+
}
|
127
|
+
|
128
|
+
function load_upload_audio_field(dom){
|
129
|
+
var $input = $(dom).parents('li:first').find('input');
|
130
|
+
$.fn.upload_elfinder({
|
131
|
+
type: "audio",
|
132
|
+
selected: function(res){
|
133
|
+
var file = _.first(res);
|
134
|
+
$input.val(file.url);
|
135
|
+
}
|
136
|
+
});
|
137
|
+
}
|
138
|
+
function load_upload_file_field(dom){
|
139
|
+
var $input = $(dom).parents('li:first').find('input');
|
140
|
+
$.fn.upload_elfinder({
|
141
|
+
type: $input.data("formats") ? $input.data("formats") : "all",
|
142
|
+
selected: function(res){
|
143
|
+
var file = _.first(res);
|
144
|
+
$input.val(file.url);
|
145
|
+
}
|
146
|
+
});
|
147
|
+
}
|
148
|
+
function load_upload_image_field(dom){
|
149
|
+
var $input = $(dom).parents('li:first').find('input');
|
150
|
+
$.fn.upload_elfinder({
|
151
|
+
type: "image",
|
152
|
+
selected: function(res){
|
153
|
+
var file = _.first(res);
|
154
|
+
$input.val(file.url);
|
155
|
+
}
|
156
|
+
});
|
157
|
+
}
|
158
|
+
function load_upload_video_field(dom){
|
159
|
+
var $input = $(dom).parents('li:first').find('input');
|
160
|
+
$.fn.upload_elfinder({
|
161
|
+
type: "video",
|
162
|
+
selected: function(res){
|
163
|
+
var file = _.first(res);
|
164
|
+
$input.val(file.url);
|
165
|
+
}
|
166
|
+
});
|
167
|
+
}
|
@@ -0,0 +1,74 @@
|
|
1
|
+
// generate default settings for tinymce editor
|
2
|
+
function cama_get_tinymce_settings(settings){
|
3
|
+
if(!settings) settings = {};
|
4
|
+
var def = {
|
5
|
+
selector: ".tinymce_textarea",
|
6
|
+
plugins: [
|
7
|
+
"advlist autolink lists link image charmap print preview hr anchor pagebreak",
|
8
|
+
"searchreplace wordcount visualblocks visualchars code fullscreen",
|
9
|
+
"insertdatetime media nonbreaking save table contextmenu directionality",
|
10
|
+
"emoticons template paste textcolor colorpicker textpattern filemanager"
|
11
|
+
],
|
12
|
+
menubar: "edit insert view format table tools",
|
13
|
+
image_advtab: true,
|
14
|
+
statusbar: true,
|
15
|
+
paste: true,
|
16
|
+
toolbar_items_size: 'small',
|
17
|
+
content_css: tinymce_global_settings["custom_css"].join(","),
|
18
|
+
convert_urls: false,
|
19
|
+
//forced_root_block: '',
|
20
|
+
extended_valid_elements: 'i[*],div[*],p[*],li[*],a[*],ol[*],ul[*],span[*]',
|
21
|
+
toolbar: "bold italic | alignleft aligncenter alignright alignjustify | fontselect fontsizeselect | bullist numlist | outdent indent | undo redo | link unlink image media | forecolor backcolor | styleselect template "+tinymce_global_settings["custom_toolbar"].join(","),
|
22
|
+
language: CURRENT_LOCALE,
|
23
|
+
relative_urls: false,
|
24
|
+
remove_script_host: false,
|
25
|
+
browser_spellcheck : true,
|
26
|
+
language_url: tinymce_global_settings["language_url"],
|
27
|
+
file_browser_callback: function(field_name, url, type, win) {
|
28
|
+
$.fn.upload_elfinder({
|
29
|
+
selected: function(res){
|
30
|
+
var file = _.first(res)
|
31
|
+
if(type == 'media') type = 'video';
|
32
|
+
if(file.mime && (file.mime.indexOf(type) > -1 || type == "file")){
|
33
|
+
$('#'+field_name).val(file.url);
|
34
|
+
}else{
|
35
|
+
alert("You must upload a valid format: "+type)
|
36
|
+
}
|
37
|
+
}
|
38
|
+
});
|
39
|
+
},
|
40
|
+
setup: function (editor) {
|
41
|
+
editor.on('blur', function () {
|
42
|
+
tinymce.triggerSave();
|
43
|
+
$('textarea#'+editor.id).trigger('change');
|
44
|
+
});
|
45
|
+
|
46
|
+
editor.addMenuItem('append_line', {
|
47
|
+
text: 'New line at the end',
|
48
|
+
context: 'insert',
|
49
|
+
onclick: function () { editor.dom.add(editor.getBody(), 'p', {}, '-New line-'); }
|
50
|
+
});
|
51
|
+
editor.addMenuItem('add_line', {
|
52
|
+
text: 'New line',
|
53
|
+
context: 'insert',
|
54
|
+
onclick: function () { editor.insertContent('<p>-New line-</p>'); }
|
55
|
+
});
|
56
|
+
|
57
|
+
// eval all extra setups
|
58
|
+
for(var ff in tinymce_global_settings["setups"]) tinymce_global_settings["setups"][ff](editor);
|
59
|
+
|
60
|
+
editor.on('postRender', function(e) {
|
61
|
+
editor.settings.onPostRender(editor);
|
62
|
+
// eval all extra setups
|
63
|
+
for(var ff in tinymce_global_settings["post_render"]) tinymce_global_settings["post_render"][ff](editor);
|
64
|
+
});
|
65
|
+
|
66
|
+
editor.on('init', function(e) {
|
67
|
+
for(var ff in tinymce_global_settings["init"]) tinymce_global_settings["init"][ff](editor);
|
68
|
+
});
|
69
|
+
},
|
70
|
+
onPostRender: function(editor){}
|
71
|
+
};
|
72
|
+
return $.extend({}, def, settings);
|
73
|
+
}
|
74
|
+
|
@@ -67,7 +67,6 @@
|
|
67
67
|
url : "/admin/elfinder".to_url(), // connector URL (REQUIRED)
|
68
68
|
lang: options.locale,
|
69
69
|
height: '500',
|
70
|
-
// transport : new elFinderSupportVer1(),
|
71
70
|
handlers : {
|
72
71
|
init : function(event, _elfinder) {
|
73
72
|
$content.find('.elfinder-navbar').append('<div id="elfinder-panel-info" class="">'+
|
@@ -0,0 +1,266 @@
|
|
1
|
+
function log(d){
|
2
|
+
if(console.log)console.log(d);
|
3
|
+
}
|
4
|
+
|
5
|
+
|
6
|
+
/****************** form validations ************/
|
7
|
+
// panel can be a object: $("#my_form")
|
8
|
+
// if panel is null, then this will be replaced by body
|
9
|
+
var init_form_validations = function(form){
|
10
|
+
// slug management
|
11
|
+
// you need to add class no_translate to avoid translations in slugs
|
12
|
+
(form ? form : $('#admin_content')).find('input.slug').each(function(){
|
13
|
+
var sl_id = $(this).attr("data-parent");
|
14
|
+
if(!sl_id) return;
|
15
|
+
var $parent = $('#'+sl_id);
|
16
|
+
if($parent.hasClass('translated-item')){
|
17
|
+
var $panel_parent = $parent.siblings('.trans_panel:first');
|
18
|
+
if($(this).hasClass("no_translate")){
|
19
|
+
$(this).slugify('#'+$panel_parent.find('.tab-content .tab-pane:first input:first').attr('id'));
|
20
|
+
}else{
|
21
|
+
$(this).addClass('translatable').Translatable(ADMIN_TRANSLATIONS);
|
22
|
+
var $panel_slug = $(this).siblings('.trans_panel:first');
|
23
|
+
$panel_parent.find('.tab-content .tab-pane').each(function(index, tab_pane){
|
24
|
+
var p_id = $(tab_pane).children('input').attr('id');
|
25
|
+
$panel_slug.find('.tab-content .tab-pane:eq('+index+') input:first').slugify('#'+p_id);
|
26
|
+
})
|
27
|
+
$panel_parent.find('.nav > li a').each(function(index, a_tab){
|
28
|
+
$(a_tab).click(function(){
|
29
|
+
$panel_slug.find('.nav > li:eq('+index+') a').click()
|
30
|
+
})
|
31
|
+
})
|
32
|
+
}
|
33
|
+
}else{
|
34
|
+
$(this).slugify('#'+sl_id);
|
35
|
+
}
|
36
|
+
});
|
37
|
+
|
38
|
+
(form ? form : $('#admin_content form')).each(function () {
|
39
|
+
var $form = $(this)
|
40
|
+
if ($form.find('.translatable').size() > 0) {
|
41
|
+
$form.find('.translatable').Translatable();
|
42
|
+
}
|
43
|
+
}).filter(".validate").each(function(){
|
44
|
+
$(this).validate()
|
45
|
+
});
|
46
|
+
};
|
47
|
+
|
48
|
+
|
49
|
+
!(function($){
|
50
|
+
// serialize form into json
|
51
|
+
jQuery.fn.serializeObject=function() {
|
52
|
+
var json = {};
|
53
|
+
jQuery.map(jQuery(this).serializeArray(), function(n, i) {
|
54
|
+
var __i = n.name.indexOf('[');
|
55
|
+
if (__i > -1) {
|
56
|
+
var o = json;
|
57
|
+
_name = n.name.replace(/\]/gi, '').split('[');
|
58
|
+
for (var i=0, len=_name.length; i<len; i++) {
|
59
|
+
if (i == len-1) {
|
60
|
+
if (o[_name[i]] && $.trim(_name[i]) == '') {
|
61
|
+
if (typeof o[_name[i]] == 'string') {
|
62
|
+
o[_name[i]] = [o[_name[i]]];
|
63
|
+
}
|
64
|
+
o[_name[i]].push(n.value);
|
65
|
+
}
|
66
|
+
else o[_name[i]] = n.value || '';
|
67
|
+
}
|
68
|
+
else o = o[_name[i]] = o[_name[i]] || {};
|
69
|
+
}
|
70
|
+
}
|
71
|
+
else {
|
72
|
+
if (json[n.name] !== undefined) {
|
73
|
+
if (!json[n.name].push) {
|
74
|
+
json[n.name] = [json[n.name]];
|
75
|
+
}
|
76
|
+
json[n.name].push(n.value || '');
|
77
|
+
}
|
78
|
+
else json[n.name] = n.value || '';
|
79
|
+
}
|
80
|
+
});
|
81
|
+
return json;
|
82
|
+
};
|
83
|
+
})(jQuery);
|
84
|
+
|
85
|
+
|
86
|
+
// file uploader
|
87
|
+
(function($){
|
88
|
+
$.fn.input_upload = function (options_init) {
|
89
|
+
var default_options = {label: I18n("msg.upload_image"), type: "image", ext: "none", icon: "upload", full_url: true, height: '100px'};
|
90
|
+
default_options = $.extend({}, default_options, options_init || {});
|
91
|
+
$(this).each(function(){
|
92
|
+
var $that = $(this);
|
93
|
+
var options = $.extend({}, default_options, $that.data() || {});
|
94
|
+
var $content_image = $("<div class='content-upload-plugin'><a href='#' target='_blank'><img src=''><strong></strong></a></div>").hide();
|
95
|
+
if(options.type != 'image') $content_image.find('img').remove();
|
96
|
+
var $btn_upload = $('<a class="btn btn-default" href="#"><i class="fa fa-upload"></i> '+options.label+'</a>')
|
97
|
+
$content_image.find('img').css('max-height', options.height);
|
98
|
+
|
99
|
+
$btn_upload.click(function(){
|
100
|
+
$.fn.upload_elfinder({
|
101
|
+
selected: function(res){
|
102
|
+
var image = _.first(res);
|
103
|
+
if(options.type == 'all' || (image.mime && image.mime.indexOf(options.type) > -1) || _.last(image.name.split(".")) == options.ext){
|
104
|
+
set_texts(image.url)
|
105
|
+
}else{
|
106
|
+
alert("File extension not allowed")
|
107
|
+
}
|
108
|
+
}
|
109
|
+
});
|
110
|
+
return false;
|
111
|
+
});
|
112
|
+
|
113
|
+
$that.after($content_image).after($btn_upload);
|
114
|
+
|
115
|
+
function set_texts(url){
|
116
|
+
$content_image.find('img').attr('src', url);
|
117
|
+
$content_image.find('a').attr('href', url);
|
118
|
+
$that.val(url);
|
119
|
+
$content_image.find('strong').html(_.last(url.split('/')));
|
120
|
+
$content_image.show()
|
121
|
+
}
|
122
|
+
if($that.val()) set_texts($that.val())
|
123
|
+
});
|
124
|
+
};
|
125
|
+
|
126
|
+
// create inline input file uploader with an icon to upload file
|
127
|
+
// options: all options needed for uploader
|
128
|
+
// you can add an attribute "data-format" in the input to define the file formats required
|
129
|
+
$.fn.input_upload_field = function(options){
|
130
|
+
this.each(function(){
|
131
|
+
var input = $(this);
|
132
|
+
var def = {
|
133
|
+
type: (input.attr("data-format") || "image"),
|
134
|
+
selected: function(res){
|
135
|
+
var file = _.first(res);
|
136
|
+
input.val(file.url);
|
137
|
+
}
|
138
|
+
};
|
139
|
+
if(!input.parent().hasClass("input-group")){
|
140
|
+
input.wrap('<div class="group-input-fields-content input-group"></div>');
|
141
|
+
input.after('<span class="input-group-addon btn_upload"><i class="fa fa-upload"></i> </span>');
|
142
|
+
input.addClass("form-control");
|
143
|
+
}
|
144
|
+
input.next("span").click(function(){
|
145
|
+
$.fn.upload_elfinder($.extend({}, def, (options || {})));
|
146
|
+
});
|
147
|
+
});
|
148
|
+
}
|
149
|
+
})(jQuery);
|
150
|
+
|
151
|
+
// jquery custom validations and default values
|
152
|
+
(function($){
|
153
|
+
|
154
|
+
// file formats
|
155
|
+
$.file_formats = {
|
156
|
+
jpg: "image",
|
157
|
+
gif: "image",
|
158
|
+
png: "image",
|
159
|
+
bmp: "image",
|
160
|
+
jpeg: "image",
|
161
|
+
|
162
|
+
mp3: "audio",
|
163
|
+
ogg: "audio",
|
164
|
+
mid: "audio",
|
165
|
+
mod: "audio",
|
166
|
+
wav: "audio",
|
167
|
+
|
168
|
+
mp4: "video",
|
169
|
+
wmv: "video",
|
170
|
+
avi: "video",
|
171
|
+
swf: "video",
|
172
|
+
mov: "video",
|
173
|
+
mpeg: "video",
|
174
|
+
mjpg: "video"
|
175
|
+
}
|
176
|
+
|
177
|
+
// verify the url for youtube, vimeo...
|
178
|
+
// return youtube | metcafe|dailymotion|vimeo
|
179
|
+
$.cama_check_video_url = function(url){
|
180
|
+
var regYoutube = new RegExp(/^.*((youtu.be\/)|(v\/)|(\/u\/w\/)|(embed\/)|(watch?))??v?=?([^#&?]*).*/);
|
181
|
+
var regVimeo = new RegExp(/^.*(vimeo.com\/)((channels\/[A-z]+\/)|(groups\/[A-z]+\/videos\/))?([0-9]+)/);
|
182
|
+
var regDailymotion = new RegExp(/^.+dailymotion.com\/(video|hub)\/([^_]+)[^#]*(#video=([^_&]+))?/);
|
183
|
+
var regMetacafe = new RegExp(/^.*(metacafe.com)(\/watch\/)(d+)(.*)/i);
|
184
|
+
if(regYoutube.test(url)) {
|
185
|
+
return 'youtube';
|
186
|
+
}else if (regMetacafe.test(url)) {
|
187
|
+
return 'metacafe';
|
188
|
+
}else if(regDailymotion.test(url)){
|
189
|
+
return 'dailymotion';
|
190
|
+
}else if(regVimeo.test(url)) {
|
191
|
+
return 'vimeo';
|
192
|
+
}else{
|
193
|
+
return false;
|
194
|
+
}
|
195
|
+
}
|
196
|
+
|
197
|
+
// helper validate only letters latin
|
198
|
+
var regex = /^[a-z\sÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏàáâãäåæçèéêëìíîïÐÑÒÓÔÕÖØÙÚÛÜÝÞßðñòóôõöøùúûüýþÿ]+$/i;
|
199
|
+
jQuery.validator.addMethod("lettersonly", function(value, element) {
|
200
|
+
return this.optional(element) || regex.test(value);
|
201
|
+
}, "Only alphabetical characters");
|
202
|
+
|
203
|
+
/************ Custom jquery validation as defaults ***************/
|
204
|
+
jQuery.validator.setDefaults({
|
205
|
+
focusInvalid: true, ignore: ".translated-item", errorPlacement: function (a,b) {
|
206
|
+
if(!a.text()) return;
|
207
|
+
if(b.parent().hasClass('trans_tab_item')){ // tabs
|
208
|
+
var parent = b.parent();
|
209
|
+
$("a[href='#"+ parent.attr('id') +"']").addClass('has-error').trigger('click');
|
210
|
+
parent.addClass('has-error').append(a.addClass('help-block'));
|
211
|
+
}else if(b.parent().hasClass('form-group')){
|
212
|
+
b.parent().addClass('has-error').append(a.addClass('help-block'));
|
213
|
+
}else{
|
214
|
+
if(b.attr('name') == 'categories[]')
|
215
|
+
b.parent().before(a.addClass('help-block')).parent().addClass('has-error');
|
216
|
+
else
|
217
|
+
b.parent().after(a.addClass('help-block')).parent().addClass('has-error');
|
218
|
+
}
|
219
|
+
}, success: function(error, element){
|
220
|
+
$(element).parent().removeClass('has-error').parent().removeClass('has-error')
|
221
|
+
if($(element).parent().hasClass('tab-pane')) $("a[href='#"+ $(element).parent().attr('id') +"']").removeClass('has-error');
|
222
|
+
}
|
223
|
+
});
|
224
|
+
|
225
|
+
// validate file extension defined in data-formats
|
226
|
+
// data-formats: (default '') image | audio | video (support also external youtube metacafe, dailymotion, vimeo) | or file extension like: jpg|png
|
227
|
+
$.validator.addMethod("file_format", function(value, element) {
|
228
|
+
var formats = $(element).attr("data-formats");
|
229
|
+
var ext = value.split(".").pop().toLowerCase();
|
230
|
+
if(formats)
|
231
|
+
return ($.inArray("video", formats.split(",")) >= 0 && $.cama_check_video_url(value)) || $.inArray($.file_formats[ext], formats.split(",")) >= 0 || $.inArray(ext, formats.split(",")) >= 0
|
232
|
+
|
233
|
+
return true;
|
234
|
+
}, "File format not accepted.");
|
235
|
+
jQuery.validator.addClassRules({
|
236
|
+
file_format : { file_format : true }
|
237
|
+
});
|
238
|
+
})(jQuery);
|
239
|
+
|
240
|
+
// convert string into hashcode
|
241
|
+
String.prototype.hashCode = function() {
|
242
|
+
var message = this;
|
243
|
+
if(message == "") {
|
244
|
+
return "";
|
245
|
+
}
|
246
|
+
var chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/_-".split("");
|
247
|
+
var length = 40;
|
248
|
+
for(var last = 0, i = 0, len = message.length; i < len; i++) {
|
249
|
+
last = (message.charCodeAt(i) + 31 * last) % 59;
|
250
|
+
}
|
251
|
+
length = length || message.length;
|
252
|
+
while(len < length) {
|
253
|
+
message += message;
|
254
|
+
len += len;
|
255
|
+
}
|
256
|
+
message = message.slice(0, length);
|
257
|
+
for(var ret = "", i = 0; i < length; i++) {
|
258
|
+
ret += chars[last = (i + last + message.charCodeAt(i)) % 64];
|
259
|
+
}
|
260
|
+
return ret;
|
261
|
+
};
|
262
|
+
|
263
|
+
// convert string path into full url
|
264
|
+
String.prototype.to_url = function () { return root_url.slice(0, root_url.length - 1) + this; };
|
265
|
+
// jquery browser supoer
|
266
|
+
!function(a){"function"==typeof define&&define.amd?define(["jquery"],function(b){a(b)}):"object"==typeof module&&"object"==typeof module.exports?module.exports=a(require("jquery")):a(window.jQuery)}(function(a){"use strict";function b(a){void 0===a&&(a=window.navigator.userAgent),a=a.toLowerCase();var b=/(edge)\/([\w.]+)/.exec(a)||/(opr)[\/]([\w.]+)/.exec(a)||/(chrome)[ \/]([\w.]+)/.exec(a)||/(version)(applewebkit)[ \/]([\w.]+).*(safari)[ \/]([\w.]+)/.exec(a)||/(webkit)[ \/]([\w.]+).*(version)[ \/]([\w.]+).*(safari)[ \/]([\w.]+)/.exec(a)||/(webkit)[ \/]([\w.]+)/.exec(a)||/(opera)(?:.*version|)[ \/]([\w.]+)/.exec(a)||/(msie) ([\w.]+)/.exec(a)||a.indexOf("trident")>=0&&/(rv)(?::| )([\w.]+)/.exec(a)||a.indexOf("compatible")<0&&/(mozilla)(?:.*? rv:([\w.]+)|)/.exec(a)||[],c=/(ipad)/.exec(a)||/(ipod)/.exec(a)||/(iphone)/.exec(a)||/(kindle)/.exec(a)||/(silk)/.exec(a)||/(android)/.exec(a)||/(windows phone)/.exec(a)||/(win)/.exec(a)||/(mac)/.exec(a)||/(linux)/.exec(a)||/(cros)/.exec(a)||/(playbook)/.exec(a)||/(bb)/.exec(a)||/(blackberry)/.exec(a)||[],d={},e={browser:b[5]||b[3]||b[1]||"",version:b[2]||b[4]||"0",versionNumber:b[4]||b[2]||"0",platform:c[0]||""};if(e.browser&&(d[e.browser]=!0,d.version=e.version,d.versionNumber=parseInt(e.versionNumber,10)),e.platform&&(d[e.platform]=!0),(d.android||d.bb||d.blackberry||d.ipad||d.iphone||d.ipod||d.kindle||d.playbook||d.silk||d["windows phone"])&&(d.mobile=!0),(d.cros||d.mac||d.linux||d.win)&&(d.desktop=!0),(d.chrome||d.opr||d.safari)&&(d.webkit=!0),d.rv||d.edge){var f="msie";e.browser=f,d[f]=!0}if(d.safari&&d.blackberry){var g="blackberry";e.browser=g,d[g]=!0}if(d.safari&&d.playbook){var h="playbook";e.browser=h,d[h]=!0}if(d.bb){var i="blackberry";e.browser=i,d[i]=!0}if(d.opr){var j="opera";e.browser=j,d[j]=!0}if(d.safari&&d.android){var k="android";e.browser=k,d[k]=!0}if(d.safari&&d.kindle){var l="kindle";e.browser=l,d[l]=!0}if(d.safari&&d.silk){var m="silk";e.browser=m,d[m]=!0}return d.name=e.browser,d.platform=e.platform,d}return window.jQBrowser=b(window.navigator.userAgent),window.jQBrowser.uaMatch=b,a&&(a.browser=window.jQBrowser),window.jQBrowser});
|
@@ -0,0 +1,273 @@
|
|
1
|
+
var App_post = {};
|
2
|
+
var $form = null;
|
3
|
+
function init_post(obj){
|
4
|
+
$form = $('#form-post');
|
5
|
+
|
6
|
+
if(obj.recover_draft == "true"){
|
7
|
+
$form.css('opacity',0).before('<h2 style="text-align: center">'+I18n("msg.recover")+'</h2>');
|
8
|
+
}
|
9
|
+
|
10
|
+
var _draft_inited = false;
|
11
|
+
var class_translate = ".translate-item";
|
12
|
+
|
13
|
+
var post_id = obj.post_id;
|
14
|
+
var post_draft_id = obj.post_draft_id;
|
15
|
+
var post_status = obj.post_status;
|
16
|
+
var _post_path = obj._post_path;
|
17
|
+
var _drafts_path = obj._drafts_path;
|
18
|
+
var _posts_path = obj._posts_path;
|
19
|
+
var _ajax_path = obj._ajax_path;
|
20
|
+
var _post_tags_path = obj._post_tags_path;
|
21
|
+
|
22
|
+
App_post.save_draft_ajax = function(callback){
|
23
|
+
_draft_inited = true;
|
24
|
+
var data = $form.serializeObject();
|
25
|
+
data._method = post_draft_id ? 'patch': 'post';
|
26
|
+
data.post_id = post_id;
|
27
|
+
if(data.post.title && $form.data("hash") != get_hash_form()){
|
28
|
+
$.ajax({
|
29
|
+
type: 'POST',
|
30
|
+
url: _drafts_path,
|
31
|
+
data: data,
|
32
|
+
success: function(res){
|
33
|
+
if(res.error){
|
34
|
+
$.fn.alert({type: 'error', title: res.error.join(", "), icon: "times"})
|
35
|
+
}else{
|
36
|
+
if(res._drafts_path) _drafts_path = res._drafts_path
|
37
|
+
post_draft_id = res.draft.id
|
38
|
+
$("#post_draft_id").val(post_draft_id);
|
39
|
+
}
|
40
|
+
if(callback) callback(res);
|
41
|
+
},
|
42
|
+
dataType: 'json',
|
43
|
+
async:false
|
44
|
+
});
|
45
|
+
}
|
46
|
+
|
47
|
+
};
|
48
|
+
|
49
|
+
App_post.save_draft = function(){
|
50
|
+
App_post.save_draft_ajax(function(){
|
51
|
+
$form.data("submitted", 1);
|
52
|
+
location.href = _posts_path+'?notice='+I18n("msg.draft")
|
53
|
+
});
|
54
|
+
|
55
|
+
}
|
56
|
+
|
57
|
+
var t = setInterval(function(){
|
58
|
+
App_post.save_draft_ajax();
|
59
|
+
}, 3*60*1000);
|
60
|
+
|
61
|
+
window.save_draft = App_post.save_draft_ajax;
|
62
|
+
|
63
|
+
if($(".title-post"+class_translate).size() == 0) class_translate = '';
|
64
|
+
$(".title-post"+class_translate).each(function(){
|
65
|
+
var $this = $(this);
|
66
|
+
if(!$this.hasClass('sluged')){
|
67
|
+
if(class_translate){
|
68
|
+
var lng = $this.attr("name").match(/-(.*)-/i).pop();
|
69
|
+
var $input_slug = $('.slug-post'+class_translate+'[name^="translation-'+lng+'"]')
|
70
|
+
var post_path = _post_path.replace('____', lng)
|
71
|
+
}else{
|
72
|
+
var $input_slug = $('.slug-post');
|
73
|
+
var post_path = _post_path.replace('/____', '');
|
74
|
+
}
|
75
|
+
|
76
|
+
var $link = $('<div class="sl-slug-edit">' +
|
77
|
+
'<strong>'+I18n("msg.permalink")+': </strong><span class="sl-link"></span> <span>/ </span>' +
|
78
|
+
'<a href="#" class="btn btn-default btn-xs btn-edit">'+I18n("button.edit")+'</a> ' +
|
79
|
+
'<a href="#" class="btn btn-info btn-xs btn-preview" target="_blank">'+I18n("msg.preview")+'</a> ' +
|
80
|
+
'<a href="#" class="btn btn-success btn-xs btn-view" style="display: none" target="_blank">'+I18n("msg.view_page")+'</a>' +
|
81
|
+
'</div>').hide();
|
82
|
+
$this.addClass('sluged');
|
83
|
+
$this.after($link)
|
84
|
+
|
85
|
+
function set_slug(slug){
|
86
|
+
$link.show().find('.sl-link').html(post_path.replace('__-__', '<span class="sl-url">' + slug + '</span>'))
|
87
|
+
$link.find('.btn-preview').attr('href', post_path.replace('__-__', slug ) + '?draft_id='+post_draft_id)
|
88
|
+
$input_slug.trigger('change_in');
|
89
|
+
set_meta_slug();
|
90
|
+
}
|
91
|
+
var xhr = null;
|
92
|
+
function ajax_set_slug(slug){
|
93
|
+
if(xhr) xhr.abort();
|
94
|
+
xhr = $.ajax({
|
95
|
+
type: "POST",
|
96
|
+
url: _ajax_path,
|
97
|
+
data: {method: 'exist_slug', slug: slug, post_id: post_id},
|
98
|
+
success: function(res){
|
99
|
+
if(res.index > 0){
|
100
|
+
$input_slug.addClass('slugify-locked').val(res.slug);
|
101
|
+
set_slug(res.slug)
|
102
|
+
}
|
103
|
+
|
104
|
+
}
|
105
|
+
});
|
106
|
+
}
|
107
|
+
|
108
|
+
function set_meta_slug(){
|
109
|
+
$('#meta_slug').val($('.slug-post'+class_translate).map(function(){return this.value;}).get().join(","));
|
110
|
+
}
|
111
|
+
var slug_tmp = null;
|
112
|
+
$input_slug.slugify($this, {
|
113
|
+
change: function(slug) {
|
114
|
+
slug_tmp = slug;
|
115
|
+
set_slug(slug);
|
116
|
+
}
|
117
|
+
}
|
118
|
+
);
|
119
|
+
|
120
|
+
$this.change(function(){
|
121
|
+
if(slug_tmp) ajax_set_slug(slug_tmp);
|
122
|
+
if(!_draft_inited) App_post.save_draft_ajax();
|
123
|
+
});
|
124
|
+
if($input_slug.val()){
|
125
|
+
set_slug($input_slug.val());
|
126
|
+
if(post_status == "published") $link.find('.btn-view').show().attr('href', post_path.replace('__-__', $input_slug.val() ))
|
127
|
+
}
|
128
|
+
$link.find('.btn-preview').click(function(){
|
129
|
+
var href = $(this).attr('href');
|
130
|
+
App_post.save_draft_ajax();
|
131
|
+
var ar = href.split("draft_id=");
|
132
|
+
ar[1] = post_draft_id;
|
133
|
+
$(this).attr('href', ar.join("draft_id="))
|
134
|
+
});
|
135
|
+
$link.find('.btn-edit').click(function(){
|
136
|
+
var $btn = $(this);
|
137
|
+
var $btn_edit = $('<a href="#" class="btn btn-default btn-xs btn-edit">'+I18n("button.accept")+'</a> <a href="#" class="btn-cancel">'+I18n("button.cancel")+'</a>');
|
138
|
+
var $label = $link.find('.sl-url');
|
139
|
+
var $input = $("<input type='text' />");
|
140
|
+
$label.hide().after($input);
|
141
|
+
$btn.hide().after($btn_edit);
|
142
|
+
$input.val($label.text());
|
143
|
+
|
144
|
+
function set_delete(){
|
145
|
+
$label.show();
|
146
|
+
$btn.show();
|
147
|
+
$input.remove();
|
148
|
+
$btn_edit.remove();
|
149
|
+
}
|
150
|
+
|
151
|
+
$btn_edit.filter('.btn-cancel').click(function(){
|
152
|
+
set_delete();
|
153
|
+
set_meta_slug()
|
154
|
+
return false;
|
155
|
+
});
|
156
|
+
$btn_edit.filter('.btn-edit').click(function(){
|
157
|
+
var value_new_slug = slugFunc($input.val());
|
158
|
+
if(value_new_slug){
|
159
|
+
$input_slug.addClass('slugify-locked').val(value_new_slug);
|
160
|
+
ajax_set_slug(value_new_slug)
|
161
|
+
set_slug(value_new_slug)
|
162
|
+
set_delete();
|
163
|
+
}
|
164
|
+
return false;
|
165
|
+
});
|
166
|
+
return false;
|
167
|
+
});
|
168
|
+
}
|
169
|
+
});
|
170
|
+
|
171
|
+
tinymce.init(cama_get_tinymce_settings({selector: '.tinymce_textarea:not(.translated-item)', height: '480px', onPostRender: onEditorPostRender}));
|
172
|
+
|
173
|
+
$form.validate();
|
174
|
+
/*
|
175
|
+
* skip translation inputs
|
176
|
+
submitHandler: function(form){
|
177
|
+
jQuery(form).find(".translate-item").prop("disabled", false).attr("disabled", "disabled");
|
178
|
+
form.submit();
|
179
|
+
}
|
180
|
+
* */
|
181
|
+
|
182
|
+
$("#post_status").change(function(){
|
183
|
+
$('#post-actions .btn[data-type]').hide();
|
184
|
+
$('#post-actions .btn[data-type="'+ $(this).val() +'"]').show();
|
185
|
+
});
|
186
|
+
|
187
|
+
// here all later actions
|
188
|
+
var form_later_actions = function(){
|
189
|
+
/*********** scroller (fix buttons position) ***************/
|
190
|
+
var panel_scroll = $("#form-post > .content-frame-right");
|
191
|
+
var fixed_position = panel_scroll.children(":first");
|
192
|
+
var fixed_offset_top = panel_scroll.offset().top;
|
193
|
+
$(window).scroll(function(){ if($(window).width() < 1024){ fixed_position.css({position: "", width: ""}); panel_scroll.css("padding-top", ""); return; } if ($(window).scrollTop() >= fixed_offset_top+10){ fixed_position.css({position: "fixed", width: "279px", top: 0, "z-index": 4}); panel_scroll.css("padding-top", fixed_position.height()+20) } else { fixed_position.css({position: "", width: "auto"}); panel_scroll.css("padding-top", "") }}).resize(function(){ if($(window).width() >= 1024){ panel_scroll.show(); } }).scroll();
|
194
|
+
/*********** end scroller buttons ***************/
|
195
|
+
|
196
|
+
/********** post tagEditor ******************/
|
197
|
+
var post_tags = $.ajax({
|
198
|
+
type: 'GET',
|
199
|
+
url: _post_tags_path,
|
200
|
+
dataType: "json",
|
201
|
+
async: false
|
202
|
+
}).responseText;
|
203
|
+
|
204
|
+
$form.find(".tagsinput").tagEditor({
|
205
|
+
autocomplete: { delay: 0, position: { collision: 'flip' }, source: $.parseJSON(post_tags) },
|
206
|
+
forceLowercase: false,
|
207
|
+
placeholder: I18n("button.add_tag") + '...'
|
208
|
+
});
|
209
|
+
/********** end post tagEditor **************/
|
210
|
+
////// thumbnail
|
211
|
+
$form.on("click", ".gallery-item-remove", function(){
|
212
|
+
$('#feature-image').hide();
|
213
|
+
$('#feature-image input').val('');
|
214
|
+
return false;
|
215
|
+
});
|
216
|
+
|
217
|
+
// sidebar toggle
|
218
|
+
$("#admin_content .content-frame-right-toggle").on("click",function(){ $(".content-frame-right").is(":visible") ? $(".content-frame-right").hide() : $(".content-frame-right").show(); });
|
219
|
+
|
220
|
+
/*********** control save changes before unload form. ***************/
|
221
|
+
$form.submit(function(){ if($(this).valid()) $form.data("submitted", 1); });
|
222
|
+
window.onbeforeunload = function (){
|
223
|
+
if($form.data("submitted"))
|
224
|
+
return;
|
225
|
+
if($form.data("hash") != get_hash_form()){
|
226
|
+
return "You sure to leave the page without saving changes?";
|
227
|
+
}
|
228
|
+
if(!$form.data("submitted"))
|
229
|
+
return;
|
230
|
+
return "You sure to leave the page without saving changes?";
|
231
|
+
};
|
232
|
+
}
|
233
|
+
setTimeout(form_later_actions, 1000);
|
234
|
+
|
235
|
+
// wait for render editors
|
236
|
+
var wait_render;
|
237
|
+
function onEditorPostRender(editor){
|
238
|
+
if(wait_render) clearTimeout(wait_render);
|
239
|
+
wait_render = setTimeout(function(){
|
240
|
+
$form.data("hash", get_hash_form());
|
241
|
+
}, 1000);
|
242
|
+
}
|
243
|
+
function get_hash_form(){
|
244
|
+
for(editor in tinymce.editors){
|
245
|
+
editor = tinymce.editors[editor];
|
246
|
+
var i = $("#"+editor.id).val(tinymce.get(editor.id).getContent()).trigger("change");
|
247
|
+
}
|
248
|
+
return $form.serialize();
|
249
|
+
}
|
250
|
+
|
251
|
+
if(obj.recover_draft == "true"){
|
252
|
+
$form.data("validator").cancelSubmit = true;
|
253
|
+
$('#post_status').val('published');
|
254
|
+
$form.submit();
|
255
|
+
}
|
256
|
+
}
|
257
|
+
|
258
|
+
// thumbnail updloader
|
259
|
+
function upload_feature_image(){
|
260
|
+
$.fn.upload_elfinder({
|
261
|
+
selected: function(res){
|
262
|
+
var image = _.first(res)
|
263
|
+
if(image.mime && image.mime.indexOf("image") > -1){
|
264
|
+
$('#feature-image img').attr('src', image.url);
|
265
|
+
$('#feature-image input').val(image.url);
|
266
|
+
$('#feature-image .meta strong').html(image.name);
|
267
|
+
$('#feature-image').show();
|
268
|
+
}else{
|
269
|
+
alert("You must upload an image")
|
270
|
+
}
|
271
|
+
}
|
272
|
+
});
|
273
|
+
}
|
@@ -0,0 +1,31 @@
|
|
1
|
+
tinymce.PluginManager.add('filemanager', function(editor) {
|
2
|
+
function openmanager() {
|
3
|
+
var dom = editor.dom;
|
4
|
+
$.fn.upload_elfinder({
|
5
|
+
selected: function(res){
|
6
|
+
var file = _.first(res)
|
7
|
+
var linkAttrs = {
|
8
|
+
href: file.url;
|
9
|
+
target: '_blank',
|
10
|
+
rel: null,
|
11
|
+
"class": null,
|
12
|
+
title: file.name
|
13
|
+
}
|
14
|
+
editor.insertContent(dom.createHTML('a', linkAttrs, dom.encode(file.name)));
|
15
|
+
}
|
16
|
+
});
|
17
|
+
}
|
18
|
+
editor.addButton('filemanager', {
|
19
|
+
icon: 'browse',
|
20
|
+
tooltip: 'Insert file',
|
21
|
+
onclick: openmanager,
|
22
|
+
stateSelector: 'img:not([data-mce-object])'
|
23
|
+
});
|
24
|
+
editor.addMenuItem('filemanager', {
|
25
|
+
icon: 'browse',
|
26
|
+
text: 'Insert file',
|
27
|
+
onclick: openmanager,
|
28
|
+
context: 'insert',
|
29
|
+
prependToContext: true
|
30
|
+
})
|
31
|
+
});
|
data/config/camaleon_plugin.json
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: camaleon_media_paperclip
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- QuintEvents
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-12-
|
11
|
+
date: 2015-12-17 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: el_finder2
|
@@ -76,7 +76,12 @@ files:
|
|
76
76
|
- MIT-LICENSE
|
77
77
|
- README.md
|
78
78
|
- Rakefile
|
79
|
+
- app/assets/javascripts/admin/custom_fields.js
|
80
|
+
- app/assets/javascripts/admin/data.js
|
79
81
|
- app/assets/javascripts/admin/elfinder/upload_elfinder.js
|
82
|
+
- app/assets/javascripts/admin/libraries.js
|
83
|
+
- app/assets/javascripts/admin/post.js
|
84
|
+
- app/assets/javascripts/admin/tinymce/plugins/filemanager/plugin.min.js
|
80
85
|
- app/controllers/plugins/camaleon_media_paperclip/admin_controller.rb
|
81
86
|
- app/helpers/plugins/camaleon_media_paperclip/helper.rb
|
82
87
|
- app/views/plugins/camaleon_media_paperclip/admin/settings.html.erb
|