diff --git a/css/style.css b/css/style.css index 1bce2a8f..c4061815 100644 --- a/css/style.css +++ b/css/style.css @@ -103,6 +103,13 @@ body { width : 16px; height : 16px; vertical-align : top; +} + +.loading-svg { + background : url(/img/spinner.svg); +} + +.loading-gif { background : url(/img/spinner.gif); } diff --git a/img/spinner.svg b/img/spinner.svg new file mode 100644 index 00000000..487ea530 --- /dev/null +++ b/img/spinner.svg @@ -0,0 +1,17 @@ + + + + + + + + + + + + + + + + + diff --git a/lib/client/dom.js b/lib/client/dom.js index 00cb694d..35a4f72e 100644 --- a/lib/client/dom.js +++ b/lib/client/dom.js @@ -14,34 +14,62 @@ var CloudCmd, Util, DOM, CloudFunc, Dialog; ImagesProto = function() { var ImagesProto = function() { - var Images = { - 'image-loading' : null, - 'image-error' : null - }; + var Classes = 'icon', + ID = 'js-image-', + Images = { + 'image-loading' : null, + 'image-error' : null + }; - function getImage(name) { - var id = 'js-image-' + name, - element = Images[id]; - - if (!element) - element = Images[id] = DOM.anyload({ - name : 'span', - className : 'icon ' + name, - id : id, - not_append : true - }); + function getImage(name, classes) { + var element = DOM.anyload({ + name : 'span', + className : classes, + id : ID + name, + not_append : true + }); return element; } - + /* Функция создаёт картинку загрузки */ this.loading = function() { - return getImage('loading'); + var classes, isSVG, + name = 'loading', + id = ID + name, + element = Images[id]; + + if (!element) { + classes = Classes + ' ' + name; + isSVG = DOM.isSVG(); + + if (isSVG) + classes += ' ' + name + '-svg'; + else + classes += ' ' + name + '-gif'; + + Images[id] = + element = getImage(name, classes); + } + + return element; }; /* Функция создаёт картинку ошибки загрузки */ this.error = function() { - return getImage('error'); + var classes, + name = 'error', + id = ID + name, + element = Images[id]; + + if (!element) { + classes = Classes + ' ' + name; + + Images[id] = + element = getImage(name, classes); + } + + return element; }; }, Images = new ImagesProto(); @@ -238,6 +266,23 @@ var CloudCmd, Util, DOM, CloudFunc, Dialog; return (pElement || document).getElementsByClassName(pClass); }; + /** + * check svg support + */ + this.isSVG = function() { + var rect, ret, + create = document.createElementNS, + SVG_URL = 'http://www.w3.org/2000/svg'; + + if (create) + create = create.bind(document); + + rect = create(SVG_URL,'svg').createSVGRect; + ret = !!rect; + + return ret; + }; + /** * add class=hidden to element *