2010-05-11 21:38:52 +00:00
|
|
|
/* ___ file or text ___ */
|
|
|
|
|
|
|
|
var enableFileOrTextToggling = function() {
|
|
|
|
$('div.hidden').hide();
|
|
|
|
|
|
|
|
$('span.alt').click(function(event) {
|
|
|
|
event.preventDefault();
|
|
|
|
|
|
|
|
if ($("div#file-selector").is(":hidden")) {
|
|
|
|
$("div#text-selector").slideUp("normal", function() {
|
|
|
|
$("div#file-selector").slideDown();
|
|
|
|
$("input#theme_asset_performing_plain_text").val(false);
|
|
|
|
});
|
|
|
|
} else {
|
|
|
|
$("div#file-selector").slideUp("normal", function() {
|
|
|
|
$("div#text-selector").slideDown();
|
|
|
|
$("input#theme_asset_performing_plain_text").val(true);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
});
|
2010-06-02 00:39:05 +00:00
|
|
|
}
|
2010-05-11 21:38:52 +00:00
|
|
|
|
2010-06-02 14:31:01 +00:00
|
|
|
var copyLinkToEditor = function(link, event) {
|
|
|
|
var editor = CodeMirrorEditors[0].editor;
|
|
|
|
var handle = editor.cursorLine(), position = editor.cursorPosition(handle).character;
|
|
|
|
var text = 'url("' + link.attr('href') + '")';
|
|
|
|
|
|
|
|
editor.insertIntoLine(handle, position, text);
|
|
|
|
|
|
|
|
event.stopPropagation();
|
|
|
|
event.preventDefault();
|
|
|
|
|
|
|
|
$.fancybox.close();
|
|
|
|
}
|
|
|
|
|
2010-06-02 00:39:05 +00:00
|
|
|
var setupUploader = function() {
|
|
|
|
var multipartParams = {};
|
|
|
|
multipartParams[$('meta[name=csrf-param]').attr('content')] = $('meta[name=csrf-token]').attr('content');
|
|
|
|
|
|
|
|
var uploader = new plupload.Uploader({
|
|
|
|
runtimes : 'html5,flash',
|
|
|
|
container: 'theme-images',
|
|
|
|
browse_button : 'upload-link',
|
|
|
|
max_file_size : '5mb',
|
|
|
|
url : $('a#upload-link').attr('href'),
|
|
|
|
flash_swf_url : '/javascripts/admin/plugins/plupload/plupload.flash.swf',
|
|
|
|
multipart: true,
|
|
|
|
multipart_params: multipartParams
|
|
|
|
});
|
|
|
|
|
|
|
|
uploader.bind('QueueChanged', function() {
|
|
|
|
uploader.start();
|
|
|
|
});
|
|
|
|
|
2010-06-02 14:31:01 +00:00
|
|
|
uploader.bind('FileUploaded', function(up, file, response) {
|
|
|
|
var json = JSON.parse(response.response);
|
|
|
|
|
|
|
|
if (json.status == 'success') {
|
|
|
|
var asset = $('.asset-picker ul li.new-asset')
|
|
|
|
.clone()
|
|
|
|
.insertBefore($('.asset-picker ul li.clear'))
|
|
|
|
.addClass('asset');
|
|
|
|
|
|
|
|
asset.find('h4 a').attr('href', json.url).html(json.name).bind('click', function(e) {
|
|
|
|
copyLinkToEditor($(this), e);
|
|
|
|
});
|
|
|
|
asset.find('.image .inside img').attr('src', json.vignette_url);
|
|
|
|
|
|
|
|
if ($('.asset-picker ul li.asset').length % 3 == 0)
|
|
|
|
asset.addClass('last');
|
|
|
|
|
|
|
|
asset.removeClass('new-asset');
|
|
|
|
|
2010-06-08 00:45:49 +00:00
|
|
|
$('.asset-picker p.no-items').hide();
|
|
|
|
|
2010-06-02 14:31:01 +00:00
|
|
|
$('.asset-picker ul').scrollTo($('li.asset:last'), 400);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2010-06-02 00:39:05 +00:00
|
|
|
uploader.init();
|
2010-05-11 21:38:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
$(document).ready(function() {
|
|
|
|
enableFileOrTextToggling();
|
|
|
|
|
2010-06-02 14:31:01 +00:00
|
|
|
$('code.stylesheet textarea').each(function() {
|
|
|
|
addCodeMirrorEditor(null, $(this), ["tokenizejavascript.js", "parsejavascript.js", "parsecss.js"]);
|
|
|
|
});
|
|
|
|
$('code.javascript textarea').each(function() {
|
|
|
|
addCodeMirrorEditor(null, $(this), ["parsecss.js", "tokenizejavascript.js", "parsejavascript.js"]);
|
|
|
|
});
|
2010-06-02 00:39:05 +00:00
|
|
|
|
|
|
|
$('select#theme_asset_content_type').bind('change', function() {
|
|
|
|
var editor = CodeMirrorEditors[0].editor;
|
|
|
|
editor.setParser($(this).val() == 'stylesheet' ? 'CSSParser' : 'JSParser');
|
2010-05-11 21:38:52 +00:00
|
|
|
});
|
2010-06-02 00:39:05 +00:00
|
|
|
|
|
|
|
$('a#asset-picker-link').fancybox({
|
|
|
|
'onComplete': function() {
|
|
|
|
setupUploader();
|
|
|
|
|
2010-06-02 14:31:01 +00:00
|
|
|
$('ul.assets h4 a').bind('click', function(e) { copyLinkToEditor($(this), e); });
|
2010-06-02 00:39:05 +00:00
|
|
|
}
|
|
|
|
});
|
2010-05-11 21:38:52 +00:00
|
|
|
});
|