| 1 |
/** |
/** |
| 2 |
* webforms2_repetition.js |
* webforms2_repetition.js |
| 3 |
*/ |
*/ |
| 4 |
|
|
| 5 |
Drupal.webforms2Repetition = { |
Drupal.webforms2Repetition = { |
| 6 |
activeButton: null, // Used to track which "add" button was last clicked |
activeButton: null, // Used to track which "add" button was last clicked |
| 9 |
}; |
}; |
| 10 |
|
|
| 11 |
/** |
/** |
| 12 |
* Tracking which button was last clicked is difficult, because the webforms2 |
* Tracking which button was last clicked is difficult, because the webforms2 |
| 13 |
* library has its own way of managing events, rather than using the jquery framework. |
* library has its own way of managing events, rather than using the jquery framework. |
| 14 |
* Furthermore, it explicitly does things to the "onclick" event, in a custom way. |
* Furthermore, it explicitly does things to the "onclick" event, in a custom way. |
| 15 |
* The only solution I found that seems to work reliably is to have the PHP |
* The only solution I found that seems to work reliably is to have the PHP |
| 16 |
* code set the "onclick" attribute on the button directly in the html. |
* code set the "onclick" attribute on the button directly in the html. |
| 17 |
*/ |
*/ |
| 18 |
Drupal.webforms2Repetition.onButtonClicked = function(e) { |
Drupal.webforms2Repetition.onButtonClicked = function(e) { |
| 19 |
var oTarget = e.target ? e.target : e.srcElement; |
var oTarget = e.target ? e.target : e.srcElement; |
| 20 |
if (oTarget && oTarget != Drupal.webforms2Repetition.activeButton) { |
if (oTarget && oTarget != Drupal.webforms2Repetition.activeButton) { |
| 32 |
} |
} |
| 33 |
|
|
| 34 |
/** |
/** |
| 35 |
* Event handler called on the repetition template, when a new block is added. |
* Event handler called on the repetition template, when a new block is added. |
| 36 |
*/ |
*/ |
| 37 |
Drupal.webforms2Repetition.onBlockAdded = function(e) { |
Drupal.webforms2Repetition.onBlockAdded = function(e) { |
| 38 |
var oNewBlock; |
var oNewBlock; |
| 39 |
|
|
| 63 |
} |
} |
| 64 |
|
|
| 65 |
/** |
/** |
| 66 |
* Event handler called on the repetition template, when a block is moved. |
* Event handler called on the repetition template, when a block is moved. |
| 67 |
*/ |
*/ |
| 68 |
Drupal.webforms2Repetition.onBlockMoved = function(e) { |
Drupal.webforms2Repetition.onBlockMoved = function(e) { |
| 69 |
if (Drupal.webforms2Repetition.activeButton) { |
if (Drupal.webforms2Repetition.activeButton) { |
| 70 |
var sButtonType = $(Drupal.webforms2Repetition.activeButton).attr('type').toLowerCase(); |
var sButtonType = $(Drupal.webforms2Repetition.activeButton).attr('type').toLowerCase(); |
| 76 |
} |
} |
| 77 |
|
|
| 78 |
/** |
/** |
| 79 |
* Event handler called on the repetition template, when a block is removed. |
* Event handler called on the repetition template, when a block is removed. |
| 80 |
*/ |
*/ |
| 81 |
Drupal.webforms2Repetition.onBlockRemoved = function(e) { |
Drupal.webforms2Repetition.onBlockRemoved = function(e) { |
| 82 |
Drupal.webforms2Repetition.activeButton = null; |
Drupal.webforms2Repetition.activeButton = null; |
| 83 |
} |
} |
| 84 |
|
|
| 85 |
/** |
/** |
| 86 |
* Let interested objects subscribe to events |
* Let interested objects subscribe to events |
| 87 |
*/ |
*/ |
| 88 |
Drupal.webforms2Repetition.subscribe = function(oSubscriber) { |
Drupal.webforms2Repetition.subscribe = function(oSubscriber) { |
| 89 |
Drupal.webforms2Repetition.subscribers.push(oSubscriber); |
Drupal.webforms2Repetition.subscribers.push(oSubscriber); |
| 90 |
} |
} |
| 91 |
|
|
| 92 |
/** |
/** |
| 93 |
* Notify subscribers of anything interesting that happens |
* Notify subscribers of anything interesting that happens |
| 94 |
*/ |
*/ |
| 95 |
Drupal.webforms2Repetition.notifySubscribers = function(sEvent, oBlock) { |
Drupal.webforms2Repetition.notifySubscribers = function(sEvent, oBlock) { |
| 96 |
//alert(sEvent + "\n" + oBlock.innerHTML); |
//alert(sEvent + "\n" + oBlock.innerHTML); |
| 97 |
var i, o; |
var i, o; |
| 102 |
} |
} |
| 103 |
|
|
| 104 |
/** |
/** |
| 105 |
* Document Ready |
* Document Ready |
| 106 |
*/ |
*/ |
| 107 |
$(function() { |
$(function() { |
| 108 |
// For each repetition template |
// For each repetition template |
| 109 |
$(".webforms2_repetition_template").each(function() { |
$(".webforms2_repetition_template").each(function() { |