summaryrefslogtreecommitdiffstats
path: root/core/js
diff options
context:
space:
mode:
Diffstat (limited to 'core/js')
-rw-r--r--core/js/jquery.ocdialog.js2
-rw-r--r--core/js/js.js105
-rw-r--r--core/js/mimetype.js15
-rw-r--r--core/js/sharedialogshareelistview.js2
-rw-r--r--core/js/sharedialogview.js2
-rw-r--r--core/js/shareitemmodel.js2
-rw-r--r--core/js/tests/specs/coreSpec.js39
7 files changed, 148 insertions, 19 deletions
diff --git a/core/js/jquery.ocdialog.js b/core/js/jquery.ocdialog.js
index 15b58f9e086..ea034f0aff7 100644
--- a/core/js/jquery.ocdialog.js
+++ b/core/js/jquery.ocdialog.js
@@ -145,7 +145,7 @@
break;
case 'closeButton':
if(value) {
- var $closeButton = $('<a class="oc-dialog-close"></a>');
+ var $closeButton = $('<a class="oc-dialog-close svg"></a>');
this.$dialog.prepend($closeButton);
$closeButton.on('click', function() {
self.close();
diff --git a/core/js/js.js b/core/js/js.js
index 07ed396bec9..7f98668dcb2 100644
--- a/core/js/js.js
+++ b/core/js/js.js
@@ -327,8 +327,8 @@ var OC={
* @return {string}
*/
imagePath:function(app,file){
- if(file.indexOf('.')==-1){//if no extension is given, use svg
- file+='.svg';
+ if(file.indexOf('.')==-1){//if no extension is given, use png or svg depending on browser support
+ file+=(OC.Util.hasSVGSupport())?'.svg':'.png';
}
return OC.filePath(app,'img',file);
},
@@ -592,7 +592,7 @@ var OC={
var arrowclass = settings.hasClass('topright') ? 'up' : 'left';
var jqxhr = $.get(OC.filePath(props.appid, '', props.scriptName), function(data) {
popup.html(data).ready(function() {
- popup.prepend('<span class="arrow '+arrowclass+'"></span><h2>'+t('core', 'Settings')+'</h2><a class="close"></a>').show();
+ popup.prepend('<span class="arrow '+arrowclass+'"></span><h2>'+t('core', 'Settings')+'</h2><a class="close svg"></a>').show();
popup.find('.close').bind('click', function() {
popup.remove();
});
@@ -613,6 +613,9 @@ var OC={
throw e;
});
}
+ if(!OC.Util.hasSVGSupport()) {
+ OC.Util.replaceSVG();
+ }
}).show();
}, 'html');
}
@@ -1355,6 +1358,49 @@ if(typeof localStorage !=='undefined' && localStorage !== null){
}
/**
+ * check if the browser support svg images
+ * @return {boolean}
+ */
+function SVGSupport() {
+ return SVGSupport.checkMimeType.correct && !!document.createElementNS && !!document.createElementNS('http://www.w3.org/2000/svg', "svg").createSVGRect;
+}
+SVGSupport.checkMimeType=function(){
+ $.ajax({
+ url: OC.imagePath('core','breadcrumb.svg'),
+ success:function(data,text,xhr){
+ var headerParts=xhr.getAllResponseHeaders().split("\n");
+ var headers={};
+ $.each(headerParts,function(i,text){
+ if(text){
+ var parts=text.split(':',2);
+ if(parts.length===2){
+ var value=parts[1].trim();
+ if(value[0]==='"'){
+ value=value.substr(1,value.length-2);
+ }
+ headers[parts[0].toLowerCase()]=value;
+ }
+ }
+ });
+ if(headers["content-type"]!=='image/svg+xml'){
+ OC.Util.replaceSVG();
+ SVGSupport.checkMimeType.correct=false;
+ }
+ }
+ });
+};
+SVGSupport.checkMimeType.correct=true;
+
+/**
+ * Replace all svg images with png for browser compatibility
+ * @param $el
+ * @deprecated use OC.Util.replaceSVG instead
+ */
+function replaceSVG($el){
+ return OC.Util.replaceSVG($el);
+}
+
+/**
* prototypical inheritance functions
* @todo Write documentation
* usage:
@@ -1471,6 +1517,12 @@ function initCore() {
initSessionHeartBeat();
}
+ if(!OC.Util.hasSVGSupport()){ //replace all svg images with png images for browser that don't support svg
+ OC.Util.replaceSVG();
+ }else{
+ SVGSupport.checkMimeType();
+ }
+
OC.registerMenu($('#expand'), $('#expanddiv'));
// toggle for menus
@@ -1739,21 +1791,24 @@ OC.Util = {
},
/**
* Returns whether the browser supports SVG
- * @deprecated SVG is always supported (since 9.0)
* @return {boolean} true if the browser supports SVG, false otherwise
*/
- hasSVGSupport: function(){
- return true
- },
+ // TODO: replace with original function
+ hasSVGSupport: SVGSupport,
/**
* If SVG is not supported, replaces the given icon's extension
* from ".svg" to ".png".
* If SVG is supported, return the image path as is.
* @param {string} file image path with svg extension
- * @deprecated SVG is always supported (since 9.0)
* @return {string} fixed image path with png extension if SVG is not supported
*/
replaceSVGIcon: function(file) {
+ if (file && !OC.Util.hasSVGSupport()) {
+ var i = file.lastIndexOf('.svg');
+ if (i >= 0) {
+ file = file.substr(0, i) + '.png' + file.substr(i+4);
+ }
+ }
return file;
},
/**
@@ -1761,9 +1816,39 @@ OC.Util = {
* with PNG images.
*
* @param $el root element from which to search, defaults to $('body')
- * @deprecated SVG is always supported (since 9.0)
*/
- replaceSVG: function($el) {},
+ replaceSVG: function($el) {
+ if (!$el) {
+ $el = $('body');
+ }
+ $el.find('img.svg').each(function(index,element){
+ element=$(element);
+ var src=element.attr('src');
+ element.attr('src',src.substr(0, src.length-3) + 'png');
+ });
+ $el.find('.svg').each(function(index,element){
+ element = $(element);
+ var background = element.css('background-image');
+ if (background){
+ var i = background.lastIndexOf('.svg');
+ if (i >= 0){
+ background = background.substr(0,i) + '.png' + background.substr(i + 4);
+ element.css('background-image', background);
+ }
+ }
+ element.find('*').each(function(index, element) {
+ element = $(element);
+ var background = element.css('background-image');
+ if (background) {
+ var i = background.lastIndexOf('.svg');
+ if(i >= 0){
+ background = background.substr(0,i) + '.png' + background.substr(i + 4);
+ element.css('background-image', background);
+ }
+ }
+ });
+ });
+ },
/**
* Fix image scaling for IE8, since background-size is not supported.
diff --git a/core/js/mimetype.js b/core/js/mimetype.js
index 0d30da26c26..3cc33ce2830 100644
--- a/core/js/mimetype.js
+++ b/core/js/mimetype.js
@@ -29,7 +29,7 @@ OC.MimeType = {
* Cache that maps mimeTypes to icon urls
*/
_mimeTypeIcons: {},
-
+
/**
* Return the file icon we want to use for the given mimeType.
* The file needs to be present in the supplied file list
@@ -60,7 +60,7 @@ OC.MimeType = {
return null;
},
-
+
/**
* Return the url to icon of the given mimeType
*
@@ -91,14 +91,19 @@ OC.MimeType = {
path += icon;
}
}
-
+
// If we do not yet have an icon fall back to the default
if (gotIcon === null) {
path = OC.webroot + '/core/img/filetypes/';
path += OC.MimeType._getFile(mimeType, OC.MimeTypeList.files);
}
- path += '.svg';
+ // Use svg if we can
+ if(OC.Util.hasSVGSupport()){
+ path += '.svg';
+ } else {
+ path += '.png';
+ }
// Cache the result
OC.MimeType._mimeTypeIcons[mimeType] = path;
@@ -106,3 +111,5 @@ OC.MimeType = {
}
};
+
+
diff --git a/core/js/sharedialogshareelistview.js b/core/js/sharedialogshareelistview.js
index 85dee978987..83fde154615 100644
--- a/core/js/sharedialogshareelistview.js
+++ b/core/js/sharedialogshareelistview.js
@@ -38,7 +38,7 @@
'<span class="shareOption">' +
'<input id="canEdit-{{cid}}-{{shareWith}}" type="checkbox" name="edit" class="permissions checkbox" {{#if hasEditPermission}}checked="checked"{{/if}} />' +
'<label for="canEdit-{{cid}}-{{shareWith}}">{{canEditLabel}}</label>' +
- '<a href="#" class="showCruds"><img alt="{{crudsLabel}}" src="{{triangleSImage}}"/></a>' +
+ '<a href="#" class="showCruds"><img class="svg" alt="{{crudsLabel}}" src="{{triangleSImage}}"/></a>' +
'</span>' +
'{{/if}}' +
'<div class="cruds hidden">' +
diff --git a/core/js/sharedialogview.js b/core/js/sharedialogview.js
index c17da94bab3..a4bfde1777b 100644
--- a/core/js/sharedialogview.js
+++ b/core/js/sharedialogview.js
@@ -30,7 +30,7 @@
'<div class="loading hidden" style="height: 50px"></div>';
var TEMPLATE_REMOTE_SHARE_INFO =
- '<a target="_blank" class="icon-info shareWithRemoteInfo hasTooltip" href="{{docLink}}" ' +
+ '<a target="_blank" class="icon-info svg shareWithRemoteInfo hasTooltip" href="{{docLink}}" ' +
'title="{{tooltip}}"></a>';
/**
diff --git a/core/js/shareitemmodel.js b/core/js/shareitemmodel.js
index 9f75ac42f21..3ced66a1a78 100644
--- a/core/js/shareitemmodel.js
+++ b/core/js/shareitemmodel.js
@@ -187,7 +187,7 @@
}).fail(function(xhr) {
var msg = t('core', 'Error');
var result = xhr.responseJSON;
- if (result && result.ocs && result.ocs.meta) {
+ if (result.ocs && result.ocs.meta) {
msg = result.ocs.meta.message;
}
diff --git a/core/js/tests/specs/coreSpec.js b/core/js/tests/specs/coreSpec.js
index 1ffe7b38a40..3d19a38c416 100644
--- a/core/js/tests/specs/coreSpec.js
+++ b/core/js/tests/specs/coreSpec.js
@@ -231,12 +231,22 @@ describe('Core base tests', function() {
});
describe('Images', function() {
it('Generates image path with given extension', function() {
+ var svgSupportStub = sinon.stub(OC.Util, 'hasSVGSupport', function() { return true; });
expect(OC.imagePath('core', 'somefile.jpg')).toEqual(OC.webroot + '/core/img/somefile.jpg');
expect(OC.imagePath(TESTAPP, 'somefile.jpg')).toEqual(TESTAPP_ROOT + '/img/somefile.jpg');
+ svgSupportStub.restore();
});
- it('Generates image path with svg extension', function() {
+ it('Generates image path with svg extension when svg support exists', function() {
+ var svgSupportStub = sinon.stub(OC.Util, 'hasSVGSupport', function() { return true; });
expect(OC.imagePath('core', 'somefile')).toEqual(OC.webroot + '/core/img/somefile.svg');
expect(OC.imagePath(TESTAPP, 'somefile')).toEqual(TESTAPP_ROOT + '/img/somefile.svg');
+ svgSupportStub.restore();
+ });
+ it('Generates image path with png ext when svg support is not available', function() {
+ var svgSupportStub = sinon.stub(OC.Util, 'hasSVGSupport', function() { return false; });
+ expect(OC.imagePath('core', 'somefile')).toEqual(OC.webroot + '/core/img/somefile.png');
+ expect(OC.imagePath(TESTAPP, 'somefile')).toEqual(TESTAPP_ROOT + '/img/somefile.png');
+ svgSupportStub.restore();
});
});
});
@@ -494,6 +504,32 @@ describe('Core base tests', function() {
expect($navigation.is(':visible')).toEqual(false);
});
});
+ describe('SVG extension replacement', function() {
+ var svgSupportStub;
+
+ beforeEach(function() {
+ svgSupportStub = sinon.stub(OC.Util, 'hasSVGSupport');
+ });
+ afterEach(function() {
+ svgSupportStub.restore();
+ });
+ it('does not replace svg extension with png when SVG is supported', function() {
+ svgSupportStub.returns(true);
+ expect(
+ OC.Util.replaceSVGIcon('/path/to/myicon.svg?someargs=1')
+ ).toEqual(
+ '/path/to/myicon.svg?someargs=1'
+ );
+ });
+ it('replaces svg extension with png when SVG not supported', function() {
+ svgSupportStub.returns(false);
+ expect(
+ OC.Util.replaceSVGIcon('/path/to/myicon.svg?someargs=1')
+ ).toEqual(
+ '/path/to/myicon.png?someargs=1'
+ );
+ });
+ });
describe('Util', function() {
describe('humanFileSize', function() {
it('renders file sizes with the correct unit', function() {
@@ -981,3 +1017,4 @@ describe('Core base tests', function() {
});
});
});
+