diff options
author | Bart Visscher <bartv@thisnet.nl> | 2012-08-30 21:49:28 +0200 |
---|---|---|
committer | Bart Visscher <bartv@thisnet.nl> | 2012-08-30 21:49:28 +0200 |
commit | b483f2aab856e3324026588a9702043072fd7ad2 (patch) | |
tree | 9a5696d43ae53160bee592e1b6874185cbd98ad4 /core/js | |
parent | cbaf858dea0f2094805edb6aa223bdd6877fff5b (diff) | |
parent | 598815b21e94219eb66684c64802e165a35180ad (diff) | |
download | nextcloud-server-b483f2aab856e3324026588a9702043072fd7ad2.tar.gz nextcloud-server-b483f2aab856e3324026588a9702043072fd7ad2.zip |
Merge branch 'master' into routing
Conflicts:
apps/contacts/js/contacts.js
apps/contacts/lib/search.php
apps/files_archive/js/archive.js
apps/gallery/lib/tiles.php
apps/gallery/templates/index.php
lib/ocs.php
Diffstat (limited to 'core/js')
-rw-r--r-- | core/js/LICENSE.jquery.inview | 41 | ||||
-rw-r--r-- | core/js/jquery.inview.js | 134 | ||||
-rw-r--r-- | core/js/jquery.inview.txt | 15 | ||||
-rw-r--r-- | core/js/js.js | 19 | ||||
-rw-r--r-- | core/js/share.js | 119 |
5 files changed, 265 insertions, 63 deletions
diff --git a/core/js/LICENSE.jquery.inview b/core/js/LICENSE.jquery.inview new file mode 100644 index 00000000000..1ed340edbe5 --- /dev/null +++ b/core/js/LICENSE.jquery.inview @@ -0,0 +1,41 @@ +Attribution-Non-Commercial-Share Alike 2.0 UK: England & Wales + +http://creativecommons.org/licenses/by-nc-sa/2.0/uk/ + +You are free: + + * to copy, distribute, display, and perform the work + * to make derivative works + + +Under the following conditions: + + * Attribution — You must give the original author credit. + Attribute this work: + Information + What does "Attribute this work" mean? + The page you came from contained embedded licensing metadata, + including how the creator wishes to be attributed for re-use. + You can use the HTML here to cite the work. Doing so will + also include metadata on your page so that others can find the + original work as well. + + * Non-Commercial — You may not use this work for commercial + purposes. + * Share Alike — If you alter, transform, or build upon this + work, you may distribute the resulting work only under a + licence identical to this one. + +With the understanding that: + + * Waiver — Any of the above conditions can be waived if you get + permission from the copyright holder. + * Other Rights — In no way are any of the following rights + affected by the license: + o Your fair dealing or fair use rights; + o The author's moral rights; + o Rights other persons may have either in the work itself + or in how the work is used, such as publicity or privacy rights. + * Notice — For any reuse or distribution, you must make clear to + others the licence terms of this work. + diff --git a/core/js/jquery.inview.js b/core/js/jquery.inview.js new file mode 100644 index 00000000000..9687cd83368 --- /dev/null +++ b/core/js/jquery.inview.js @@ -0,0 +1,134 @@ +/** + * author Christopher Blum + * - based on the idea of Remy Sharp, http://remysharp.com/2009/01/26/element-in-view-event-plugin/ + * - forked from http://github.com/zuk/jquery.inview/ + */ +(function ($) { + var inviewObjects = {}, viewportSize, viewportOffset, + d = document, w = window, documentElement = d.documentElement, expando = $.expando, isFiring = false, $elements = {}; + + $.event.special.inview = { + add: function(data) { + var inviewObject = { data: data, $element: $(this) } + inviewObjects[data.guid + "-" + this[expando]] = inviewObject; + var selector = inviewObject.data.selector, + $element = inviewObject.$element; + var hash = parseInt(getHash( data.guid + this[expando])); + $elements[hash] = selector ? $element.find(selector) : $element; + }, + + remove: function(data) { + try { delete inviewObjects[data.guid + "-" + this[expando]]; } catch(e) {} + try { + var hash = parseInt(getHash(data.guid + this[expando])); + delete($elements[hash]); + } catch (e){} + } + }; + + + function getHash(str){ + str = str+''; + var hash = 0; + if (str.length == 0) return hash; + for (i = 0; i < str.length; i++) { + char = str.charCodeAt(i); + hash = ((hash<<5)-hash)+char; + hash = hash & hash; // Convert to 32bit integer + } + return Math.abs(hash); + } + + function getViewportSize() { + var mode, domObject, size = { height: w.innerHeight, width: w.innerWidth }; + + // if this is correct then return it. iPad has compat Mode, so will + // go into check clientHeight/clientWidth (which has the wrong value). + if (!size.height) { + mode = d.compatMode; + if (mode || !$.support.boxModel) { // IE, Gecko + domObject = mode === 'CSS1Compat' ? + documentElement : // Standards + d.body; // Quirks + size = { + height: domObject.clientHeight, + width: domObject.clientWidth + }; + } + } + + return size; + } + + function getViewportOffset() { + return { + top: w.pageYOffset || documentElement.scrollTop || (d.body?d.body.scrollTop:0), + left: w.pageXOffset || documentElement.scrollLeft || (d.body?d.body.scrollLeft:0) + }; + } + + function checkInView() { + if (isFiring){ + return; + } + isFiring = true; + viewportSize = viewportSize || getViewportSize(); + viewportOffset = viewportOffset || getViewportOffset(); + + for (var i in $elements) { + if (isNaN(parseInt(i))) { + continue; + } + + var $element = $($elements[i]), + elementSize = { height: $element.height(), width: $element.width() }, + elementOffset = $element.offset(), + inView = $element.data('inview'), + visiblePartX, + visiblePartY, + visiblePartsMerged; + + // Don't ask me why because I haven't figured out yet: + // viewportOffset and viewportSize are sometimes suddenly null in Firefox 5. + // Even though it sounds weird: + // It seems that the execution of this function is interferred by the onresize/onscroll event + // where viewportOffset and viewportSize are unset + if (!viewportOffset || !viewportSize) { + isFiring = false; + return; + } + + if (elementOffset.top + elementSize.height > viewportOffset.top && + elementOffset.top < viewportOffset.top + viewportSize.height && + elementOffset.left + elementSize.width > viewportOffset.left && + elementOffset.left < viewportOffset.left + viewportSize.width) { + visiblePartX = (viewportOffset.left > elementOffset.left ? + 'right' : (viewportOffset.left + viewportSize.width) < (elementOffset.left + elementSize.width) ? + 'left' : 'both'); + visiblePartY = (viewportOffset.top > elementOffset.top ? + 'bottom' : (viewportOffset.top + viewportSize.height) < (elementOffset.top + elementSize.height) ? + 'top' : 'both'); + visiblePartsMerged = visiblePartX + "-" + visiblePartY; + if (!inView || inView !== visiblePartsMerged) { + $element.data('inview', visiblePartsMerged).trigger('inview', [true, visiblePartX, visiblePartY]); + } + } else if (inView) { + $element.data('inview', false).trigger('inview', [false]); + } + } + isFiring = false; + } + + $(w).bind("scroll resize", function() { + viewportSize = viewportOffset = null; + }); + + // Use setInterval in order to also make sure this captures elements within + // "overflow:scroll" elements or elements that appeared in the dom tree due to + // dom manipulation and reflow + // old: $(window).scroll(checkInView); + // + // By the way, iOS (iPad, iPhone, ...) seems to not execute, or at least delays + // intervals while the user scrolls. Therefore the inview event might fire a bit late there + setInterval(checkInView, 250); +})(jQuery);
\ No newline at end of file diff --git a/core/js/jquery.inview.txt b/core/js/jquery.inview.txt new file mode 100644 index 00000000000..c53dbd1d97c --- /dev/null +++ b/core/js/jquery.inview.txt @@ -0,0 +1,15 @@ +jQuery.inview is licensed Attribution-Non-Commercial-Share Alike 2.0 but the +conditions has been waived by the author in the following tweet: + +https://twitter.com/#!/ChristopherBlum/status/148382899887013888 + +Saying: + +Thomas Tanghus @tanghus 18 Dec. 2011 + +@ChristopherBlum Hi. Is it OK if I use https://github.com/protonet/jquery.inview in ownCloud? Preferably under an AGPL license ;-) owncloud.org + + +Christopher Blum Christopher Blum @ChristopherBlum 18 Dec. 2011 + +@tanghus Feel free to! :) diff --git a/core/js/js.js b/core/js/js.js index e50b407bacf..f1ed6070c32 100644 --- a/core/js/js.js +++ b/core/js/js.js @@ -29,6 +29,16 @@ function t(app,text){ } t.cache={}; +/** +* Get the path to download a file +* @param file The filename +* @param dir The directory the file is in - e.g. $('#dir').val() +* @return string +*/ +function fileDownloadPath(dir, file) { + return OC.filePath('files', 'ajax', 'download.php')+encodeURIComponent('?files='+encodeURIComponent(file)+'&dir='+encodeURIComponent(dir)); +} + OC={ webroot:oc_webroot, appswebroots:oc_appswebroots, @@ -110,18 +120,19 @@ OC={ */ addScript:function(app,script,ready){ var path=OC.filePath(app,'js',script+'.js'); - if(OC.addScript.loaded.indexOf(path)==-1){ - OC.addScript.loaded.push(path); + if(!OC.addScript.loaded[path]){ if(ready){ - $.getScript(path,ready); + var deferred=$.getScript(path,ready); }else{ - $.getScript(path); + var deferred=$.getScript(path); } + OC.addScript.loaded[path]=deferred; }else{ if(ready){ ready(); } } + return OC.addScript.loaded[path]; }, /** * load a css file and load it diff --git a/core/js/share.js b/core/js/share.js index 3db69dc6901..8bfbdd36e19 100644 --- a/core/js/share.js +++ b/core/js/share.js @@ -1,7 +1,7 @@ OC.Share={ SHARE_TYPE_USER:0, SHARE_TYPE_GROUP:1, - SHARE_TYPE_PRIVATE_LINK:3, + SHARE_TYPE_LINK:3, SHARE_TYPE_EMAIL:4, PERMISSION_CREATE:4, PERMISSION_READ:1, @@ -118,7 +118,7 @@ OC.Share={ } }); }, - showDropDown:function(itemType, itemSource, appendTo, privateLink, possiblePermissions) { + showDropDown:function(itemType, itemSource, appendTo, link, possiblePermissions) { var data = OC.Share.loadItem(itemType, itemSource); var html = '<div id="dropdown" class="drop" data-item-type="'+itemType+'" data-item-source="'+itemSource+'">'; if (data.reshare) { @@ -130,14 +130,19 @@ OC.Share={ html += '<br />'; } if (possiblePermissions & OC.Share.PERMISSION_SHARE) { - html += '<input id="shareWith" type="text" placeholder="Share with" style="width:90%;"/>'; + html += '<input id="shareWith" type="text" placeholder="Share with" />'; html += '<ul id="shareWithList">'; html += '</ul>'; - if (privateLink) { - html += '<div id="privateLink">'; - html += '<input type="checkbox" name="privateLinkCheckbox" id="privateLinkCheckbox" value="1" /><label for="privateLinkCheckbox">Share with private link</label>'; + if (link) { + html += '<div id="link">'; + html += '<input type="checkbox" name="linkCheckbox" id="linkCheckbox" value="1" /><label for="linkCheckbox">Share with link</label>'; + // TODO Change to lock/unlock icon? + html += '<a href="#" id="showPassword" style="display:none;"><img class="svg" alt="Password protect" src="'+OC.imagePath('core', 'actions/triangle-n')+'"/></a>'; html += '<br />'; - html += '<input id="privateLinkText" style="display:none; width:90%;" readonly="readonly" />'; + html += '<input id="linkText" type="text" readonly="readonly" />'; + html += '<div id="linkPass">'; + html += '<input id="linkPassText" type="password" placeholder="Password" />'; + html += '</div>' html += '</div>'; } html += '</div>'; @@ -146,8 +151,8 @@ OC.Share={ OC.Share.itemShares = []; if (data.shares) { $.each(data.shares, function(index, share) { - if (share.share_type == OC.Share.SHARE_TYPE_PRIVATE_LINK) { - OC.Share.showPrivateLink(item, share.share_with); + if (share.share_type == OC.Share.SHARE_TYPE_LINK) { + OC.Share.showLink(itemSource, share.share_with); } else { OC.Share.addShareWith(share.share_type, share.share_with, share.permissions, possiblePermissions); } @@ -264,36 +269,28 @@ OC.Share={ $(html).appendTo('#shareWithList'); }, - showPrivateLink:function(item, token) { - $('#privateLinkCheckbox').attr('checked', true); - var link = parent.location.protocol+'//'+location.host+OC.linkTo('', 'public.php')+'?service=files&token='+token; - if (token.indexOf('&path=') == -1) { - link += '&file=' + encodeURIComponent(item).replace(/%2F/g, '/'); + showLink:function(itemSource, password) { + $('#linkCheckbox').attr('checked', true); + var filename = $('tr').filterAttr('data-id', String(itemSource)).data('file'); + if ($('#dir').val() == '/') { + var file = $('#dir').val() + filename; } else { - // Disable checkbox if inside a shared parent folder - $('#privateLinkCheckbox').attr('disabled', 'true'); + var file = $('#dir').val() + '/' + filename; + } + file = '/'+OC.currentUser+'/files'+file; + var link = parent.location.protocol+'//'+location.host+OC.linkTo('', 'public.php')+'?service=files&file='+file; + $('#linkText').val(link); + $('#linkText').show('blind'); + $('#showPassword').show(); + if (password.length > 0) { + $('#linkPass').show('blind'); + $('#linkPassText').attr('placeholder', 'Password protected'); } - $('#privateLinkText').val(link); - $('#privateLinkText').show('blind', function() { - $('#privateLinkText').after('<br id="emailBreak" />'); - $('#email').show(); - $('#emailButton').show(); - }); - }, - hidePrivateLink:function() { - $('#privateLinkText').hide('blind'); - $('#emailBreak').remove(); - $('#email').hide(); - $('#emailButton').hide(); }, - emailPrivateLink:function() { - var link = $('#privateLinkText').val(); - var file = link.substr(link.lastIndexOf('/') + 1).replace(/%20/g, ' '); - $.post(OC.filePath('files_sharing', 'ajax', 'email.php'), { toaddress: $('#email').val(), link: link, file: file } ); - $('#email').css('font-weight', 'bold'); - $('#email').animate({ fontWeight: 'normal' }, 2000, function() { - $(this).val(''); - }).val('Email sent'); + hideLink:function() { + $('#linkText').hide('blind'); + $('#showPassword').hide(); + $('#linkPass').hide(); }, dirname:function(path) { return path.replace(/\\/g,'/').replace(/\/[^\/]*$/, ''); @@ -308,21 +305,21 @@ $(document).ready(function() { var itemType = $(this).data('item-type'); var itemSource = $(this).data('item'); var appendTo = $(this).parent().parent(); - var privateLink = false; + var link = false; var possiblePermissions = $(this).data('possible-permissions'); - if ($(this).data('private-link') !== undefined && $(this).data('private-link') == true) { - privateLink = true; + if ($(this).data('link') !== undefined && $(this).data('link') == true) { + link = true; } if (OC.Share.droppedDown) { if (itemSource != $('#dropdown').data('item')) { OC.Share.hideDropDown(function () { - OC.Share.showDropDown(itemType, itemSource, appendTo, privateLink, possiblePermissions); + OC.Share.showDropDown(itemType, itemSource, appendTo, link, possiblePermissions); }); } else { OC.Share.hideDropDown(); } } else { - OC.Share.showDropDown(itemType, itemSource, appendTo, privateLink, possiblePermissions); + OC.Share.showDropDown(itemType, itemSource, appendTo, link, possiblePermissions); } } }); @@ -396,36 +393,40 @@ $(document).ready(function() { OC.Share.setPermissions($('#dropdown').data('item-type'), $('#dropdown').data('item-source'), $(li).data('share-type'), $(li).data('share-with'), permissions); }); - $('#privateLinkCheckbox').live('change', function() { + $('#linkCheckbox').live('change', function() { var itemType = $('#dropdown').data('item-type'); - var item = $('#dropdown').data('item'); + var itemSource = $('#dropdown').data('item-source'); if (this.checked) { - // Create a private link - OC.Share.share(itemType, item, OC.Share.SHARE_TYPE_PRIVATE_LINK, 0, 0, function(token) { - OC.Share.showPrivateLink(item, 'foo'); - // Change icon - OC.Share.icons[item] = OC.imagePath('core', 'actions/public'); + // Create a link + OC.Share.share(itemType, itemSource, OC.Share.SHARE_TYPE_LINK, '', OC.Share.PERMISSION_READ, function() { + OC.Share.showLink(itemSource); + // TODO Change icon }); } else { // Delete private link - OC.Share.unshare(item, 'public', function() { - OC.Share.hidePrivateLink(); - // Change icon - if (OC.Share.itemUsers || OC.Share.itemGroups) { - OC.Share.icons[item] = OC.imagePath('core', 'actions/shared'); - } else { - OC.Share.icons[item] = OC.imagePath('core', 'actions/share'); - } + OC.Share.unshare(itemType, itemSource, OC.Share.SHARE_TYPE_LINK, '', function() { + OC.Share.hideLink(); }); } }); - $('#privateLinkText').live('click', function() { + $('#linkText').live('click', function() { $(this).focus(); $(this).select(); }); - $('#emailPrivateLink').live('submit', function() { - OC.Share.emailPrivateLink(); + $('#showPassword').live('click', function() { + $('#linkPass').toggle('blind'); + }); + + $('#linkPassText').live('keyup', function(event) { + if (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, $(this).val(), OC.Share.PERMISSION_READ, function() { + $('#linkPassText').val(''); + $('#linkPassText').attr('placeholder', 'Password protected'); + }); + } }); }); |