aboutsummaryrefslogtreecommitdiff
path: root/static/js/wpaint/src/wPaint.utils.js
diff options
context:
space:
mode:
authorLibravatar bai 2019-03-29 02:14:43 +0000
committerLibravatar bai 2019-03-29 02:14:43 +0000
commit95dfe14528663923ca2a88ec928f1d8d9df2402b (patch)
tree5bc88d1466957f1aa39043b056bde5c439648022 /static/js/wpaint/src/wPaint.utils.js
downloadweabot-95dfe14528663923ca2a88ec928f1d8d9df2402b.tar.gz
weabot-95dfe14528663923ca2a88ec928f1d8d9df2402b.tar.xz
weabot-95dfe14528663923ca2a88ec928f1d8d9df2402b.zip
Init
Diffstat (limited to 'static/js/wpaint/src/wPaint.utils.js')
-rw-r--r--static/js/wpaint/src/wPaint.utils.js70
1 files changed, 70 insertions, 0 deletions
diff --git a/static/js/wpaint/src/wPaint.utils.js b/static/js/wpaint/src/wPaint.utils.js
new file mode 100644
index 0000000..7f1346a
--- /dev/null
+++ b/static/js/wpaint/src/wPaint.utils.js
@@ -0,0 +1,70 @@
+(function () {
+ if (!String.prototype.capitalize) {
+ String.prototype.capitalize = function () {
+ return this.slice(0, 1).toUpperCase() + this.slice(1);
+ };
+ }
+})();
+
+(function ($) {
+ $.fn.realWidth = function (type, margin, $el) {
+ var width = null, $div = null, method = null;
+
+ type = type === 'inner' || type === 'outer' ? type : '';
+ method = type === '' ? 'width' : type + 'Width';
+ margin = margin === true ? true : false;
+ $div = $(this).clone().css({position: 'absolute', left: -10000}).appendTo($el || 'body');
+ width = margin ? $div[method](margin) : $div[method]();
+
+ $div.remove();
+
+ return width;
+ };
+
+ $.fn.realHeight = function (type, margin, $el) {
+ var height = null, $div = null, method = null;
+
+ type = type === 'inner' || type === 'outer' ? type : '';
+ method = type === '' ? 'height' : type + 'Height';
+ margin = margin === true ? true : false;
+ $div = $(this).clone().css({position: 'absolute', left: -10000}).appendTo($el || 'body');
+ height = margin ? $div[method](margin) : $div[method]();
+
+ $div.remove();
+
+ return height;
+ };
+
+ $.fn.bindMobileEvents = function () {
+ $(this).on('touchstart touchmove touchend touchcancel', function () {
+ var touches = (event.changedTouches || event.originalEvent.targetTouches),
+ first = touches[0],
+ type = '';
+
+ switch (event.type) {
+ case 'touchstart':
+ type = 'mousedown';
+ break;
+ case 'touchmove':
+ type = 'mousemove';
+ event.preventDefault();
+ break;
+ case 'touchend':
+ type = 'mouseup';
+ break;
+ default:
+ return;
+ }
+
+ var simulatedEvent = document.createEvent('MouseEvent');
+
+ simulatedEvent.initMouseEvent(
+ type, true, true, window, 1,
+ first.screenX, first.screenY, first.clientX, first.clientY,
+ false, false, false, false, 0/*left*/, null
+ );
+
+ first.target.dispatchEvent(simulatedEvent);
+ });
+ };
+})(jQuery); \ No newline at end of file