Project

General

Profile

1
/**
2
 *
3
 */
4
domReady(function() {
5

    
6
//    LoadOnFly ( 'body', WB_URL + '/modules/droplets/js/draggabilly.pkgd.js' );
7
//    LoadOnFly ( 'body', WB_URL + '/modules/droplets/js/modal.js' );
8

    
9
    function toggle_visibility(id) {
10
       var e = document.getElementById(id);
11
       if(e.style.display == 'block')
12
          e.style.display = 'none';
13
       else
14
          e.style.display = 'block';
15
    }
16
// CHANGELOG 20160323
17
    function addEvent(elem, event, fn) {
18
        if(!elem) { return false; }
19
//console.info (elem);
20
        if (elem.addEventListener) {
21
            elem.addEventListener(event, fn, false);
22
        } else {
23
            elem.attachEvent("on" + event, function() {
24
                // set the this pointer same as addEventListener when fn is called
25
                return(fn.call(elem, window.event));
26
            });
27
        }
28
    }
29

    
30
    function mouseX (e) {
31
      if (e.pageX) {
32
        return e.pageX;
33
      }
34
      if (e.clientX) {
35
        return e.clientX + (document.documentElement.scrollLeft ?
36
                            document.documentElement.scrollLeft :
37
                            document.body.scrollLeft);
38
      }
39
      return null;
40
    }
41

    
42
    function mouseY (e) {
43
      if (e.pageY) {
44
        return e.pageY;
45
      }
46
      if (e.clientY) {
47
        return e.clientY + (document.documentElement.scrollTop ?
48
                            document.documentElement.scrollTop :
49
                            document.body.scrollTop);
50
      }
51
      return null;
52
    }
53

    
54
    function dragable (clickEl,dragEl) {
55
      var p = get(clickEl);
56
      var t = get(dragEl);
57
      var drag = false;
58
      offsetX = 0;
59
      offsetY = 0;
60
      var mousemoveTemp = null;
61
      if (t) {
62
        var move = function (x,y) {
63
          t.style.left = (parseInt(t.style.left)+x) + "px";
64
          t.style.top  = (parseInt(t.style.top) +y) + "px";
65
        }
66
        var mouseMoveHandler = function (e) {
67
          e = e || window.event;
68
          if(!drag){return true};
69
          var x = mouseX(e);
70
          var y = mouseY(e);
71
          if (x != offsetX || y != offsetY) {
72
            move(x-offsetX,y-offsetY);
73
            offsetX = x;
74
            offsetY = y;
75
          }
76
          return false;
77
        }
78
        var start_drag = function (e) {
79
          e = e || window.event;
80
          offsetX=mouseX(e);
81
          offsetY=mouseY(e);
82
          drag=true; // basically we're using this to detect dragging
83
          // save any previous mousemove event handler:
84
          if (document.body.onmousemove) {
85
            mousemoveTemp = document.body.onmousemove;
86
          }
87
          document.body.onmousemove = mouseMoveHandler;
88
          return false;
89
        }
90
        var stop_drag = function () {
91
          drag=false;
92
          // restore previous mousemove event handler if necessary:
93
          if (mousemoveTemp) {
94
            document.body.onmousemove = mousemoveTemp;
95
            mousemoveTemp = null;
96
          }
97
          return false;
98
        }
99
        p.onmousedown = start_drag;
100
        p.onmouseup = stop_drag;
101
      }
102
    }
103

    
104
    function move(ev) {
105
      ev.dataTransfer.setData('text', ev.target.id);
106
    }
107

    
108
    window.addEventListener("load",function () {
109
      initCheckboxes();
110
//      addEvent(document.getElementById('selectOrder'), 'change', changeOrder);
111
      var dragItems = document.querySelectorAll("[draggable=true]")
112
      for (var i = 0; i < dragItems.length; i++) {
113
        var draggable = dragItems[i];
114
        draggable.addEventListener("dragstart",move);
115
      };
116
    });
117
//    addEvent( window, 'load', initCheckboxes );
118
    function initCheckboxes() {
119
        addEvent(document.getElementById('select_all'), 'click', setCheckboxes);
120
    }
121
    function setCheckboxes() {
122
        var cb = document.getElementById( 'cb-droplets' ).getElementsByTagName('input');
123
        var isChecked = document.getElementById('select_all').checked;
124
        for (var i = 0; i < cb.length; i++) {
125
            cb[i].checked = isChecked;
126
        }
127
    }
128

    
129
    function selectSingleElement(IdSuffix, el ) {
130
        document.getElementById(el.id + IdSuffix).checked ='checked';
131
        document.getElementById('select_all').checked =false;
132
    }
133

    
134
    function deselectAllElements(IdSuffix, el ) {
135
        for ( i = 0;; i++) {
136
            if (!(e = document.getElementById('L' + i + IdSuffix))) {
137
                break;
138
            }
139
            e.checked = el.checked;
140
        }
141
    }
142
    function changeOrder(){
143
console.info(this);
144
    }
145

    
146
});
147
/*-------------------------------------------------------------------------------------------------*/
148
if (typeof Droplet ==="object"){
149
    var DR_MODULE_URL = Droplet.AddonUrl;
150
    var DR_ICONS = Droplet.ThemeUrl + 'img';
151
    var DR_AJAX_PLUGINS =  Droplet.AddonUrl + 'ajax';  // this var could change in the future
152
    var LANGUAGE = LANGUAGE ? LANGUAGE : 'EN'; // set var LANGUAGE to EN if LANGUAGE not set before
153
    /*
154
    console.info(DR_MODULE_URL);
155
    console.info(DR_ICONS);
156
    console.info(DR_AJAX_PLUGINS);
157
    */
158
            $.insert(  Droplet.AddonUrl + 'ajax' +"/ajaxActiveStatus.js");
159
            // AjaxHelper change item active status
160
            $("td.toggle_active_status").ajaxActiveStatus({
161
                    MODULE : Droplet.AddonUrl,
162
                    DB_COLUMN: 'id',
163
                    sIdKey: ''
164
            });
165
}
(5-5/15)