script.js 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  1. /*jslint white: true, browser: true, undef: true, nomen: true, eqeqeq: true, plusplus: false, bitwise: true, regexp: true, strict: true, newcap: true, immed: true, maxerr: 14 */
  2. /*global window: false, REDIPS: true */
  3. /* enable strict mode */
  4. "use strict";
  5. // define redips_init variable
  6. var redipsInit;
  7. // redips initialization
  8. redipsInit = function () {
  9. // reference to the REDIPS.drag library and message line
  10. var rd = REDIPS.drag,
  11. msg = document.getElementById('message');
  12. // how to display disabled elements
  13. rd.style.borderDisabled = 'solid'; // border style for disabled element will not be changed (default is dotted)
  14. rd.style.opacityDisabled = 60; // disabled elements will have opacity effect
  15. // initialization
  16. rd.init();
  17. // only "smile" can be placed to the marked cell
  18. rd.mark.exception.d8 = 'smile';
  19. // prepare handlers
  20. rd.event.clicked = function () {
  21. msg.innerHTML = 'Clicked';
  22. };
  23. rd.event.dblClicked = function () {
  24. msg.innerHTML = 'Dblclicked';
  25. };
  26. rd.event.moved = function () {
  27. msg.innerHTML = 'Moved';
  28. };
  29. rd.event.notMoved = function () {
  30. msg.innerHTML = 'Not moved';
  31. };
  32. rd.event.dropped = function () {
  33. msg.innerHTML = 'Dropped';
  34. };
  35. rd.event.switched = function () {
  36. msg.innerHTML = 'Switched';
  37. };
  38. rd.event.clonedEnd1 = function () {
  39. msg.innerHTML = 'Cloned end1';
  40. };
  41. rd.event.clonedEnd2 = function () {
  42. msg.innerHTML = 'Cloned end2';
  43. };
  44. rd.event.notCloned = function () {
  45. msg.innerHTML = 'Not cloned';
  46. };
  47. rd.event.deleted = function (cloned) {
  48. // if cloned element is directly moved to the trash
  49. if (cloned) {
  50. // set id of original element (read from redips property)
  51. // var id_original = rd.obj.redips.id_original;
  52. msg.innerHTML = 'Deleted (c)';
  53. }
  54. else {
  55. msg.innerHTML = 'Deleted';
  56. }
  57. };
  58. rd.event.undeleted = function () {
  59. msg.innerHTML = 'Undeleted';
  60. };
  61. rd.event.cloned = function () {
  62. // display message
  63. msg.innerHTML = 'Cloned';
  64. // append 'd' to the element text (Clone -> Cloned)
  65. rd.obj.innerHTML += 'd';
  66. };
  67. rd.event.changed = function () {
  68. // get target and source position (method returns positions as array)
  69. var pos = rd.getPosition();
  70. // display current row and current cell
  71. msg.innerHTML = 'Changed: ' + pos[1] + ' ' + pos[2];
  72. };
  73. };
  74. // toggles trash_ask parameter defined at the top
  75. function toggleConfirm(chk) {
  76. if (chk.checked === true) {
  77. REDIPS.drag.trash.question = 'Are you sure you want to delete DIV element?';
  78. }
  79. else {
  80. REDIPS.drag.trash.question = null;
  81. }
  82. }
  83. // toggles delete_cloned parameter defined at the top
  84. function toggleDeleteCloned(chk) {
  85. REDIPS.drag.clone.drop = !chk.checked;
  86. }
  87. // enables / disables dragging
  88. function toggleDragging(chk) {
  89. REDIPS.drag.enableDrag(chk.checked);
  90. }
  91. // function sets drop_option parameter defined at the top
  92. function setMode(radioButton) {
  93. REDIPS.drag.dropMode = radioButton.value;
  94. }
  95. // show prepared content for saving
  96. function save(type) {
  97. // define table_content variable
  98. var table_content;
  99. // prepare table content of first table in JSON format or as plain query string (depends on value of "type" variable)
  100. table_content = REDIPS.drag.saveContent('table1', type);
  101. // if content doesn't exist
  102. if (!table_content) {
  103. alert('Table is empty!');
  104. }
  105. // display query string
  106. else if (type === 'json') {
  107. //window.open('/my/multiple-parameters-json.php?p=' + table_content, 'Mypop', 'width=350,height=260,scrollbars=yes');
  108. window.open('multiple-parameters-json.php?p=' + table_content, 'Mypop', 'width=350,height=260,scrollbars=yes');
  109. }
  110. else {
  111. //window.open('/my/multiple-parameters.php?' + table_content, 'Mypop', 'width=350,height=160,scrollbars=yes');
  112. window.open('multiple-parameters.php?' + table_content, 'Mypop', 'width=350,height=260,scrollbars=yes');
  113. }
  114. }
  115. // add onload event listener
  116. if (window.addEventListener) {
  117. window.addEventListener('load', redipsInit, false);
  118. }
  119. else if (window.attachEvent) {
  120. window.attachEvent('onload', redipsInit);
  121. }