Tizen 2.0 Release
[samples/web/FileManager.git] / js / app.clipboard.js
1 /*jslint devel: true*/
2 /*global $*/
3
4 /**
5  * @class Config
6  */
7 function Clipboard() {
8         'use strict';
9         this.mode = this.INACTIVE_MODE;
10 }
11
12 (function () { // strict mode wrapper
13         'use strict';
14         Clipboard.prototype = {
15                 /**
16                  * Clipboard mode for copying
17                  */
18                 COPY_MODE_ID: 0,
19
20                 /**
21                  * Clipboard mode for moving
22                  */
23                 MOVE_MODE_ID: 1,
24
25                 /**
26                  * Clipbboard inactive mode
27                  */
28                 INACTIVE_MODE: -1,
29
30                 /**
31                  * Clipboard data
32                  */
33                 data: [],
34
35                 /**
36                  * Clipboard mode: [copy | move | inactive]
37                  */
38                 mode: undefined,
39
40                 /**
41                  * Returns all paths in clipboard
42                  * @returns {array}
43                  */
44                 get: function Clipboard_get() {
45                         return this.data;
46                 },
47
48                 /**
49                  * Add new path to clipboard
50                  * @param {array} paths aray of full paths
51                  * @returns {number} current length of clipboard objects
52                  */
53                 add: function Clipboard_add(paths) {
54                         var len = paths.length,
55                                 i;
56
57                         // clear clipboard
58                         this.clear();
59                         for (i = 0; i < len; i += 1) {
60                                 if (this.has(paths[i]) === false) {
61                                         this.data.push(paths[i]);
62                                 }
63                         }
64
65                         return this.data.length;
66                 },
67
68                 /**
69                  * Checks if specified path is already in clipboard
70                  * @param {string} path full path
71                  * @returns {boolean}
72                  */
73                 has: function Clipboard_has(path) {
74                         return $.inArray(path, this.data) === -1 ? false : true;
75                 },
76
77                 /**
78                  * Clears all clipboard data and resets clipboard mode
79                  */
80                 clear: function Clipboard_clear() {
81                         this.data = [];
82                         this.mode = this.INACTIVE_MODE;
83                 },
84
85                 /**
86                  * Sets clipboard mode
87                  * @param {number} mode
88                  * @returns {boolean}
89                  */
90                 setMode: function Clipboard_setMode(mode) {
91                         if ($.inArray(mode, [this.MOVE_MODE_ID, this.COPY_MODE_ID]) === false) {
92                                 console.error('Incorrect clipboard mode');
93                                 return false;
94                         }
95                         this.mode = mode;
96                         return true;
97                 },
98
99                 /**
100                  * @returns {number} mode Clipboard mode
101                  */
102                 getMode: function Clipboard_getMode() {
103                         return this.mode;
104                 },
105
106                 /**
107                  * @returns {boolean}
108                  */
109                 isEmpty: function Clipboard_isEmpty() {
110                         return this.data.length === 0;
111                 }
112         };
113 }());