diff options
author | Jan-Christoph Borchardt <hey@jancborchardt.net> | 2013-01-15 20:40:38 +0700 |
---|---|---|
committer | Jan-Christoph Borchardt <hey@jancborchardt.net> | 2013-01-15 20:40:38 +0700 |
commit | 6182b1353bd53bb6bdc5b06248d9742e97d2e249 (patch) | |
tree | b154b88d910c57d17b07ce482cbeb98cb791a106 /core/js | |
parent | 74b4fefda87feeaf51633ea7794ac498f7dce892 (diff) | |
parent | bb9cc227c2583adc6b51a1f6d75a9fc8333836b9 (diff) | |
download | nextcloud-server-6182b1353bd53bb6bdc5b06248d9742e97d2e249.tar.gz nextcloud-server-6182b1353bd53bb6bdc5b06248d9742e97d2e249.zip |
merge master into navigation
Diffstat (limited to 'core/js')
-rw-r--r-- | core/js/config.js | 2 | ||||
-rw-r--r-- | core/js/js.js | 19 | ||||
-rw-r--r-- | core/js/multiselect.js | 231 | ||||
-rw-r--r-- | core/js/share.js | 31 |
4 files changed, 215 insertions, 68 deletions
diff --git a/core/js/config.js b/core/js/config.js index f7a29276f7d..563df4e6632 100644 --- a/core/js/config.js +++ b/core/js/config.js @@ -50,6 +50,6 @@ OC.AppConfig={ }, deleteApp:function(app){ OC.AppConfig.postCall('deleteApp',{app:app}); - }, + } }; //TODO OC.Preferences diff --git a/core/js/js.js b/core/js/js.js index e1f213972dc..5ba7d1eef5c 100644 --- a/core/js/js.js +++ b/core/js/js.js @@ -3,14 +3,15 @@ * Add * define('DEBUG', true); * To the end of config/config.php to enable debug mode. + * The undefined checks fix the broken ie8 console */ -if (oc_debug !== true) { +if (oc_debug !== true || typeof console === "undefined" || typeof console.log === "undefined") { if (!window.console) { window.console = {}; } var methods = ['log', 'debug', 'warn', 'info', 'error', 'assert']; for (var i = 0; i < methods.length; i++) { - console[methods[i]] = function () { }; + console[methods[i]] = function () { }; } } @@ -20,7 +21,6 @@ if (oc_debug !== true) { * @param text the string to translate * @return string */ - function t(app,text, vars){ if( !( t.cache[app] )){ $.ajax(OC.filePath('core','ajax','translations.php'),{ @@ -343,8 +343,15 @@ if(typeof localStorage !=='undefined' && localStorage !== null){ return localStorage.setItem(OC.localStorage.namespace+name,JSON.stringify(item)); }, getItem:function(name){ - if(localStorage.getItem(OC.localStorage.namespace+name)===null){return null;} - return JSON.parse(localStorage.getItem(OC.localStorage.namespace+name)); + var item = localStorage.getItem(OC.localStorage.namespace+name); + if(item===null) { + return null; + } else if (typeof JSON === 'undefined') { + //fallback to jquery for IE6/7/8 + return $.parseJSON(item); + } else { + return JSON.parse(item); + } } }; }else{ @@ -607,7 +614,7 @@ $(document).ready(function(){ $('.jp-controls .jp-previous').tipsy({gravity:'nw', fade:true, live:true}); $('.jp-controls .jp-next').tipsy({gravity:'n', fade:true, live:true}); $('.password .action').tipsy({gravity:'se', fade:true, live:true}); - $('#upload a').tipsy({gravity:'w', fade:true}); + $('#upload').tipsy({gravity:'w', fade:true}); $('.selectedActions a').tipsy({gravity:'s', fade:true, live:true}); $('a.delete').tipsy({gravity: 'e', fade:true, live:true}); $('a.action').tipsy({gravity:'s', fade:true, live:true}); diff --git a/core/js/multiselect.js b/core/js/multiselect.js index c4fd74b0475..623c6e0f7e1 100644 --- a/core/js/multiselect.js +++ b/core/js/multiselect.js @@ -1,20 +1,44 @@ +/** + * @param 'createCallback' A function to be called when a new entry is created. Two arguments are supplied to this function: + * The select element used and the value of the option. If the function returns false addition will be cancelled. If it returns + * anything else it will be used as the value of the newly added option. + * @param 'createText' The placeholder text for the create action. + * @param 'title' The title to show if no options are selected. + * @param 'checked' An array containing values for options that should be checked. Any options which are already selected will be added to this array. + * @param 'labels' The corresponding labels to show for the checked items. + * @param 'oncheck' Callback function which will be called when a checkbox/radiobutton is selected. If the function returns false the input will be unchecked. + * @param 'onuncheck' @see 'oncheck'. + * @param 'singleSelect' If true radiobuttons will be used instead of checkboxes. + */ (function( $ ){ var multiSelectId=-1; - $.fn.multiSelect=function(options){ + $.fn.multiSelect=function(options) { multiSelectId++; var settings = { 'createCallback':false, 'createText':false, + 'singleSelect':false, + 'selectedFirst':false, + 'sort':true, 'title':this.attr('title'), 'checked':[], + 'labels':[], 'oncheck':false, 'onuncheck':false, 'minWidth': 'default;', }; + $(this).attr('data-msid', multiSelectId); $.extend(settings,options); - $.each(this.children(),function(i,option){ - if($(option).attr('selected') && settings.checked.indexOf($(option).val())==-1){ + $.each(this.children(),function(i,option) { + // If the option is selected, but not in the checked array, add it. + if($(option).attr('selected') && settings.checked.indexOf($(option).val()) === -1) { settings.checked.push($(option).val()); + settings.labels.push($(option).text().trim()); + } + // If the option is in the checked array but not selected, select it. + else if(settings.checked.indexOf($(option).val()) !== -1 && !$(option).attr('selected')) { + $(option).attr('selected', 'selected'); + settings.labels.push($(option).text().trim()); } }); var button=$('<div class="multiselect button"><span>'+settings.title+'</span><span>▾</span></div>'); @@ -24,24 +48,36 @@ button.selectedItems=[]; this.hide(); this.before(span); - if(settings.minWidth=='default'){ + if(settings.minWidth=='default') { settings.minWidth=button.width(); } button.css('min-width',settings.minWidth); settings.minOuterWidth=button.outerWidth()-2; button.data('settings',settings); - if(settings.checked.length>0){ - button.children('span').first().text(settings.checked.join(', ')); + + if(!settings.singleSelect && settings.checked.length>0) { + button.children('span').first().text(settings.labels.join(', ')); + } else if(settings.singleSelect) { + button.children('span').first().text(this.find(':selected').text()); } + var self = this; + self.menuDirection = 'down'; button.click(function(event){ var button=$(this); - if(button.parent().children('ul').length>0){ - button.parent().children('ul').slideUp(400,function(){ - button.parent().children('ul').remove(); - button.removeClass('active'); - }); + if(button.parent().children('ul').length>0) { + if(self.menuDirection === 'down') { + button.parent().children('ul').slideUp(400,function() { + button.parent().children('ul').remove(); + button.removeClass('active down'); + }); + } else { + button.parent().children('ul').fadeOut(400,function() { + button.parent().children('ul').remove(); + button.removeClass('active up'); + }); + } return; } var lists=$('ul.multiselectoptions'); @@ -54,49 +90,69 @@ event.stopPropagation(); var options=$(this).parent().next().children(); var list=$('<ul class="multiselectoptions"/>').hide().appendTo($(this).parent()); - function createItem(element,checked){ + var inputType = settings.singleSelect ? 'radio' : 'checkbox'; + function createItem(element, checked){ element=$(element); var item=element.val(); var id='ms'+multiSelectId+'-option-'+item; - var input=$('<input type="checkbox"/>'); + var input=$('<input type="' + inputType + '"/>'); input.attr('id',id); + if(settings.singleSelect) { + input.attr('name', 'ms'+multiSelectId+'-option'); + } var label=$('<label/>'); label.attr('for',id); - label.text(item); - if(settings.checked.indexOf(item)!=-1 || checked){ - input.attr('checked',true); + label.text(element.text() || item); + if(settings.checked.indexOf(item)!=-1 || checked) { + input.attr('checked', true); } if(checked){ - settings.checked.push(item); + if(settings.singleSelect) { + settings.checked = [item]; + settings.labels = [item]; + } else { + settings.checked.push(item); + settings.labels.push(item); + } } input.change(function(){ - var groupname=$(this).next().text(); - if($(this).is(':checked')){ + var value = $(this).attr('id').substring(String('ms'+multiSelectId+'-option').length+1); + var label = $(this).next().text().trim(); + if($(this).is(':checked')) { + if(settings.singleSelect) { + settings.checked = []; + settings.labels = []; + $.each(self.find('option'), function() { + $(this).removeAttr('selected'); + }); + } element.attr('selected','selected'); - if(settings.oncheck){ - if(settings.oncheck(groupname)===false){ + if(typeof settings.oncheck === 'function') { + if(settings.oncheck(value)===false) { $(this).attr('checked', false); return; } } - settings.checked.push(groupname); - }else{ - var index=settings.checked.indexOf(groupname); + settings.checked.push(value); + settings.labels.push(label); + $(this).parent().addClass('checked'); + } else { + var index=settings.checked.indexOf(value); element.attr('selected',null); - if(settings.onuncheck){ - if(settings.onuncheck(groupname)===false){ + if(typeof settings.onuncheck === 'function') { + if(settings.onuncheck(value)===false) { $(this).attr('checked',true); return; } } + $(this).parent().removeClass('checked'); settings.checked.splice(index,1); + settings.labels.splice(index,1); } var oldWidth=button.width(); - if(settings.checked.length>0){ - button.children('span').first().text(settings.checked.join(', ')); - }else{ - button.children('span').first().text(settings.title); - } + button.children('span').first().text(settings.labels.length > 0 + ? settings.labels.join(', ') + : settings.title); var newOuterWidth=Math.max((button.outerWidth()-2),settings.minOuterWidth)+'px'; var newWidth=Math.max(button.width(),settings.minWidth); var pos=button.position(); @@ -110,6 +166,9 @@ }); var li=$('<li></li>'); li.append(input).append(label); + if(input.is(':checked')) { + li.addClass('checked'); + } return li; } $.each(options,function(index,item){ @@ -117,13 +176,13 @@ }); button.parent().data('preventHide',false); if(settings.createText){ - var li=$('<li>+ <em>'+settings.createText+'<em></li>'); + var li=$('<li class="creator">+ <em>'+settings.createText+'<em></li>'); li.click(function(event){ li.empty(); var input=$('<input class="new">'); li.append(input); input.focus(); - input.css('width',button.width()); + input.css('width',button.innerWidth()); button.parent().data('preventHide',true); input.keypress(function(event) { if(event.keyCode == 13) { @@ -132,7 +191,7 @@ var value = $(this).val(); var exists = false; $.each(options,function(index, item) { - if ($(item).val() == value) { + if ($(item).val() == value || $(item).text() == value) { exists = true; return false; } @@ -141,22 +200,39 @@ return false; } var li=$(this).parent(); + var val = $(this).val() + var select=button.parent().next(); + if(typeof settings.createCallback === 'function') { + var response = settings.createCallback(select, val); + if(response === false) { + return false; + } else if(typeof response !== 'undefined') { + val = response; + } + } + if(settings.singleSelect) { + $.each(select.find('option:selected'), function() { + $(this).removeAttr('selected'); + }); + } $(this).remove(); li.text('+ '+settings.createText); li.before(createItem(this)); - var select=button.parent().next(); var option=$('<option selected="selected"/>'); - option.attr('value',value); - option.text($(this).val()); + option.text($(this).val()).val(val).attr('selected', 'selected'); select.append(option); - li.prev().children('input').trigger('click'); + li.prev().children('input').prop('checked', true).trigger('change'); button.parent().data('preventHide',false); - if(settings.createCallback){ - settings.createCallback($(this).val()); + button.children('span').first().text(settings.labels.length > 0 + ? settings.labels.join(', ') + : settings.title); + if(self.menuDirection === 'up') { + var list = li.parent(); + list.css('top', list.position().top-li.outerHeight()); } } }); - input.blur(function(){ + input.blur(function() { event.preventDefault(); event.stopPropagation(); $(this).remove(); @@ -168,21 +244,72 @@ }); list.append(li); } + + var doSort = function(list, selector) { + var rows = list.find('li'+selector).get(); + + if(settings.sort) { + rows.sort(function(a, b) { + return $(a).text().toUpperCase().localeCompare($(b).text().toUpperCase()); + }); + } + + $.each(rows, function(index, row) { + list.append(row); + }); + }; + if(settings.sort && settings.selectedFirst) { + doSort(list, '.checked'); + doSort(list, ':not(.checked)'); + } else if(settings.sort && !settings.selectedFirst) { + doSort(list, ''); + } + list.append(list.find('li.creator')); var pos=button.position(); - list.css('top',pos.top+button.outerHeight()-5); - list.css('left',pos.left+3); - list.css('width',(button.outerWidth()-2)+'px'); - list.slideDown(); - list.click(function(event){ + if($(document).height() > (button.offset().top+button.outerHeight() + list.children().length * button.height()) + || $(document).height()/2 > pos.top + ) { + list.css({ + top:pos.top+button.outerHeight()-5, + left:pos.left+3, + width:(button.outerWidth()-2)+'px', + 'max-height':($(document).height()-(button.offset().top+button.outerHeight()+10))+'px' + }); + list.addClass('down'); + button.addClass('down'); + list.slideDown(); + } else { + list.css('max-height', $(document).height()-($(document).height()-(pos.top)+50)+'px'); + list.css({ + top:pos.top - list.height(), + left:pos.left+3, + width:(button.outerWidth()-2)+'px' + + }); + list.detach().insertBefore($(this)); + list.addClass('up'); + button.addClass('up'); + list.fadeIn(); + self.menuDirection = 'up'; + } + list.click(function(event) { event.stopPropagation(); }); }); - $(window).click(function(){ - if(!button.parent().data('preventHide')){ - button.parent().children('ul').slideUp(400,function(){ - button.parent().children('ul').remove(); - button.removeClass('active'); - }); + $(window).click(function() { + if(!button.parent().data('preventHide')) { + // How can I save the effect in a var? + if(self.menuDirection === 'down') { + button.parent().children('ul').slideUp(400,function() { + button.parent().children('ul').remove(); + button.removeClass('active down'); + }); + } else { + button.parent().children('ul').fadeOut(400,function() { + button.parent().children('ul').remove(); + button.removeClass('active up'); + }); + } } }); diff --git a/core/js/share.js b/core/js/share.js index df5ebf008b4..bb3ec010ff5 100644 --- a/core/js/share.js +++ b/core/js/share.js @@ -161,9 +161,9 @@ OC.Share={ if (link) { html += '<div id="link">'; html += '<input type="checkbox" name="linkCheckbox" id="linkCheckbox" value="1" /><label for="linkCheckbox">'+t('core', 'Share with link')+'</label>'; - html += '<a href="#" id="showPassword" style="display:none;"><img class="svg" alt="'+t('core', 'Password protect')+'" src="'+OC.imagePath('core', 'actions/lock')+'"/></a>'; html += '<br />'; html += '<input id="linkText" type="text" readonly="readonly" />'; + html += '<input type="checkbox" name="showPassword" id="showPassword" value="1" style="display:none;" /><label for="showPassword" style="display:none;">'+t('core', 'Password protect')+'</label>'; html += '<div id="linkPass">'; html += '<input id="linkPassText" type="password" placeholder="'+t('core', 'Password')+'" />'; html += '</div>'; @@ -347,9 +347,12 @@ OC.Share={ } $('#linkText').val(link); $('#linkText').show('blind'); + $('#linkText').css('display','block'); $('#showPassword').show(); + $('#showPassword+label').show(); if (password != null) { $('#linkPass').show('blind'); + $('#showPassword').attr('checked', true); $('#linkPassText').attr('placeholder', t('core', 'Password protected')); } $('#expiration').show(); @@ -359,6 +362,7 @@ OC.Share={ hideLink:function() { $('#linkText').hide('blind'); $('#showPassword').hide(); + $('#showPassword+label').hide(); $('#linkPass').hide(); $('#emailPrivateLink #email').hide(); $('#emailPrivateLink #emailButton').hide(); @@ -518,16 +522,25 @@ $(document).ready(function() { $('#showPassword').live('click', function() { $('#linkPass').toggle('blind'); + if (!$('#showPassword').is(':checked') ) { + var itemType = $('#dropdown').data('item-type'); + var itemSource = $('#dropdown').data('item-source'); + OC.Share.share(itemType, itemSource, OC.Share.SHARE_TYPE_LINK, '', OC.PERMISSION_READ); + } else { + $('#linkPassText').focus(); + } }); - $('#linkPassText').live('focusout', function(event) { - var itemType = $('#dropdown').data('item-type'); - var itemSource = $('#dropdown').data('item-source'); - OC.Share.share(itemType, itemSource, OC.Share.SHARE_TYPE_LINK, $(this).val(), OC.PERMISSION_READ, function() { - $('#linkPassText').val(''); - $('#linkPassText').attr('placeholder', t('core', 'Password protected')); - }); - $('#linkPassText').attr('placeholder', t('core', 'Password protected')); + $('#linkPassText').live('focusout keyup', function(event) { + if ( $('#linkPassText').val() != '' && (event.type == 'focusout' || event.keyCode == 13) ) { + var itemType = $('#dropdown').data('item-type'); + var itemSource = $('#dropdown').data('item-source'); + OC.Share.share(itemType, itemSource, OC.Share.SHARE_TYPE_LINK, $('#linkPassText').val(), OC.PERMISSION_READ, function() { + console.log("password set to: '" + $('#linkPassText').val() +"' by event: " + event.type); + $('#linkPassText').val(''); + $('#linkPassText').attr('placeholder', t('core', 'Password protected')); + }); + } }); $('#expirationCheckbox').live('click', function() { |