Updated application sources
[apps/web/sample/FileManager.git] / project / js / app.clipboard.js
index cee9925..aa5d175 100644 (file)
@@ -1,3 +1,19 @@
+/*
+ *      Copyright 2013  Samsung Electronics Co., Ltd
+ *
+ *      Licensed under the Flora License, Version 1.1 (the "License");
+ *      you may not use this file except in compliance with the License.
+ *      You may obtain a copy of the License at
+ *
+ *              http://floralicense.org/license/
+ *
+ *      Unless required by applicable law or agreed to in writing, software
+ *      distributed under the License is distributed on an "AS IS" BASIS,
+ *      WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *      See the License for the specific language governing permissions and
+ *      limitations under the License.
+ */
+
 /*jslint devel: true*/
 /*global $*/
 
  * @class Config
  */
 function Clipboard() {
-       'use strict';
-       this.mode = this.INACTIVE_MODE;
+    'use strict';
+    this.mode = this.INACTIVE_MODE;
 }
 
 (function () { // strict mode wrapper
-       'use strict';
-       Clipboard.prototype = {
-               /**
-                * Clipboard mode for copying
-                */
-               COPY_MODE_ID: 0,
-
-               /**
-                * Clipboard mode for moving
-                */
-               MOVE_MODE_ID: 1,
-
-               /**
-                * Clipbboard inactive mode
-                */
-               INACTIVE_MODE: -1,
-
-               /**
-                * Clipboard data
-                */
-               data: [],
-
-               /**
-                * Clipboard mode: [copy | move | inactive]
-                */
-               mode: undefined,
-
-               /**
-                * Returns all paths in clipboard
-                * @returns {array}
-                */
-               get: function Clipboard_get() {
-                       return this.data;
-               },
-
-               /**
-                * Add new path to clipboard
-                * @param {array} paths array of full paths
-                * @returns {number} current length of clipboard objects
-                */
-               add: function Clipboard_add(paths) {
-                       var len = paths.length,
-                               i;
-
-                       // clear clipboard
-                       this.clear();
-                       for (i = 0; i < len; i += 1) {
-                               if (this.has(paths[i]) === false) {
-                                       this.data.push(paths[i]);
-                               }
-                       }
-
-                       return this.data.length;
-               },
-
-               /**
-                * Remove specified path is already in clipboard
-                * @param {string} path full path
-                * @returns {number} current length of clipboard objects
-                */
-               remove: function Clipboard_remove(path) {
-                       var index = $.inArray(path, this.data);
-                       var length;
-                       if (index >= 0) {
-                               this.data.splice(index, 1);
-                               length = this.data.length;
-                               if (length === 0) {
-                                       this.mode = this.INACTIVE_MODE;
-                               }
-                       }
-                       return length;
-               },
-
-               /**
-                * Remove specified path and all children paths if already in clipboard
-                * @param {string} path full path
-                * @returns {number} current length of clipboard objects
-                */
-               removeRecursively: function Clipboard_removeRecursively(path) {
-                       var childPattern = new RegExp(path),
-                               index = this.data.length;
-                       while (index--) {
-                               if(childPattern.test(this.data[index])) {
-                                       this.data.splice(index, 1);
-                               }
-                       }
-                       return this.data.length;
-               },
-
-               /**
-                * Checks if specified path is already in clipboard
-                * @param {string} path full path
-                * @returns {boolean}
-                */
-               has: function Clipboard_has(path) {
-                       return $.inArray(path, this.data) === -1 ? false : true;
-               },
-
-               /**
-                * Clears all clipboard data and resets clipboard mode
-                */
-               clear: function Clipboard_clear() {
-                       this.data = [];
-                       this.mode = this.INACTIVE_MODE;
-               },
-
-               /**
-                * Sets clipboard mode
-                * @param {number} mode
-                * @returns {boolean}
-                */
-               setMode: function Clipboard_setMode(mode) {
-                       if ($.inArray(mode, [this.MOVE_MODE_ID, this.COPY_MODE_ID]) === false) {
-                               console.error('Incorrect clipboard mode');
-                               return false;
-                       }
-                       this.mode = mode;
-                       return true;
-               },
-
-               /**
-                * @returns {number} mode Clipboard mode
-                */
-               getMode: function Clipboard_getMode() {
-                       return this.mode;
-               },
-
-               /**
-                * @returns {boolean}
-                */
-               isEmpty: function Clipboard_isEmpty() {
-                       return this.data.length === 0;
-               }
-       };
+    'use strict';
+    Clipboard.prototype = {
+        /**
+         * Clipboard mode for copying
+         */
+        COPY_MODE_ID: 0,
+
+        /**
+         * Clipboard mode for moving
+         */
+        MOVE_MODE_ID: 1,
+
+        /**
+         * Clipbboard inactive mode
+         */
+        INACTIVE_MODE: -1,
+
+        /**
+         * Clipboard data
+         */
+        data: [],
+
+        /**
+         * Clipboard mode: [copy | move | inactive]
+         */
+        mode: undefined,
+
+        /**
+         * Returns all paths in clipboard
+         * @returns {array}
+         */
+        get: function Clipboard_get() {
+            return this.data;
+        },
+
+        /**
+         * Add new path to clipboard
+         * @param {array} paths array of full paths
+         * @returns {number} current length of clipboard objects
+         */
+        add: function Clipboard_add(paths) {
+            var len = paths.length,
+                i;
+
+            // clear clipboard
+            this.clear();
+            for (i = 0; i < len; i += 1) {
+                if (this.has(paths[i]) === false) {
+                    this.data.push(paths[i]);
+                }
+            }
+
+            return this.data.length;
+        },
+
+        /**
+         * Remove specified path is already in clipboard
+         * @param {string} path full path
+         * @returns {number} current length of clipboard objects
+         */
+        remove: function Clipboard_remove(path) {
+            var index = $.inArray(path, this.data),
+                length;
+            if (index >= 0) {
+                this.data.splice(index, 1);
+                length = this.data.length;
+                if (length === 0) {
+                    this.mode = this.INACTIVE_MODE;
+                }
+            }
+            return length;
+        },
+
+        /**
+         * Remove specified path and all children paths if already in clipboard
+         * @param {string} path full path
+         * @returns {number} current length of clipboard objects
+         */
+        removeRecursively: function Clipboard_removeRecursively(path) {
+            var escapeRegExp = function (str) {
+                    return str
+                        .replace(/[\-\[\]\/\{\}\(\)\*\+\?\.\\\^\$\|]/g, "\\$&");
+                },
+                childPattern = new RegExp(escapeRegExp(path)),
+                index = this.data.length - 1;
+            while (index >= 0) {
+                if (childPattern.test(this.data[index])) {
+                    this.data.splice(index, 1);
+                }
+                index -= 1;
+            }
+            return this.data.length;
+        },
+
+        /**
+         * Checks if specified path is already in clipboard
+         * @param {string} path full path
+         * @returns {boolean}
+         */
+        has: function Clipboard_has(path) {
+            return $.inArray(path, this.data) === -1 ? false : true;
+        },
+
+        /**
+         * Clears all clipboard data and resets clipboard mode
+         */
+        clear: function Clipboard_clear() {
+            this.data = [];
+            this.mode = this.INACTIVE_MODE;
+        },
+
+        /**
+         * Sets clipboard mode
+         * @param {number} mode
+         * @returns {boolean}
+         */
+        setMode: function Clipboard_setMode(mode) {
+            if (
+                $.inArray(
+                    mode,
+                    [this.MOVE_MODE_ID, this.COPY_MODE_ID]
+                ) === false
+            ) {
+                console.error('Incorrect clipboard mode');
+                return false;
+            }
+            this.mode = mode;
+            return true;
+        },
+
+        /**
+         * @returns {number} mode Clipboard mode
+         */
+        getMode: function Clipboard_getMode() {
+            return this.mode;
+        },
+
+        /**
+         * @returns {boolean}
+         */
+        isEmpty: function Clipboard_isEmpty() {
+            return this.data.length === 0;
+        }
+    };
 }());