aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/lib/scripts/media.js
diff options
context:
space:
mode:
authorGerrit Uitslag <klapinklapin@gmail.com>2016-05-11 19:15:01 +0200
committerGerrit Uitslag <klapinklapin@gmail.com>2016-05-11 19:15:01 +0200
commitc59f5183371d22c86dee319361d27b796cf72872 (patch)
tree6e5dbc27e08f46b09407401dfc1b8b8399d662d8 /lib/scripts/media.js
parent3d32f1cd26b1130d406b77631d5f2b1431f6f614 (diff)
downloaddokuwiki-c59f5183371d22c86dee319361d27b796cf72872.tar.gz
dokuwiki-c59f5183371d22c86dee319361d27b796cf72872.zip
reformatting media.js
Diffstat (limited to 'lib/scripts/media.js')
-rw-r--r--lib/scripts/media.js272
1 files changed, 141 insertions, 131 deletions
diff --git a/lib/scripts/media.js b/lib/scripts/media.js
index 2a328de3d..f8507396b 100644
--- a/lib/scripts/media.js
+++ b/lib/scripts/media.js
@@ -30,8 +30,8 @@ var dw_mediamanager = {
init: function () {
var $content, $tree;
$content = jQuery('#media__content');
- $tree = jQuery('#media__tree');
- if(!$tree.length) return;
+ $tree = jQuery('#media__tree');
+ if (!$tree.length) return;
dw_mediamanager.prepare_content($content);
@@ -45,27 +45,27 @@ var dw_mediamanager = {
.delegate('a.select', 'click', dw_mediamanager.select)
// Attach deletion confirmation dialog to the delete buttons
.delegate('#media__content a.btn_media_delete', 'click',
- dw_mediamanager.confirmattach)
+ dw_mediamanager.confirmattach)
.delegate('#mediamanager__done_form', 'submit', dw_mediamanager.list);
- $tree.dw_tree({toggle_selector: 'img',
- load_data: function (show_sublist, $clicky) {
- // get the enclosed link (is always the first one)
- var $link = $clicky.parent().find('div.li a.idx_dir');
-
- jQuery.post(
- DOKU_BASE + 'lib/exe/ajax.php',
- $link[0].search.substr(1) + '&call=medians',
- show_sublist,
- 'html'
- );
- },
-
- toggle_display: function ($clicky, opening) {
- $clicky.attr('src',
- DOKU_BASE + 'lib/images/' +
- (opening ? 'minus' : 'plus') + '.gif');
- }});
+ $tree.dw_tree({
+ toggle_selector: 'img',
+ load_data: function (show_sublist, $clicky) {
+ // get the enclosed link (is always the first one)
+ var $link = $clicky.parent().find('div.li a.idx_dir');
+
+ jQuery.post(
+ DOKU_BASE + 'lib/exe/ajax.php',
+ $link[0].search.substr(1) + '&call=medians',
+ show_sublist,
+ 'html'
+ );
+ },
+
+ toggle_display: function ($clicky, opening) {
+ $clicky.attr('src', DOKU_BASE + 'lib/images/' + (opening ? 'minus' : 'plus') + '.gif');
+ }
+ });
$tree.delegate('a', 'click', dw_mediamanager.list);
// Init view property
@@ -153,43 +153,51 @@ var dw_mediamanager = {
var opts, $insp, $insbtn;
dw_mediamanager.$popup = jQuery(document.createElement('div'))
- .attr('id', 'media__popup_content')
- .dialog({autoOpen: false, width: 280, modal: true,
- draggable: true, title: LANG.mediatitle,
- resizable: false});
-
- opts = [{id: 'link', label: LANG.mediatarget,
- btns: ['lnk', 'direct', 'nolnk', 'displaylnk']},
- {id: 'align', label: LANG.mediaalign,
- btns: ['noalign', 'left', 'center', 'right']},
- {id: 'size', label: LANG.mediasize,
- btns: ['small', 'medium', 'large', 'original']}
- ];
+ .attr('id', 'media__popup_content')
+ .dialog({
+ autoOpen: false, width: 280, modal: true,
+ draggable: true, title: LANG.mediatitle,
+ resizable: false
+ });
+
+ opts = [
+ {
+ id: 'link', label: LANG.mediatarget,
+ btns: ['lnk', 'direct', 'nolnk', 'displaylnk']
+ },
+ {
+ id: 'align', label: LANG.mediaalign,
+ btns: ['noalign', 'left', 'center', 'right']
+ },
+ {
+ id: 'size', label: LANG.mediasize,
+ btns: ['small', 'medium', 'large', 'original']
+ }
+ ];
jQuery.each(opts, function (_, opt) {
var $p, $l;
$p = jQuery(document.createElement('p'))
- .attr('id', 'media__' + opt.id);
+ .attr('id', 'media__' + opt.id);
if (dw_mediamanager.display === "2") {
$p.hide();
}
$l = jQuery(document.createElement('label'))
- .text(opt.label);
+ .text(opt.label);
$p.append($l);
jQuery.each(opt.btns, function (i, text) {
var $btn, $img;
$btn = jQuery(document.createElement('button'))
- .addClass('button')
- .attr('id', "media__" + opt.id + "btn" + (i + 1))
- .attr('title', LANG['media' + text])
- .click(bind(dw_mediamanager.setOpt, opt.id));
+ .addClass('button')
+ .attr('id', "media__" + opt.id + "btn" + (i + 1))
+ .attr('title', LANG['media' + text])
+ .click(bind(dw_mediamanager.setOpt, opt.id));
$img = jQuery(document.createElement('img'))
- .attr('src', DOKU_BASE + 'lib/images/media_' +
- opt.id + '_' + text + '.png');
+ .attr('src', DOKU_BASE + 'lib/images/media_' + opt.id + '_' + text + '.png');
$btn.append($img);
$p.append($btn);
@@ -203,10 +211,10 @@ var dw_mediamanager = {
dw_mediamanager.$popup.append($insp);
$insbtn = jQuery(document.createElement('input'))
- .attr('id', 'media__sendbtn')
- .attr('type', 'button')
- .addClass('button')
- .val(LANG.mediainsert);
+ .attr('id', 'media__sendbtn')
+ .attr('type', 'button')
+ .addClass('button')
+ .val(LANG.mediainsert);
$insp.append($insbtn);
},
@@ -228,7 +236,7 @@ var dw_mediamanager = {
if ({img: 1, swf: 1}[dw_mediamanager.ext] === 1) {
if (dw_mediamanager.link === '4') {
- opts = '?linkonly';
+ opts = '?linkonly';
} else {
if (dw_mediamanager.link === "3" && dw_mediamanager.ext === 'img') {
@@ -240,19 +248,19 @@ var dw_mediamanager = {
s = parseInt(dw_mediamanager.size, 10);
if (s && s >= 1 && s < 4) {
- opts += (opts.length)?'&':'?';
+ opts += (opts.length) ? '&' : '?';
opts += dw_mediamanager.size + '00';
if (dw_mediamanager.ext === 'swf') {
switch (s) {
- case 1:
- opts += 'x62';
- break;
- case 2:
- opts += 'x123';
- break;
- case 3:
- opts += 'x185';
- break;
+ case 1:
+ opts += 'x62';
+ break;
+ case 2:
+ opts += 'x123';
+ break;
+ case 3:
+ opts += 'x185';
+ break;
}
}
}
@@ -260,11 +268,11 @@ var dw_mediamanager = {
}
edid = String.prototype.match.call(document.location, /&edid=([^&]+)/);
edid = edid ? edid[1] : 'wiki__text';
- cb = String.prototype.match.call(document.location, /&onselect=([^&]+)/);
- cb = cb ? cb[1].replace(/[^\w]+/, '') : 'dw_mediamanager_item_select';
+ cb = String.prototype.match.call(document.location, /&onselect=([^&]+)/);
+ cb = cb ? cb[1].replace(/[^\w]+/, '') : 'dw_mediamanager_item_select';
opener[cb](edid, id, opts, dw_mediamanager.align);
- if(!dw_mediamanager.keepopen) {
+ if (!dw_mediamanager.keepopen) {
window.close();
}
opener.focus();
@@ -272,13 +280,12 @@ var dw_mediamanager = {
},
-
/**
* Prefills the wikiname.
*
* @author Andreas Gohr <andi@splitbrain.org>
*/
- suggest: function(){
+ suggest: function () {
var $file, $name, text;
$file = jQuery(this);
@@ -286,13 +293,13 @@ var dw_mediamanager = {
if ($name.val() != '') return;
- if(!$file.length || !$name.length) {
+ if (!$file.length || !$name.length) {
return;
}
text = $file.val();
- text = text.substr(text.lastIndexOf('/')+1);
- text = text.substr(text.lastIndexOf('\\')+1);
+ text = text.substr(text.lastIndexOf('/') + 1);
+ text = text.substr(text.lastIndexOf('\\') + 1);
$name.val(text);
},
@@ -342,24 +349,27 @@ var dw_mediamanager = {
dw_mediamanager.update_content($content, params);
},
- /**
+ /**
* Returns form parameters
*
* @author Kate Arzamastseva <pshns@ukr.net>
*/
form_params: function ($form) {
if (!$form.length) return;
+
var action = '';
var i = $form[0].action.indexOf('?');
- if (i >= 0) action = $form[0].action.substr(i+1);
- return action+'&'+$form.serialize();
+ if (i >= 0) {
+ action = $form[0].action.substr(i + 1);
+ }
+ return action + '&' + $form.serialize();
},
set_fileview_list: function (new_type) {
dw_mediamanager.set_fileview_opt(['list', 'listType', function (new_type) {
jQuery('div.filelist div.panelContent ul')
- .toggleClass('rows', new_type === 'rows')
- .toggleClass('thumbs', new_type === 'thumbs');
+ .toggleClass('rows', new_type === 'rows')
+ .toggleClass('thumbs', new_type === 'thumbs');
}], new_type);
// FIXME: Move to onchange handler (opt[2])?
@@ -375,7 +385,7 @@ var dw_mediamanager = {
set_fileview_opt: function (opt, new_val) {
if (typeof new_val === 'undefined') {
new_val = jQuery('form.options li.' + opt[1] + ' input')
- .filter(':checked').val();
+ .filter(':checked').val();
// if new_val is still undefined (because form.options is not in active tab), set to most spacious option
if (typeof new_val === 'undefined') {
new_val = 'thumbs';
@@ -391,7 +401,7 @@ var dw_mediamanager = {
}
},
- /**
+ /**
* Lists the content of the right column (image details) using AJAX
*
* @author Kate Arzamastseva <pshns@ukr.net>
@@ -422,7 +432,7 @@ var dw_mediamanager = {
}
update_list = ($link[0].id == 'mediamanager__btn_delete' ||
- $link[0].id == 'mediamanager__btn_restore');
+ $link[0].id == 'mediamanager__btn_restore');
dw_mediamanager.update_content($content, params, update_list);
},
@@ -485,12 +495,12 @@ var dw_mediamanager = {
var $resizables = dw_mediamanager.$resizables();
$resizables.resizable({
- handles: (jQuery('html[dir=rtl]').length ? 'w' :'e'),
- resize: function(event, ui){
+ handles: (jQuery('html[dir=rtl]').length ? 'w' : 'e'),
+ resize: function (event, ui) {
var $page = jQuery('#mediamanager__page');
var widthFull = $page.width();
var widthResizables = 0;
- $resizables.each(function() {
+ $resizables.each(function () {
widthResizables += jQuery(this).width();
});
var $filePanel = $page.find('div.panel.file');
@@ -499,17 +509,17 @@ var dw_mediamanager = {
var widthOtherResizable = widthResizables - jQuery(this).width();
var minWidthNonResizable = parseFloat($filePanel.css("min-width"));
var maxWidth = widthFull - (widthOtherResizable + minWidthNonResizable) - 1;
- $resizables.resizable( "option", "maxWidth", maxWidth );
+ $resizables.resizable("option", "maxWidth", maxWidth);
// width of file panel in % = 100% - width of resizables in %
// this calculates with 99.9 and not 100 to overcome rounding errors
var relWidthNonResizable = 99.9 - (100 * widthResizables / widthFull);
// set width of file panel
- $filePanel.width(relWidthNonResizable+'%');
+ $filePanel.width(relWidthNonResizable + '%');
// FIXME: please fix without browser sniffing
if (!jQuery.browser.webkit) {
- $resizables.each(function() {
+ $resizables.each(function () {
var w = jQuery(this).width();
w = (99.99 * w / widthFull);
w += "%";
@@ -541,13 +551,12 @@ var dw_mediamanager = {
$contents.height(height);
dw_mediamanager.$resizables().each(function () {
var $this = jQuery(this);
- $this.height(height + $this.find('div.panelContent').offset().top -
- $this.offset().top);
+ $this.height(height + $this.find('div.panelContent').offset().top - $this.offset().top);
});
}
},
- /**
+ /**
* Prints 'select' for image difference representation type
*
* @author Kate Arzamastseva <pshns@ukr.net>
@@ -559,11 +568,11 @@ var dw_mediamanager = {
if (!$form.length) return;
var $label = jQuery(document.createElement('label'));
- $label.append('<span>'+LANG.media_diff+'</span> ');
+ $label.append('<span>' + LANG.media_diff + '</span> ');
var $select = jQuery(document.createElement('select'))
- .attr('id', 'mediamanager__difftype')
- .attr('name', 'difftype')
- .change(dw_mediamanager.change_diff_type);
+ .attr('id', 'mediamanager__difftype')
+ .attr('name', 'difftype')
+ .change(dw_mediamanager.change_diff_type);
$select.append(new Option(LANG.media_diff_both, "both"));
$select.append(new Option(LANG.media_diff_opacity, "opacity"));
$select.append(new Option(LANG.media_diff_portions, "portions"));
@@ -586,7 +595,7 @@ var dw_mediamanager = {
var $select = jQuery('#mediamanager__difftype');
var $content = jQuery('#mediamanager__diff');
- var params = dw_mediamanager.form_params($select.closest('form'))+'&call=mediadiff';
+ var params = dw_mediamanager.form_params($select.closest('form')) + '&call=mediadiff';
jQuery.post(
DOKU_BASE + 'lib/exe/ajax.php',
params,
@@ -611,19 +620,19 @@ var dw_mediamanager = {
var $image = $diff.find('div.imageDiff.opacity div.image1 img');
if (!$image.length) return;
- $slider.width($image.width()-20);
+ $slider.width($image.width() - 20);
$slider.slider();
$slider.slider("option", "min", 0);
$slider.slider("option", "max", 0.999);
$slider.slider("option", "step", 0.001);
$slider.slider("option", "value", 0.5);
- $slider.bind("slide", function(event, ui) {
- jQuery('#mediamanager__diff').find('div.imageDiff.opacity div.image2 img').css({ opacity: $slider.slider("option", "value")});
+ $slider.bind("slide", function (event, ui) {
+ jQuery('#mediamanager__diff').find('div.imageDiff.opacity div.image2 img').css({opacity: $slider.slider("option", "value")});
});
},
- /**
+ /**
* Sets options for red line diff slider
*
* @author Kate Arzamastseva <pshns@ukr.net>
@@ -651,15 +660,15 @@ var dw_mediamanager = {
var $slider = $diff.find("div.slider");
if (!$slider.length) return;
- $slider.width($image1.width()-20);
+ $slider.width($image1.width() - 20);
$slider.slider();
$slider.slider("option", "min", 0);
$slider.slider("option", "max", 97);
$slider.slider("option", "step", 1);
$slider.slider("option", "value", 50);
- $slider.bind("slide", function(event, ui) {
- jQuery('#mediamanager__diff').find('div.imageDiff.portions div.image2').css({ width: $slider.slider("option", "value")+'%'});
+ $slider.bind("slide", function (event, ui) {
+ jQuery('#mediamanager__diff').find('div.imageDiff.portions div.image2').css({width: $slider.slider("option", "value") + '%'});
});
},
@@ -671,7 +680,7 @@ var dw_mediamanager = {
params_toarray: function (str) {
var vars = [], hash;
var hashes = str.split('&');
- for(var i = 0; i < hashes.length; i++) {
+ for (var i = 0; i < hashes.length; i++) {
hash = hashes[i].split('=');
vars[decodeURIComponent(hash[0])] = decodeURIComponent(hash[1]);
}
@@ -682,7 +691,7 @@ var dw_mediamanager = {
if (!jQuery('#mediamanager__uploader').length) return;
if (jQuery('.qq-upload-list').length) return;
- var params = dw_mediamanager.form_params(jQuery('#dw__upload'))+'&call=mediaupload';
+ var params = dw_mediamanager.form_params(jQuery('#dw__upload')) + '&call=mediaupload';
params = dw_mediamanager.params_toarray(params);
var uploader = new qq.FileUploaderExtended({
@@ -700,7 +709,7 @@ var dw_mediamanager = {
/**
* shows the popup for a image link
*/
- select: function(event){
+ select: function (event) {
var $link, id, dot, ext;
event.preventDefault();
@@ -708,12 +717,12 @@ var dw_mediamanager = {
$link = jQuery(this);
id = $link.attr('id').substr(2);
- if(!opener){
+ if (!opener) {
// if we don't run in popup display example
// the id's are a bit wierd and jQuery('#ex_wiki_dokuwiki-128.png')
// will not be found by Sizzle (the CSS Selector Engine
// used by jQuery), hence the document.getElementById() call
- jQuery(document.getElementById('ex_'+id.replace(/:/g,'_').replace(/^_/,''))).dw_toggle();
+ jQuery(document.getElementById('ex_' + id.replace(/:/g, '_').replace(/^_/, ''))).dw_toggle();
return;
}
@@ -727,7 +736,7 @@ var dw_mediamanager = {
ext = id.substr(dot);
- if ({'.jpg':1, '.jpeg':1, '.png':1, '.gif':1, '.swf':1}[ext] !== 1) {
+ if ({'.jpg': 1, '.jpeg': 1, '.png': 1, '.gif': 1, '.swf': 1}[ext] !== 1) {
dw_mediamanager.insert(id);
return;
}
@@ -739,8 +748,10 @@ var dw_mediamanager = {
dw_mediamanager.unforbid('ext');
if (ext === '.swf') {
dw_mediamanager.ext = 'swf';
- dw_mediamanager.forbid('ext', {link: ['1', '2'],
- size: ['4']});
+ dw_mediamanager.forbid('ext', {
+ link: ['1', '2'],
+ size: ['4']
+ });
} else {
dw_mediamanager.ext = 'img';
}
@@ -765,8 +776,8 @@ var dw_mediamanager = {
* @author Michael Klier <chi@chimeric.de>
* @author Pierre Spring <pierre.spring@caillou.ch>
*/
- confirmattach: function(e){
- if(!confirm(LANG.del_confirm + "\n" + jQuery(this).attr('title'))) {
+ confirmattach: function (e) {
+ if (!confirm(LANG.del_confirm + "\n" + jQuery(this).attr('title'))) {
e.preventDefault();
}
},
@@ -777,41 +788,40 @@ var dw_mediamanager = {
* @author Andreas Gohr <andi@splitbrain.org>
* @author Pierre Spring <pierre.spring@caillou.ch>
*/
- attachoptions: function(){
+ attachoptions: function () {
var $obj, opts;
$obj = jQuery('#media__opts');
- if($obj.length === 0) {
+ if ($obj.length === 0) {
return;
}
opts = [];
// keep open
- if(opener){
+ if (opener) {
opts.push(['keepopen', 'keepopen']);
}
opts.push(['hide', 'hidedetails']);
jQuery.each(opts,
- function(_, opt) {
- var $box, $lbl;
- $box = jQuery(document.createElement('input'))
- .attr('type', 'checkbox')
- .attr('id', 'media__' + opt[0])
- .click(bind(dw_mediamanager.toggleOption,
- opt[0]));
-
- if(DokuCookie.getValue(opt[0])){
- $box.prop('checked', true);
- dw_mediamanager[opt[0]] = true;
- }
+ function (_, opt) {
+ var $box, $lbl;
+ $box = jQuery(document.createElement('input'))
+ .attr('type', 'checkbox')
+ .attr('id', 'media__' + opt[0])
+ .click(bind(dw_mediamanager.toggleOption, opt[0]));
+
+ if (DokuCookie.getValue(opt[0])) {
+ $box.prop('checked', true);
+ dw_mediamanager[opt[0]] = true;
+ }
- $lbl = jQuery(document.createElement('label'))
- .attr('for', 'media__' + opt[0])
- .text(LANG[opt[1]]);
+ $lbl = jQuery(document.createElement('label'))
+ .attr('for', 'media__' + opt[0])
+ .text(LANG[opt[1]]);
- $obj.append($box, $lbl, document.createElement('br'));
- });
+ $obj.append($box, $lbl, document.createElement('br'));
+ });
dw_mediamanager.updatehide();
},
@@ -840,7 +850,7 @@ var dw_mediamanager = {
*
* @author Andreas Gohr <andi@splitbrain.org>
*/
- updatehide: function(){
+ updatehide: function () {
jQuery('#media__content').find('div.detail').dw_toggle(!dw_mediamanager.hide);
},
@@ -849,7 +859,7 @@ var dw_mediamanager = {
*
* @author Dominik Eckelmann <eckelmann@cosmocode.de>
*/
- setOpt: function(opt, e){
+ setOpt: function (opt, e) {
var val, i;
if (typeof e !== 'undefined') {
val = this.id.substring(this.id.length - 1);
@@ -858,7 +868,7 @@ var dw_mediamanager = {
}
if (val === false) {
- DokuCookie.setValue(opt,'');
+ DokuCookie.setValue(opt, '');
dw_mediamanager[opt] = false;
return;
}
@@ -895,11 +905,11 @@ var dw_mediamanager = {
allowedOpt: function (opt, val) {
var ret = true;
jQuery.each(dw_mediamanager.forbidden_opts,
- function (_, forbids) {
- ret = forbids[opt] !== false &&
- jQuery.inArray(val, forbids[opt]) === -1;
- return ret;
- });
+ function (_, forbids) {
+ ret = forbids[opt] !== false &&
+ jQuery.inArray(val, forbids[opt]) === -1;
+ return ret;
+ });
return ret;
},