This repository has been archived by the owner on Apr 24, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathmediamosa_ck.js
145 lines (126 loc) · 4.03 KB
/
mediamosa_ck.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
/**
* Basic JS functions.
*/
(function($) {
Drupal.behaviors.mediamosa_ck = {
attach: function (context, settings) {
// Process links for AJAX tabs.
$('div.mediamosa-ck-tabs').once('mediamosa-ck-tabs', Drupal.mediamosaCK.mediamosa_ck_tab);
// For closing the popups.
$('div.mediamosa-ck-icon-close').once('ck-icon-close').click(function(e) {
// Hide it first.
$(this).parent('div.mediamosa-ck-popup').hide();
// Remove the contents of the popup, will make the next popup faster.
$(this).parent('div.mediamosa-ck-popup').remove();
});
}
};
Drupal.mediamosaCK = Drupal.mediamosaCK || {};
/**
* Create upload ticket.
*
* @return array
* - 'action'
* The upload URL for the file.
* - 'progress_id'
* Progress ID to use when getting upload progression from server.
* - 'uploadprogress_url'
* A json based progress URL.
* - 'asset_id'
* The asset ID of the upload.
* - 'mediafile_id'
* The mediafile ID of the upload.
*/
Drupal.mediamosaCK.getUploadTicket = function(file) {
var result = null;
$.ajax({
type: 'GET',
url: Drupal.settings.basePath + 'mediamosa/ck/json/uploadticket/create?filename=' + escape(file.name),
async: false,
dataType: 'json',
success: function (uploadticket) {
if (typeof uploadticket.action !== undefined) {
result = uploadticket;
}
},
error: function (xmlhttp) {
alert(Drupal.ajaxError(xmlhttp, 'mediamosa/ck/json/uploadticket/create'));
console.log('Unable to get upload ticket!');
}
});
return result;
}
/**
* Check if MediaMosa connector is setup correctly.
*
* @return boolean
* Either true (success) or false (failure).
*/
Drupal.mediamosaCK.getConnectorStatus = function() {
var result = false;
$.ajax({
type: 'GET',
url: Drupal.settings.basePath + 'mediamosa/ck/json/connector/status',
async: false,
dataType: 'json',
success: function (status) {
result = (parseInt(status.ok) === 1);
},
error: function (xmlhttp) {
alert(Drupal.ajaxError(xmlhttp, 'mediamosa/ck/json/connector/status'));
}
});
return result;
}
/**
* Helper function to parse a querystring.
*/
Drupal.mediamosaCK.parseQueryString = function (query) {
var args = {};
var pos = query.indexOf('?');
if (pos !== -1) {
query = query.substring(pos + 1);
}
var pairs = query.split('&');
for(var i in pairs) {
if (typeof(pairs[i]) === 'string') {
var pair = pairs[i].split('=');
// Ignore the 'q' path argument, if present.
if (pair[0] !== 'q' && pair[1]) {
args[decodeURIComponent(pair[0].replace(/\+/g, ' '))] = decodeURIComponent(pair[1].replace(/\+/g, ' '));
}
}
}
return args;
};
Drupal.mediamosaCK.mediamosa_ck_tab = function() {
var navigation = $(this);
// Hide all tab content.
navigation.find('.mediamosa-ck-tab-content').hide();
// If the current URL has a fragment and one of the tabs contains an
// element that matches the URL fragment, activate that tab.
var tab_focus;
if (window.location.hash && $(this).find(window.location.hash).length) {
tab_focus = navigation.find(window.location.hash).closest('ul.mediamosa-ck-tabs > li');
navigation.find(window.location.hash).parents('ul.mediamosa-ck-tabs > li').map(function() {
$('#' + $(this).children('a').attr('name')).show();
$(this).addClass('active');
});
}
if (tab_focus === undefined) {
// Make first tab active.
navigation.find('ul.mediamosa-ck-tabs > li').first().addClass('active');
navigation.find('.mediamosa-ck-tab-content').first().show();
}
navigation.find('a.ck-tab-link').once('ck-tab-link').click(function(e) {
// Show my contents.
$('#' + $(this).attr('name')).show();
// Hide other tab contents, except mine.
$('#' + $(this).attr('name')).siblings('.mediamosa-ck-tab-content').hide();
// Remove the 'active' status of all tabs.
$(this).parents('ul').children('li').removeClass('active');
// Activate my tab.
$(this).parent('li').addClass('active');
});
};
})(jQuery);