mortar 0.7.0 → 0.7.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,169 @@
1
+ (function ($, window, document) {
2
+ "use strict";
3
+
4
+ var allInstances = [];
5
+
6
+ var pluginName = "mortarTableExpandableCell",
7
+ defaults = {
8
+ previewSelector : '.mortar-table-expandable-cell-preview',
9
+ contentSelector : '.mortar-table-expandable-cell-content',
10
+ expandingSelector : '.mortar-table-expandable-cell-container',
11
+ expandedContainerStyle : {
12
+ 'width' : 250,
13
+ 'height' : 180
14
+ },
15
+ expandedPreviewStyle : {
16
+ 'opacity' : '0'
17
+ },
18
+ expandedContentStyle : {
19
+ 'opacity' : '1'
20
+ },
21
+ expandInward : true,
22
+ globalBlocking : true
23
+ };
24
+
25
+ function MortarTableExpandableCell(element, options) {
26
+ this.element = element;
27
+ this.options = $.extend({}, defaults, options);
28
+
29
+
30
+ var item = $(this.element).find(this.options.expandingSelector)
31
+ , preview = $(item).find(this.options.previewSelector)
32
+ , content = $(item).find(this.options.contentSelector)
33
+ , _this = this;
34
+
35
+
36
+ item.stylestack('enable');
37
+ preview.stylestack('enable');
38
+ content.stylestack('enable');
39
+
40
+
41
+ $(this.element).click( function(event) {
42
+ _this.open();
43
+ });
44
+ $(this.element).find(this.options.contentSelector).click( function(event) {
45
+ event.stopPropagation();
46
+ });
47
+
48
+ allInstances.push(this);
49
+ }
50
+
51
+
52
+ MortarTableExpandableCell.prototype.close = function () {
53
+ if (!$(this.element).find(this.options.expandingSelector).hasClass('active')) {
54
+ return;
55
+ }
56
+
57
+ $(this.element).find(this.options.expandingSelector).stylestack('pop', function () {
58
+ $(this).removeClass('active');
59
+ });
60
+ $(this.element).find(this.options.previewSelector).stylestack('pop');
61
+ $(this.element).find(this.options.contentSelector).stylestack('pop');
62
+
63
+ $(this.element).trigger('MortarTableExpandableCell.Closed');
64
+ };
65
+
66
+ MortarTableExpandableCell.prototype.open = function() {
67
+ var item = $(this.element).find(this.options.expandingSelector)
68
+ , preview = $(item).find(this.options.previewSelector)
69
+ , content = $(item).find(this.options.contentSelector)
70
+ , containerStyles = _getStyleBasedOnPosition.call(this)
71
+ , _this = this;
72
+
73
+ if(!item.hasClass('active')) {
74
+ item.css(containerStyles['containerStyle']);
75
+
76
+ // This is a hack to let the page reflow
77
+ setTimeout(function() {
78
+ item.addClass('active');
79
+ content.css('display', 'block');
80
+
81
+ item.transition(containerStyles['containerAnimatedStyle'], function() {
82
+ _this.opening = false;
83
+ });
84
+ preview.transition(_this.options.expandedPreviewStyle);
85
+ content.transition(_this.options.expandedContentStyle);
86
+
87
+ item.css({ 'z-index' : '1000' });
88
+ }, 0);
89
+ }
90
+ }
91
+
92
+ var _getStyleBasedOnPosition = function() {
93
+
94
+ var containerStyle = {}
95
+ , containerAnimatedStyle = {}
96
+ , container = $(this.element).find(this.options.expandingSelector)
97
+ , width = container.outerWidth()
98
+ , height = container.outerHeight();
99
+
100
+ containerAnimatedStyle['top'] = '50%';
101
+ containerAnimatedStyle['left'] = '50%';
102
+ containerAnimatedStyle['margin-left'] = -(this.options.expandedContainerStyle.width / 2);
103
+ containerAnimatedStyle['margin-top'] = -(this.options.expandedContainerStyle.height / 2);
104
+
105
+ if( this.options.expandInward ) {
106
+ var firstInRow = $(this.element).is(':first-child')
107
+ , lastInRow = $(this.element).is(':last-child')
108
+ , firstRow = $(this.element).parent().is(':first-child')
109
+ , lastRow = $(this.element).parent().is(':last-child');
110
+
111
+
112
+ if( firstInRow && !lastInRow ) {
113
+ containerAnimatedStyle['left'] = 0;
114
+ containerAnimatedStyle['margin-left'] = 0;
115
+ console.log('First in Row');
116
+ }
117
+ if( lastInRow && !firstInRow ) {
118
+ containerStyle['left'] = 'auto';
119
+ containerStyle['right'] = 0;
120
+ containerAnimatedStyle['left'] = undefined;
121
+ containerAnimatedStyle['margin-left'] = 0;
122
+ console.log('Last in Row');
123
+ }
124
+ if( firstRow ) {
125
+ //containerAnimatedStyle['top'] = 0;
126
+ //containerAnimatedStyle['margin-top'] = 0;
127
+ console.log('First Row');
128
+ }
129
+ if( lastRow && !firstRow ) {
130
+ //containerStyle['top'] = 'auto';
131
+ //containerAnimatedStyle['top'] = undefined;
132
+ //containerAnimatedStyle['bottom'] = 0;
133
+ //containerAnimatedStyle['margin-bottom'] = 0;
134
+ console.log('Last Row');
135
+ }
136
+ }
137
+
138
+
139
+ containerAnimatedStyle = $.extend({}, containerAnimatedStyle, this.options.expandedContainerStyle);
140
+
141
+ return { 'containerStyle' : containerStyle, 'containerAnimatedStyle' : containerAnimatedStyle };
142
+ };
143
+
144
+ var _closeAllInstances = function() {
145
+ console.log("CLOSE ALL INSTANCES");
146
+ for(var i = 0; i < allInstances.length; i++) {
147
+ allInstances[i].close();
148
+ }
149
+ };
150
+
151
+ $('body').click( _closeAllInstances );
152
+ $(document).keyup(function(e) {
153
+ if (e.keyCode == 27) { _closeAllInstances() } // esc
154
+ });
155
+
156
+ $.fn[pluginName] = function (option) {
157
+ return this.each(function () {
158
+ var $this = $(this)
159
+ , data = $this.data('plugin_' + pluginName)
160
+ , options = typeof option == 'object' && option
161
+ , action = typeof option == 'string' && option
162
+ if (!data) $.data(this, 'plugin_' + pluginName, (data = new MortarTableExpandableCell(this, options)));
163
+ if (action) data[action]();
164
+
165
+ });
166
+ };
167
+
168
+
169
+ })(jQuery, window, document);
@@ -0,0 +1,358 @@
1
+ /*!
2
+ * zeroclipboard
3
+ * The Zero Clipboard library provides an easy way to copy text to the clipboard using an invisible Adobe Flash movie, and a JavaScript interface.
4
+ * Copyright 2012 Jon Rohan, James M. Greene, .
5
+ * Released under the MIT license
6
+ * http://jonrohan.github.com/ZeroClipboard/
7
+ * v1.1.7
8
+ */(function() {
9
+ "use strict";
10
+ var _getStyle = function(el, prop) {
11
+ var y = el.style[prop];
12
+ if (el.currentStyle) y = el.currentStyle[prop]; else if (window.getComputedStyle) y = document.defaultView.getComputedStyle(el, null).getPropertyValue(prop);
13
+ if (y == "auto" && prop == "cursor") {
14
+ var possiblePointers = [ "a" ];
15
+ for (var i = 0; i < possiblePointers.length; i++) {
16
+ if (el.tagName.toLowerCase() == possiblePointers[i]) {
17
+ return "pointer";
18
+ }
19
+ }
20
+ }
21
+ return y;
22
+ };
23
+ var _elementMouseOver = function(event) {
24
+ if (!ZeroClipboard.prototype._singleton) return;
25
+ if (!event) {
26
+ event = window.event;
27
+ }
28
+ var target;
29
+ if (this !== window) {
30
+ target = this;
31
+ } else if (event.target) {
32
+ target = event.target;
33
+ } else if (event.srcElement) {
34
+ target = event.srcElement;
35
+ }
36
+ ZeroClipboard.prototype._singleton.setCurrent(target);
37
+ };
38
+ var _addEventHandler = function(element, method, func) {
39
+ if (element.addEventListener) {
40
+ element.addEventListener(method, func, false);
41
+ } else if (element.attachEvent) {
42
+ element.attachEvent("on" + method, func);
43
+ }
44
+ };
45
+ var _removeEventHandler = function(element, method, func) {
46
+ if (element.removeEventListener) {
47
+ element.removeEventListener(method, func, false);
48
+ } else if (element.detachEvent) {
49
+ element.detachEvent("on" + method, func);
50
+ }
51
+ };
52
+ var _addClass = function(element, value) {
53
+ if (element.addClass) {
54
+ element.addClass(value);
55
+ return element;
56
+ }
57
+ if (value && typeof value === "string") {
58
+ var classNames = (value || "").split(/\s+/);
59
+ if (element.nodeType === 1) {
60
+ if (!element.className) {
61
+ element.className = value;
62
+ } else {
63
+ var className = " " + element.className + " ", setClass = element.className;
64
+ for (var c = 0, cl = classNames.length; c < cl; c++) {
65
+ if (className.indexOf(" " + classNames[c] + " ") < 0) {
66
+ setClass += " " + classNames[c];
67
+ }
68
+ }
69
+ element.className = setClass.replace(/^\s+|\s+$/g, "");
70
+ }
71
+ }
72
+ }
73
+ return element;
74
+ };
75
+ var _removeClass = function(element, value) {
76
+ if (element.removeClass) {
77
+ element.removeClass(value);
78
+ return element;
79
+ }
80
+ if (value && typeof value === "string" || value === undefined) {
81
+ var classNames = (value || "").split(/\s+/);
82
+ if (element.nodeType === 1 && element.className) {
83
+ if (value) {
84
+ var className = (" " + element.className + " ").replace(/[\n\t]/g, " ");
85
+ for (var c = 0, cl = classNames.length; c < cl; c++) {
86
+ className = className.replace(" " + classNames[c] + " ", " ");
87
+ }
88
+ element.className = className.replace(/^\s+|\s+$/g, "");
89
+ } else {
90
+ element.className = "";
91
+ }
92
+ }
93
+ }
94
+ return element;
95
+ };
96
+ var _getDOMObjectPosition = function(obj) {
97
+ var info = {
98
+ left: 0,
99
+ top: 0,
100
+ width: obj.width || obj.offsetWidth || 0,
101
+ height: obj.height || obj.offsetHeight || 0,
102
+ zIndex: 9999
103
+ };
104
+ var zi = _getStyle(obj, "zIndex");
105
+ if (zi && zi != "auto") {
106
+ info.zIndex = parseInt(zi, 10);
107
+ }
108
+ while (obj && obj.offsetParent != null) {
109
+ var borderLeftWidth = parseInt(_getStyle(obj, "borderLeftWidth"), 10);
110
+ var borderTopWidth = parseInt(_getStyle(obj, "borderTopWidth"), 10);
111
+ info.left += isNaN(obj.offsetLeft) ? 0 : obj.offsetLeft;
112
+ info.left += isNaN(borderLeftWidth) ? 0 : borderLeftWidth;
113
+ info.left -= isNaN(obj.scrollLeft) ? 0 : obj.scrollLeft;
114
+ info.top += isNaN(obj.offsetTop) ? 0 : obj.offsetTop;
115
+ info.top += isNaN(borderTopWidth) ? 0 : borderTopWidth;
116
+ info.top -= isNaN(obj.scrollTop) ? 0 : obj.scrollTop;
117
+ obj = obj.offsetParent;
118
+ }
119
+ return info;
120
+ };
121
+ var _noCache = function(path) {
122
+ return (path.indexOf("?") >= 0 ? "&" : "?") + "nocache=" + (new Date).getTime();
123
+ };
124
+ var _vars = function(options) {
125
+ var str = [];
126
+ if (options.trustedDomains) {
127
+ if (typeof options.trustedDomains === "string") {
128
+ str.push("trustedDomain=" + options.trustedDomains);
129
+ } else {
130
+ str.push("trustedDomain=" + options.trustedDomains.join(","));
131
+ }
132
+ }
133
+ return str.join("&");
134
+ };
135
+ var _inArray = function(elem, array) {
136
+ if (array.indexOf) {
137
+ return array.indexOf(elem);
138
+ }
139
+ for (var i = 0, length = array.length; i < length; i++) {
140
+ if (array[i] === elem) {
141
+ return i;
142
+ }
143
+ }
144
+ return -1;
145
+ };
146
+ var _prepGlue = function(elements) {
147
+ if (typeof elements === "string") throw new TypeError("ZeroClipboard doesn't accept query strings.");
148
+ if (!elements.length) return [ elements ];
149
+ return elements;
150
+ };
151
+ var ZeroClipboard = function(elements, options) {
152
+ if (elements) (ZeroClipboard.prototype._singleton || this).glue(elements);
153
+ if (ZeroClipboard.prototype._singleton) return ZeroClipboard.prototype._singleton;
154
+ ZeroClipboard.prototype._singleton = this;
155
+ this.options = {};
156
+ for (var kd in _defaults) this.options[kd] = _defaults[kd];
157
+ for (var ko in options) this.options[ko] = options[ko];
158
+ this.handlers = {};
159
+ if (ZeroClipboard.detectFlashSupport()) _bridge();
160
+ };
161
+ var currentElement, gluedElements = [];
162
+ ZeroClipboard.prototype.setCurrent = function(element) {
163
+ currentElement = element;
164
+ this.reposition();
165
+ if (element.getAttribute("title")) {
166
+ this.setTitle(element.getAttribute("title"));
167
+ }
168
+ this.setHandCursor(_getStyle(element, "cursor") == "pointer");
169
+ };
170
+ ZeroClipboard.prototype.setText = function(newText) {
171
+ if (newText && newText !== "") {
172
+ this.options.text = newText;
173
+ if (this.ready()) this.flashBridge.setText(newText);
174
+ }
175
+ };
176
+ ZeroClipboard.prototype.setTitle = function(newTitle) {
177
+ if (newTitle && newTitle !== "") this.htmlBridge.setAttribute("title", newTitle);
178
+ };
179
+ ZeroClipboard.prototype.setSize = function(width, height) {
180
+ if (this.ready()) this.flashBridge.setSize(width, height);
181
+ };
182
+ ZeroClipboard.prototype.setHandCursor = function(enabled) {
183
+ if (this.ready()) this.flashBridge.setHandCursor(enabled);
184
+ };
185
+ ZeroClipboard.version = "1.1.7";
186
+ var _defaults = {
187
+ moviePath: "ZeroClipboard.swf",
188
+ trustedDomains: null,
189
+ text: null,
190
+ hoverClass: "zeroclipboard-is-hover",
191
+ activeClass: "zeroclipboard-is-active",
192
+ allowScriptAccess: "sameDomain"
193
+ };
194
+ ZeroClipboard.setDefaults = function(options) {
195
+ for (var ko in options) _defaults[ko] = options[ko];
196
+ };
197
+ ZeroClipboard.destroy = function() {
198
+ ZeroClipboard.prototype._singleton.unglue(gluedElements);
199
+ var bridge = ZeroClipboard.prototype._singleton.htmlBridge;
200
+ bridge.parentNode.removeChild(bridge);
201
+ delete ZeroClipboard.prototype._singleton;
202
+ };
203
+ ZeroClipboard.detectFlashSupport = function() {
204
+ var hasFlash = false;
205
+ try {
206
+ if (new ActiveXObject("ShockwaveFlash.ShockwaveFlash")) {
207
+ hasFlash = true;
208
+ }
209
+ } catch (error) {
210
+ if (navigator.mimeTypes["application/x-shockwave-flash"]) {
211
+ hasFlash = true;
212
+ }
213
+ }
214
+ return hasFlash;
215
+ };
216
+ var _bridge = function() {
217
+ var client = ZeroClipboard.prototype._singleton;
218
+ client.htmlBridge = document.getElementById("global-zeroclipboard-html-bridge");
219
+ if (client.htmlBridge) {
220
+ client.flashBridge = document["global-zeroclipboard-flash-bridge"];
221
+ return;
222
+ }
223
+ var html = ' <object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" id="global-zeroclipboard-flash-bridge" width="100%" height="100%"> <param name="movie" value="' + client.options.moviePath + _noCache(client.options.moviePath) + '"/> <param name="allowScriptAccess" value="' + client.options.allowScriptAccess + '" /> <param name="scale" value="exactfit"> <param name="loop" value="false" /> <param name="menu" value="false" /> <param name="quality" value="best" /> <param name="bgcolor" value="#ffffff" /> <param name="wmode" value="transparent"/> <param name="flashvars" value="' + _vars(client.options) + '"/> <embed src="' + client.options.moviePath + _noCache(client.options.moviePath) + '" loop="false" menu="false" quality="best" bgcolor="#ffffff" width="100%" height="100%" name="global-zeroclipboard-flash-bridge" allowScriptAccess="always" allowFullScreen="false" type="application/x-shockwave-flash" wmode="transparent" pluginspage="http://www.macromedia.com/go/getflashplayer" flashvars="' + _vars(client.options) + '" scale="exactfit"> </embed> </object>';
224
+ client.htmlBridge = document.createElement("div");
225
+ client.htmlBridge.id = "global-zeroclipboard-html-bridge";
226
+ client.htmlBridge.setAttribute("class", "global-zeroclipboard-container");
227
+ client.htmlBridge.setAttribute("data-clipboard-ready", false);
228
+ client.htmlBridge.style.position = "absolute";
229
+ client.htmlBridge.style.left = "-9999px";
230
+ client.htmlBridge.style.top = "-9999px";
231
+ client.htmlBridge.style.width = "15px";
232
+ client.htmlBridge.style.height = "15px";
233
+ client.htmlBridge.style.zIndex = "9999";
234
+ client.htmlBridge.innerHTML = html;
235
+ document.body.appendChild(client.htmlBridge);
236
+ client.flashBridge = document["global-zeroclipboard-flash-bridge"];
237
+ };
238
+ ZeroClipboard.prototype.resetBridge = function() {
239
+ this.htmlBridge.style.left = "-9999px";
240
+ this.htmlBridge.style.top = "-9999px";
241
+ this.htmlBridge.removeAttribute("title");
242
+ this.htmlBridge.removeAttribute("data-clipboard-text");
243
+ _removeClass(currentElement, this.options.activeClass);
244
+ currentElement = null;
245
+ this.options.text = null;
246
+ };
247
+ ZeroClipboard.prototype.ready = function() {
248
+ var ready = this.htmlBridge.getAttribute("data-clipboard-ready");
249
+ return ready === "true" || ready === true;
250
+ };
251
+ ZeroClipboard.prototype.reposition = function() {
252
+ if (!currentElement) return false;
253
+ var pos = _getDOMObjectPosition(currentElement);
254
+ this.htmlBridge.style.top = pos.top + "px";
255
+ this.htmlBridge.style.left = pos.left + "px";
256
+ this.htmlBridge.style.width = pos.width + "px";
257
+ this.htmlBridge.style.height = pos.height + "px";
258
+ this.htmlBridge.style.zIndex = pos.zIndex + 1;
259
+ this.setSize(pos.width, pos.height);
260
+ };
261
+ ZeroClipboard.dispatch = function(eventName, args) {
262
+ ZeroClipboard.prototype._singleton.receiveEvent(eventName, args);
263
+ };
264
+ ZeroClipboard.prototype.on = function(eventName, func) {
265
+ var events = eventName.toString().split(/\s/g);
266
+ for (var i = 0; i < events.length; i++) {
267
+ eventName = events[i].toLowerCase().replace(/^on/, "");
268
+ if (!this.handlers[eventName]) this.handlers[eventName] = func;
269
+ }
270
+ if (this.handlers.noflash && !ZeroClipboard.detectFlashSupport()) {
271
+ this.receiveEvent("onNoFlash", null);
272
+ }
273
+ };
274
+ ZeroClipboard.prototype.addEventListener = ZeroClipboard.prototype.on;
275
+ ZeroClipboard.prototype.off = function(eventName, func) {
276
+ var events = eventName.toString().split(/\s/g);
277
+ for (var i = 0; i < events.length; i++) {
278
+ eventName = events[i].toLowerCase().replace(/^on/, "");
279
+ for (var event in this.handlers) {
280
+ if (event === eventName && this.handlers[event] === func) {
281
+ delete this.handlers[event];
282
+ }
283
+ }
284
+ }
285
+ };
286
+ ZeroClipboard.prototype.removeEventListener = ZeroClipboard.prototype.off;
287
+ ZeroClipboard.prototype.receiveEvent = function(eventName, args) {
288
+ eventName = eventName.toString().toLowerCase().replace(/^on/, "");
289
+ var element = currentElement;
290
+ switch (eventName) {
291
+ case "load":
292
+ if (args && parseFloat(args.flashVersion.replace(",", ".").replace(/[^0-9\.]/gi, "")) < 10) {
293
+ this.receiveEvent("onWrongFlash", {
294
+ flashVersion: args.flashVersion
295
+ });
296
+ return;
297
+ }
298
+ this.htmlBridge.setAttribute("data-clipboard-ready", true);
299
+ break;
300
+ case "mouseover":
301
+ _addClass(element, this.options.hoverClass);
302
+ break;
303
+ case "mouseout":
304
+ _removeClass(element, this.options.hoverClass);
305
+ this.resetBridge();
306
+ break;
307
+ case "mousedown":
308
+ _addClass(element, this.options.activeClass);
309
+ break;
310
+ case "mouseup":
311
+ _removeClass(element, this.options.activeClass);
312
+ break;
313
+ case "datarequested":
314
+ var targetId = element.getAttribute("data-clipboard-target"), targetEl = !targetId ? null : document.getElementById(targetId);
315
+ if (targetEl) {
316
+ var textContent = targetEl.value || targetEl.textContent || targetEl.innerText;
317
+ if (textContent) this.setText(textContent);
318
+ } else {
319
+ var defaultText = element.getAttribute("data-clipboard-text");
320
+ if (defaultText) this.setText(defaultText);
321
+ }
322
+ break;
323
+ case "complete":
324
+ this.options.text = null;
325
+ break;
326
+ }
327
+ if (this.handlers[eventName]) {
328
+ var func = this.handlers[eventName];
329
+ if (typeof func == "function") {
330
+ func.call(element, this, args);
331
+ } else if (typeof func == "string") {
332
+ window[func].call(element, this, args);
333
+ }
334
+ }
335
+ };
336
+ ZeroClipboard.prototype.glue = function(elements) {
337
+ elements = _prepGlue(elements);
338
+ for (var i = 0; i < elements.length; i++) {
339
+ if (_inArray(elements[i], gluedElements) == -1) {
340
+ gluedElements.push(elements[i]);
341
+ _addEventHandler(elements[i], "mouseover", _elementMouseOver);
342
+ }
343
+ }
344
+ };
345
+ ZeroClipboard.prototype.unglue = function(elements) {
346
+ elements = _prepGlue(elements);
347
+ for (var i = 0; i < elements.length; i++) {
348
+ _removeEventHandler(elements[i], "mouseover", _elementMouseOver);
349
+ var arrayIndex = _inArray(elements[i], gluedElements);
350
+ if (arrayIndex != -1) gluedElements.splice(arrayIndex, 1);
351
+ }
352
+ };
353
+ if (typeof module !== "undefined") {
354
+ module.exports = ZeroClipboard;
355
+ } else {
356
+ window.ZeroClipboard = ZeroClipboard;
357
+ }
358
+ })();