PageSourceSearch

https://skve.com.my/userfiles/modules/microweber/api/tools/images.js

js skve.com.my collected 2026-09-26 10:26:25 UTC 18,786 bytes, 375 lines download raw bytes

1mw.image = {
2    isResizing: false,
3    currentResizing: null,
4    resize: {
5        create_resizer: function () {
6            if (!mw.image_resizer) {
7                var resizer = document.createElement('div');
8                resizer.className = 'mw-defaults mw_image_resizer';
9                resizer.innerHTML = '<div id="image-edit-nav"><span onclick="mw.wysiwyg.media(\'#editimage\');" class="btn btn-link mw-ui-btn-invert mw-ui-btn-icon image_change tip" data-tip="' + mw.msg.change + '"><span class="mdi mdi-image mdi-18px"></span></span><span class="btn btn-link mw-ui-btn-invert mw-ui-btn-icon tip image_change" id="image-settings-button" data-tip="' + mw.msg.edit + '" onclick="mw.image.settings();"><span class="mdi mdi-pencil mdi-18px"></span></span></div>';
10                document.body.appendChild(resizer);
11                mw.image_resizer = resizer;
12                mw.image_resizer_time = null;
13                mw.image_resizer._show = function () {
14                    clearTimeout(mw.image_resizer_time)
15                    mw.$(mw.image_resizer).addClass('active')
16                };
17                mw.image_resizer._hide = function () {
18                    clearTimeout(mw.image_resizer_time)
19                    mw.image_resizer_time = setTimeout(function () {
20                        mw.$(mw.image_resizer).removeClass('active')
21                    }, 3000)
22                };
23
24                mw.$(resizer).on("click", function (e) {
25                    if (mw.image.currentResizing[0].nodeName === 'IMG') {
26                        mw.wysiwyg.select_element(mw.image.currentResizing[0])
27                    }
28                });
29                mw.$(resizer).on("dblclick", function (e) {
30                    mw.wysiwyg.media('#editimage');
31                });
32            }
33        },
34        prepare: function () {
35            mw.image.resize.create_resizer();
36            mw.$(mw.image_resizer).resizable({
37                handles: "all",
38                minWidth: 60,
39                minHeight: 60,
40                start: function () {
41                    mw.image.isResizing = true;
42                    mw.$(mw.image_resizer)
43                        .resizable("option", "maxWidth", mw.image.currentResizing.parent().width())
44                        .height('auto');
45                    mw.$(mw.tools.firstParentWithClass(mw.image.currentResizing[0], 'edit')).addClass("changed");
46                },
47                stop: function () {
48                    mw.image.isResizing = false;
49                    mw.drag.fix_placeholders();
50                    mw.image.currentResizing[0].style.height = 'auto';
51                    mw.wysiwyg.change(mw.image.currentResizing[0]);
52
53
54                },
55                resize: function () {
56                    var offset = mw.image.currentResizing.offset();
57                    mw.$(this).css(offset);
58                    mw.image.currentResizing[0].style.height = 'auto';
59                 },
60                aspectRatio: 16 / 9
61            });
62            mw.image_resizer.mwImageResizerComponent = true;
63            var all = mw.image_resizer.querySelectorAll('*'), l = all.length, i = 0;
64            for (; i < l; i++) all[i].mwImageResizerComponent = true
65        },
66        resizerSet: function (el, selectImage) {
67            selectImage = typeof selectImage === 'undefined' ? true : selectImage;
68            /*  var order = mw.tools.parentsOrder(el, ['edit', 'module']);
69             if(!(order.module > -1 && order.edit > order.module) && order.edit>-1){   */
70
71
72            mw.$('.ui-resizable-handle', mw.image_resizer)[el.nodeName == 'IMG' ? 'show' : 'hide']()
73
74            el = mw.$(el);
75            var offset = el.offset();
76            var parent = el.parent();
77            var parentOffset = parent.offset();
78            if(parent[0].nodeName !== 'A'){
79                offset.top = offset.top < parentOffset.top ? parentOffset.top : offset.top;
80                offset.left = offset.left < parentOffset.left ? parentOffset.left : offset.left;
81            }
82            var r = mw.$(mw.image_resizer);
83            var width = el.outerWidth();
84            var height = el.outerHeight();
85            r.css({
86                left: offset.left,
87                top: offset.top,
88                width: width,
89                height: mw.tools.hasParentsWithClass(el[0], 'mw-image-holder') ? 1 : height
90            });
91            r.addClass("active");
92            mw.$(mw.image_resizer).resizable("option", "alsoResize", el);
93            mw.$(mw.image_resizer).resizable("option", "aspectRatio", width / height);
94            mw.image.currentResizing = el;
95            if (!el[0].contentEditable) {
96                mw.wysiwyg.contentEditable(el[0], true);
97            }
98
99            if (selectImage) {
100                if (el[0].parentNode.tagName !== 'A') {
101                    mw.wysiwyg.select_element(el[0]);
102                }
103                else {
104                    mw.wysiwyg.select_element(el[0].parentNode);
105                }
106            }
107            if (document.getElementById('image-settings-button') !== null) {
108                if (!!el[0].src && el[0].src.contains('userfiles/media/pixum/')) {
109                    document.getElementById('image-settings-button').style.display = 'none';
110                }
111                else {
112                    document.getElementById('image-settings-button').style.display = '';
113                }
114            }
115            /* } */
116        },
117        init: function (selector) {
118            mw.image_resizer == undefined ? mw.image.resize.prepare() : '';
119
120            mw.on("ImageClick", function (e, el) {
121                if (!mw.image.isResizing && !mw.isDrag && !mw.settings.resize_started && el.tagName === 'IMG') {
122                    mw.image.resize.resizerSet(el);
123                }
124            })
125        }
126    },
127
128    _isrotating: false,
129    rotate: function (img_object, angle) {
130        if (!mw.image.Rotator) {
131            mw.image.Rotator = document.createElement('canvas');
132            mw.image.Rotator.style.top = '-9999px';
133            mw.image.Rotator.style.left = '-9999px';
134            mw.image.Rotator.style.position = 'absolute';
135            mw.image.RotatorContext = mw.image.Rotator.getContext('2d');
136            document.body.appendChild(mw.image.Rotator);
137        }
138        if (!mw.image._isrotating) {
139            mw.image._isrotating = true;
140            img_object = img_object || document.querySelector("img.element-current");
141            if (img_object === null) {
142                return false;
143            }
144            mw.image.preload(img_object.src, function () {
145                if (!img_object.src.contains("base64")) {
146                    var currDomain = mw.url.getDomain(window.location.href);
147                    var srcDomain = mw.url.getDomain(img_object.src);
148                    if (currDomain !== srcDomain) {
149                        mw.tools.alert("This action is allowed for images on the same domain.");
150                        return false;
151                    }
152                }
153                var angle = angle || 90;
154                var image = mw.$(this);
155                var w = this.naturalWidth;
156                var h = this.naturalHeight;
157                var contextWidth = w;
158                var contextHeight = h;
159                var x = 0;
160                var y = 0;
161                switch (angle) {
162                    case 90:
163                        contextWidth = h;
164                        contextHeight = w;
165                        y = -h;
166                        break;
167                    case 180:
168                        x = -w;
169                        y = -h;
170                        break;
171                    case 270:
172                        contextWidth = h;
173                        contextHeight = w;
174                        x = -w;
175                        break;
176                    default:
177                        contextWidth = h;
178                        contextHeight = w;
179                        y = -h;
180                }
181                mw.image.Rotator.setAttribute('width', contextWidth);
182                mw.image.Rotator.setAttribute('height', contextHeight);
183                mw.image.RotatorContext.rotate(angle * Math.PI / 180);
184                mw.image.RotatorContext.drawImage(img_object, x, y);
185                var data = mw.image.Rotator.toDataURL("image/png");
186                img_object.src = data;
187                mw.image._isrotating = false;
188             });
189        }
190    },
191    grayscale: function (node) {
192        var node = node || document.querySelector("img.element-current");
193        if (node === null) {
194            return false;
195        }
196        mw.image.preload(node.src, function () {
197            var canvas = document.createElement('canvas');
198            var ctx = canvas.getContext('2d');
199            canvas.width = this.naturalWidth;
200            canvas.height = this.naturalHeight;
201            ctx.drawImage(node, 0, 0);
202            var imgPixels = ctx.getImageData(0, 0, canvas.width, canvas.height);
203            for (var y = 0; y < imgPixels.height; y++) {
204                for (var x = 0; x < imgPixels.width; x++) {
205                    var i = (y * 4) * imgPixels.width + x * 4; //Why is this multiplied by 4?
206                    var avg = (imgPixels.data[i] + imgPixels.data[i + 1] + imgPixels.data[i + 2]) / 3;
207                    imgPixels.data[i] = avg;
208                    imgPixels.data[i + 1] = avg;
209                    imgPixels.data[i + 2] = avg;
210                }
211            }
212            ctx.putImageData(imgPixels, 0, 0, 0, 0, imgPixels.width, imgPixels.height);
213            node.src = canvas.toDataURL();
214        })
215    },
216    vr: [0, 0, 0, 1, 1, 2, 3, 3, 3, 4, 4, 4, 5, 5, 5, 6, 6, 7, 7, 7, 7, 8, 8, 8, 9, 9, 9, 9, 10, 10, 10, 10, 11, 11, 12, 12, 12, 12, 13, 13, 13, 14, 14, 15, 15, 16, 16, 17, 17, 17, 18, 19, 19, 20, 21, 22, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 39, 40, 41, 42, 44, 45, 47, 48, 49, 52, 54, 55, 57, 59, 60, 62, 65, 67, 69, 70, 72, 74, 77, 79, 81, 83, 86, 88, 90, 92, 94, 97, 99, 101, 103, 
216107, 109, 111, 112, 116, 118, 120, 124, 126, 127, 129, 133, 135, 136, 140, 142, 143, 145, 149, 150, 152, 155, 157, 159, 162, 163, 165, 167, 170, 171, 173, 176, 177, 178, 180, 183, 184, 185, 188, 189, 190, 192, 194, 195, 196, 198, 200, 201, 202, 203, 204, 206, 207, 208, 209, 211, 212, 213, 214, 215, 216, 218, 219, 219, 220, 221, 222, 223, 224, 225, 226, 227, 227, 228, 229, 229, 230, 231, 232, 232, 233, 234, 234, 235, 236, 236, 237, 238, 238, 239, 239, 240, 241, 241, 242, 242, 243, 244, 244, 245, 245, 245, 246, 247, 247, 248, 248, 249, 249, 249, 250, 251, 251, 252, 252, 252, 253, 254, 254, 254, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255],
217    vg: [0, 0, 1, 2, 2, 3, 5, 5, 6, 7, 8, 8, 10, 11, 11, 12, 13, 15, 15, 16, 17, 18, 18, 19, 21, 22, 22, 23, 24, 26, 26, 27, 28, 29, 31, 31, 32, 33, 34, 35, 35, 37, 38, 39, 40, 41, 43, 44, 44, 45, 46, 47, 48, 50, 51, 52, 53, 54, 56, 57, 58, 59, 60, 61, 63, 64, 65, 66, 67, 68, 69, 71, 72, 73, 74, 75, 76, 77, 79, 80, 81, 83, 84, 85, 86, 88, 89, 90, 92, 93, 94, 95, 96, 97, 100, 101, 102, 103, 105, 106, 107, 108, 109, 111, 113, 114, 115, 117, 118, 119, 120, 122, 123, 124, 126, 127, 128, 129, 131, 132, 133, 135, 136, 137, 138, 140, 141, 142, 144, 145, 146, 148, 149, 150, 151, 153, 154, 155, 157, 158, 159, 160, 162, 163, 164, 166, 167, 168, 169, 171, 172, 173, 174, 175, 176, 177, 178, 179, 181, 182, 183, 184, 186, 186, 187, 188, 189, 190, 192, 193, 194, 195, 195, 196, 197, 199, 200, 201, 202, 202, 203, 204, 205, 206, 207, 208, 208, 209, 210, 211, 212, 213, 214, 214, 215, 216, 217, 218, 219, 219, 220, 221, 222, 223, 223, 224, 225, 226, 226, 227, 228, 228, 229, 230, 231, 232, 232, 232, 233, 234, 235, 235, 236, 236, 237, 238, 238, 239, 239, 240, 240, 241, 242, 242, 242, 243, 244, 245, 245, 246, 246, 247, 247, 248, 249, 249, 249, 250, 251, 251, 252, 252, 252, 253, 254, 255],
218    vb: [53, 53, 53, 54, 54, 54, 55, 55, 55, 56, 57, 57, 57, 58, 58, 58, 59, 59, 59, 60, 61, 61, 61, 62, 62, 63, 63, 63, 64, 65, 65, 65, 66, 66, 67, 67, 67, 68, 69, 69, 69, 70, 70, 71, 71, 72, 73, 73, 73, 74, 74, 75, 75, 76, 77, 77, 78, 78, 79, 79, 80, 81, 81, 82, 82, 83, 83, 84, 85, 85, 86, 86, 87, 87, 88, 89, 89, 90, 90, 91, 91, 93, 93, 94, 94, 95, 95, 96, 97, 98, 98, 99, 99, 100, 101, 102, 102, 103, 104, 105, 105, 106, 106, 107, 108, 109, 109, 110, 111, 111, 112, 113, 114, 114, 115, 116, 117, 117, 118, 119, 119, 121, 121, 122, 122, 123, 124, 125, 126, 126, 127, 128, 129, 129, 130, 131, 132, 132, 133, 134, 134, 135, 136, 137, 137, 138, 139, 140, 140, 141, 142, 142, 143, 144, 145, 145, 146, 146, 148, 148, 149, 149, 150, 151, 152, 152, 153, 153, 154, 155, 156, 156, 157, 157, 158, 159, 160, 160, 161, 161, 162, 162, 163, 164, 164, 165, 165, 166, 166, 167, 168, 168, 169, 169, 170, 170, 171, 172, 172, 173, 173, 174, 174, 175, 176, 176, 177, 177, 177, 178, 178, 179, 180, 180, 181, 181, 181, 182, 182, 183, 184, 184, 184, 185, 185, 186, 186, 186, 187, 188, 188, 188, 189, 189, 189, 190, 190, 191, 191, 192, 192, 193, 193, 193, 194, 194, 194, 195, 196, 196, 196, 197, 197, 197, 198, 199],
219    vintage: function (node) {
220        var node = node || document.querySelector("img.element-current");
221        if (node === null) {
222            return false;
223        }
224        var canvas = document.createElement('canvas');
225        var ctx = canvas.getContext('2d');
226        mw.image.preload(node.src, function (w, h) {
227            canvas.width = w;
228            canvas.height = h;
229            ctx.drawImage(node, 0, 0);
230            var imageData = ctx.getImageData(0, 0, canvas.width, canvas.height), l = imageData.data.length, i = 0;
231            for (; i < l; i += 4) {
232                imageData.data[i] = mw.image.vr[imageData.data[i]];
233                imageData.data[i + 1] = mw.image.vg[imageData.data[i + 1]];
234                imageData.data[i + 2] = mw.image.vb[imageData.data[i + 2]];
235                if (noise > 0) {
236                    var noise = Math.round(noise - Math.random() * noise), j = 0;
237                    for (; j < 3; j++) {
238                        var iPN = noise + imageData.data[i + j];
239                        imageData.data[i + j] = (iPN > 255) ? 255 : iPN;
240                    }
241                }
242            }
243            ctx.putImageData(imageData, 0, 0);
244            node.src = canvas.toDataURL();
245            mw.$(canvas).remove()
246        });
247    },
248    _dragActivated: false,
249    _dragcurrent: null,
250    _dragparent: null,
251    _dragcursorAt: {x: 0, y: 0},
252    _dragTxt: function (e) {
253        if (mw.image._dragcurrent !== null) {
254            mw.image._dragcursorAt.x = e.pageX - mw.image._dragcurrent.offsetLeft;
255            mw.image._dragcursorAt.y = e.pageY - mw.image._dragcurrent.offsetTop;
256            var x = e.pageX - mw.image._dragparent.offsetLeft - mw.image._dragcurrent.startedX - mw.image._dragcursorAt.x;
257            var y = e.pageY - mw.image._dragparent.offsetTop - mw.image._dragcurrent.startedY - mw.image._dragcursorAt.y;
258            mw.image._dragcurrent.style.top = y + 'px';
259            mw.image._dragcurrent.style.left = x + 'px';
260        }
261    },
262    preloadForAll: function (array, eachCall, callback) {
263        var size = array.length, i = 0, count = 0;
264        for (; i < size; i++) {
265            mw.image.preload(array[i], function (imgWidth, imgHeight) {
266                count++;
267                if(eachCall) {
268                    eachCall.call(this, imgWidth, imgHeight)
269                }
270                if (count === size) {
271                    if (!!callback) callback.call()
272                }
273            })
274        }
275    },
276    preloadAll: function (array, callback) {
277        var size = array.length, i = 0, count = 0;
278        for (; i < size; i++) {
279            mw.image.preload(array[i], function () {
280                count++;
281                if (count === size) {
282                    callback.call()
283                }
284            })
285        }
286    },
287    preload: function (url, callback) {
288        var img;
289        if (typeof window.chrome === 'object') {
290            var img = new Image();
291        }
292        else {
293            img = document.createElement('img')
294        }
295        img.className = 'semi_hidden';
296        img.src = url;
297        img.onload = function () {
298            setTimeout(function () {
299                if (typeof callback === 'function') {
300                    callback.call(img, img.naturalWidth, img.naturalHeight);
301                }
302                mw.$(img).remove();
303            }, 33);
304        }
305        img.onerror = function () {
306            setTimeout(function () {
307                if (typeof callback === 'function') {
308                    callback.call(img, 0, 0, 'error');
309                }
310            }, 33);
311        }
312        document.body.appendChild(img);
313    },
314    preloadAsLink: function (url, callback) {
315
316        var link = document.createElement("link");
317        link.href = url;
318        link.rel = "preload";
319        link.as = "image";
320        link.onload = function () {
321            setTimeout(function () {
322                if (typeof callback === 'function') {
323                    callback.call(img);
324                }
325            }, 33);
326        };
327        link.onerror = function () {
328            setTimeout(function () {
329                if (typeof callback === 'function') {
330                    callback.call(img);
331                }
332            }, 33);
333        };
334        document.head.appendChild(link);
335    },
336
337    description: {
338        add: function (text) {
339            var img = document.querySelector("img.element-current");
340            img.title = text;
341        },
342        get: function () {
343            return document.querySelector("img.element-current").title;
344        },
345        init: function (id) {
346            var area = mw.$(id);
347            area.hover(function () {
348                area.addClass("desc_area_hover");
349            }, function () {
350                area.removeClass("desc_area_hover");
351            });
352            var curr = mw.image.description.get();
353            if (!area.hasClass("inited")) {
354                area.addClass("inited");
355                area.bind("keyup change paste", function () {
356                    var val = mw.$(this).val();
357                    mw.image.description.add(val);
358                });
359            }
360            area.val(curr);
361            area.show();
362        }
363    },
364    settings: function () {
365        return mw.dialogIframe({
366            url: 'imageeditor',
367            template: "mw_modal_basic",
368            overlay: true,
369            width: '600',
370            height: "auto",
371            autoHeight: true,
372            name: 'mw-image-settings-modal'
373        });
374    }
375};

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.