2 * Copyright 2013 Samsung Electronics Co., Ltd
4 * Licensed under the Flora License, Version 1.1 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://floralicense.org/license/
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
17 /*jslint devel: true*/
27 (function () { // strict mode wrapper
71 '.icalendar': 'text.png',
82 * Capitalise the first letter
84 * @param {string} text
87 UCFirst: function Helpers_UCFirst(text) {
88 return text.charAt(0).toUpperCase() + text.slice(1);
92 * @param {string} fileName
93 * @returns {string} file name without extension
95 getFileName: function Helpers_getFileName(fileName) {
96 var fileNameLen = fileName.lastIndexOf('.');
97 if (fileNameLen !== -1) {
98 fileName = fileName.slice(0, fileNameLen);
104 * @param {string} fileName
105 * @returns {string} extension for specified file name
107 getFileExtension: function Helpers_getFileExtension(fileName) {
108 var splittedFileName = fileName.split('.'),
111 if (splittedFileName.length > 1) {
112 ext = '.' + splittedFileName.pop();
118 * Return icon filename for the given extension.
119 * For example, for '.mp3' returns 'music.png'
121 * @param {string} ext
124 resolveFileIcon: function Helpers_resolveFileIcon(ext) {
125 ext = ext.toLowerCase();
126 return this.extensions[ext] || 'etc.png';
130 * Returns thumbnail URI for specified file
131 * @param {string} fileName
135 getThumbnailURI: function Helpers_getThumbnailURI(fileName, node) {
136 var ext = this.getFileExtension(fileName);
138 if (!node.thumbnailURIs) {
139 return 'images/' + this.resolveFileIcon(ext);
143 node.thumbnailURIs[0] &&
144 $.inArray(ext, ['.mp4', '.jpg', '.png', '.gif'])
146 return node.thumbnailURIs[0];
149 return 'images/etc.png';
153 * File name automatic number increase for copy files
155 getCopyFileName: function Helpers_getCopyFileName(
159 var i = 1, copyFileName = sourceName,
160 filesNames = filesList.map(function (element) {
163 index = filesNames.indexOf(copyFileName),
164 ext = this.getFileExtension(sourceName);
166 while (index !== -1) {
167 if (filesList[index].isDirectory) {
168 copyFileName = sourceName + '(' + i + ')';
170 copyFileName = this.getFileName(
172 ) + '(' + i + ')' + ext;
175 index = filesNames.indexOf(copyFileName);
182 * Fixes invalid URI returned by API's File::toURI() method.
183 * See issue https://bugs.tizendev.org/jira/browse/N_SE-54639
185 fixURI: function Helpers_fixURI(invaliduri) {
186 var scheme, address, k;
187 invaliduri = invaliduri.split('://');
188 scheme = invaliduri[0];
190 address = invaliduri.join('://').split('/');
191 for (k = address.length - 1; k >= 0; k -= 1) {
192 address[k] = encodeURIComponent(address[k]);
194 return scheme + '://' + address.join('/');