root / drupal7 / sites / all / modules / ds / modules / ds_extras / js / ds_extras.js @ bf6fb0ee
1 |
/**
|
---|---|
2 |
* @file
|
3 |
* Javascript functionality for the Display Suite Extras module.
|
4 |
*/
|
5 |
|
6 |
(function ($) { |
7 |
|
8 |
// Switch view mode inline with AJAX, for the 'View mode switcher' option.
|
9 |
Drupal.behaviors.DSExtrasSwitchViewmode = { |
10 |
attach: function (context) { |
11 |
|
12 |
if ($('.switch-view-mode-field').length > 0) { |
13 |
$('.switch-view-mode-field a').click(function() { |
14 |
|
15 |
// Create an object.
|
16 |
var link = $(this); |
17 |
|
18 |
// Get params from the class.
|
19 |
var params = $(this).attr('class').split('-'); |
20 |
|
21 |
$.ajax({
|
22 |
type: 'GET', |
23 |
url: Drupal.settings.basePath + 'ds-switch-view-mode', |
24 |
data: {entity_type: params[0], view_mode: params[3], id: params[2]}, |
25 |
dataType: 'json', |
26 |
success: function (data) { |
27 |
if (data.status) {
|
28 |
old_view_mode = params[1];
|
29 |
wrapper = link.parents('.view-mode-' + old_view_mode);
|
30 |
Drupal.theme('DisplaySuiteSwitchViewmode', wrapper, data.content);
|
31 |
Drupal.attachBehaviors(); |
32 |
} |
33 |
else {
|
34 |
alert(data.errorMessage); |
35 |
} |
36 |
}, |
37 |
error: function (xmlhttp) { |
38 |
alert(Drupal.t('An HTTP error @status occurred.', {'@status': xmlhttp.status})); |
39 |
} |
40 |
}); |
41 |
return false; |
42 |
}); |
43 |
} |
44 |
} |
45 |
}; |
46 |
|
47 |
/**
|
48 |
* Theme function for a replacing content of Display Suite content wrapper.
|
49 |
*
|
50 |
* @param wrapper
|
51 |
* The HTML object which needs to be replaced
|
52 |
* @param content
|
53 |
* The new content
|
54 |
*/
|
55 |
Drupal.theme.prototype.DisplaySuiteSwitchViewmode = function (wrapper, content) { |
56 |
wrapper.replaceWith(content); |
57 |
}; |
58 |
|
59 |
})(jQuery); |