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*/
23 function Clipboard() {
25 this.mode = this.INACTIVE_MODE;
28 (function () { // strict mode wrapper
30 Clipboard.prototype = {
32 * Clipboard mode for copying
37 * Clipboard mode for moving
42 * Clipbboard inactive mode
52 * Clipboard mode: [copy | move | inactive]
57 * Returns all paths in clipboard
60 get: function Clipboard_get() {
65 * Add new path to clipboard
66 * @param {array} paths array of full paths
67 * @returns {number} current length of clipboard objects
69 add: function Clipboard_add(paths) {
70 var len = paths.length,
75 for (i = 0; i < len; i += 1) {
76 if (this.has(paths[i]) === false) {
77 this.data.push(paths[i]);
81 return this.data.length;
85 * Remove specified path is already in clipboard
86 * @param {string} path full path
87 * @returns {number} current length of clipboard objects
89 remove: function Clipboard_remove(path) {
90 var index = $.inArray(path, this.data),
93 this.data.splice(index, 1);
94 length = this.data.length;
96 this.mode = this.INACTIVE_MODE;
103 * Remove specified path and all children paths if already in clipboard
104 * @param {string} path full path
105 * @returns {number} current length of clipboard objects
107 removeRecursively: function Clipboard_removeRecursively(path) {
108 var escapeRegExp = function (str) {
110 .replace(/[\-\[\]\/\{\}\(\)\*\+\?\.\\\^\$\|]/g, "\\$&");
112 childPattern = new RegExp(escapeRegExp(path)),
113 index = this.data.length - 1;
115 if (childPattern.test(this.data[index])) {
116 this.data.splice(index, 1);
120 return this.data.length;
124 * Checks if specified path is already in clipboard
125 * @param {string} path full path
128 has: function Clipboard_has(path) {
129 return $.inArray(path, this.data) === -1 ? false : true;
133 * Clears all clipboard data and resets clipboard mode
135 clear: function Clipboard_clear() {
137 this.mode = this.INACTIVE_MODE;
141 * Sets clipboard mode
142 * @param {number} mode
145 setMode: function Clipboard_setMode(mode) {
149 [this.MOVE_MODE_ID, this.COPY_MODE_ID]
152 console.error('Incorrect clipboard mode');
160 * @returns {number} mode Clipboard mode
162 getMode: function Clipboard_getMode() {
169 isEmpty: function Clipboard_isEmpty() {
170 return this.data.length === 0;