Add consultation module assets and libraries
This commit is contained in:
@@ -0,0 +1,20 @@
|
||||
(function (factory, define, require, module) {
|
||||
'use strict';
|
||||
|
||||
if (typeof define === 'function' && define.amd) {
|
||||
// AMD
|
||||
define(['jquery'], factory);
|
||||
} else if (typeof module === 'object' && typeof module.exports === 'object') {
|
||||
// CommonJS
|
||||
module.exports = factory(require('jquery'));
|
||||
} else {
|
||||
// Global jQuery
|
||||
factory(jQuery);
|
||||
}
|
||||
}(function ($) {
|
||||
'use strict';
|
||||
|
||||
// rename to avoid conflict with jquery-resizable
|
||||
$.fn.uiresizable = $.fn.resizable;
|
||||
delete $.fn.resizable;
|
||||
}));
|
||||
1
konsultasi/libs/Trumbowyg/plugins/resizimg/resizable-resolveconflict.min.js
vendored
Normal file
1
konsultasi/libs/Trumbowyg/plugins/resizimg/resizable-resolveconflict.min.js
vendored
Normal file
@@ -0,0 +1 @@
|
||||
!function(e,t,o,r){"use strict";"function"==typeof t&&t.amd?t(["jquery"],e):"object"==typeof r&&"object"==typeof r.exports?r.exports=e(o("jquery")):e(jQuery)}(function(e){"use strict";e.fn.uiresizable=e.fn.resizable,delete e.fn.resizable});
|
||||
303
konsultasi/libs/Trumbowyg/plugins/resizimg/trumbowyg.resizimg.js
Normal file
303
konsultasi/libs/Trumbowyg/plugins/resizimg/trumbowyg.resizimg.js
Normal file
@@ -0,0 +1,303 @@
|
||||
;(function ($) {
|
||||
'use strict';
|
||||
|
||||
var defaultOptions = {
|
||||
minSize: 32,
|
||||
step: 4
|
||||
};
|
||||
|
||||
function preventDefault(e) {
|
||||
e.stopPropagation();
|
||||
e.preventDefault();
|
||||
}
|
||||
|
||||
var ResizeWithCanvas = function () {
|
||||
// variable to create canvas and save img in resize mode
|
||||
this.resizeCanvas = document.createElement('canvas');
|
||||
// to allow canvas to get focus
|
||||
this.resizeCanvas.setAttribute('tabindex', '0');
|
||||
this.resizeCanvas.id = 'trumbowyg-resizimg-' + (+new Date());
|
||||
this.ctx = null;
|
||||
this.resizeImg = null;
|
||||
|
||||
this.pressEscape = function (obj) {
|
||||
obj.reset();
|
||||
};
|
||||
this.pressBackspaceOrDelete = function (obj) {
|
||||
$(obj.resizeCanvas).replaceWith('');
|
||||
obj.resizeImg = null;
|
||||
};
|
||||
|
||||
// PRIVATE FUNCTION
|
||||
var focusedNow = false;
|
||||
var isCursorSeResize = false;
|
||||
|
||||
// calculate offset to change mouse over square in the canvas
|
||||
var offsetX, offsetY;
|
||||
var reOffset = function (canvas) {
|
||||
var BB = canvas.getBoundingClientRect();
|
||||
offsetX = BB.left;
|
||||
offsetY = BB.top;
|
||||
};
|
||||
|
||||
var drawRect = function (shapeData, ctx) {
|
||||
// Inner
|
||||
ctx.beginPath();
|
||||
ctx.fillStyle = 'rgb(255, 255, 255)';
|
||||
ctx.rect(shapeData.points.x, shapeData.points.y, shapeData.points.width, shapeData.points.height);
|
||||
ctx.fill();
|
||||
ctx.stroke();
|
||||
};
|
||||
|
||||
var updateCanvas = function (canvas, ctx, img, canvasWidth, canvasHeight) {
|
||||
ctx.translate(0.5, 0.5);
|
||||
ctx.lineWidth = 1;
|
||||
|
||||
// image
|
||||
ctx.drawImage(img, 5, 5, canvasWidth - 10, canvasHeight - 10);
|
||||
|
||||
// border
|
||||
ctx.beginPath();
|
||||
ctx.rect(5, 5, canvasWidth - 10, canvasHeight - 10);
|
||||
ctx.stroke();
|
||||
|
||||
// square in the angle
|
||||
ctx.beginPath();
|
||||
ctx.fillStyle = 'rgb(255, 255, 255)';
|
||||
ctx.rect(canvasWidth - 10, canvasHeight - 10, 9, 9);
|
||||
ctx.fill();
|
||||
ctx.stroke();
|
||||
|
||||
// get the offset to change the mouse cursor
|
||||
reOffset(canvas);
|
||||
|
||||
return ctx;
|
||||
};
|
||||
|
||||
// PUBLIC FUNCTION
|
||||
// necessary to correctly print cursor over square. Called once for instance. Useless with trumbowyg.
|
||||
this.init = function () {
|
||||
var _this = this;
|
||||
$(window).on('scroll resize', function () {
|
||||
_this.reCalcOffset();
|
||||
});
|
||||
};
|
||||
|
||||
this.reCalcOffset = function () {
|
||||
reOffset(this.resizeCanvas);
|
||||
};
|
||||
|
||||
this.canvasId = function () {
|
||||
return this.resizeCanvas.id;
|
||||
};
|
||||
|
||||
this.isActive = function () {
|
||||
return this.resizeImg !== null;
|
||||
};
|
||||
|
||||
this.isFocusedNow = function () {
|
||||
return focusedNow;
|
||||
};
|
||||
|
||||
this.blurNow = function () {
|
||||
focusedNow = false;
|
||||
};
|
||||
|
||||
// restore image in the HTML of the editor
|
||||
this.reset = function () {
|
||||
if (this.resizeImg === null) {
|
||||
return;
|
||||
}
|
||||
|
||||
this.resizeImg.width = this.resizeCanvas.clientWidth - 10;
|
||||
this.resizeImg.height = this.resizeCanvas.clientHeight - 10;
|
||||
// clear style of image to avoid issue on resize because this attribute have priority over width and height attribute
|
||||
this.resizeImg.removeAttribute('style');
|
||||
|
||||
$(this.resizeCanvas).replaceWith($(this.resizeImg));
|
||||
|
||||
// reset canvas style
|
||||
this.resizeCanvas.removeAttribute('style');
|
||||
this.resizeImg = null;
|
||||
};
|
||||
|
||||
// setup canvas with points and border to allow the resizing operation
|
||||
this.setup = function (img, resizableOptions) {
|
||||
this.resizeImg = img;
|
||||
|
||||
if (!this.resizeCanvas.getContext) {
|
||||
return false;
|
||||
}
|
||||
|
||||
focusedNow = true;
|
||||
|
||||
// draw canvas
|
||||
this.resizeCanvas.width = $(this.resizeImg).width() + 10;
|
||||
this.resizeCanvas.height = $(this.resizeImg).height() + 10;
|
||||
this.resizeCanvas.style.margin = '-5px';
|
||||
this.ctx = this.resizeCanvas.getContext('2d');
|
||||
|
||||
// replace image with canvas
|
||||
$(this.resizeImg).replaceWith($(this.resizeCanvas));
|
||||
|
||||
updateCanvas(this.resizeCanvas, this.ctx, this.resizeImg, this.resizeCanvas.width, this.resizeCanvas.height);
|
||||
|
||||
// enable resize
|
||||
$(this.resizeCanvas).resizable(resizableOptions)
|
||||
.on('mousedown', preventDefault);
|
||||
|
||||
var _this = this;
|
||||
$(this.resizeCanvas)
|
||||
.on('mousemove', function (e) {
|
||||
var mouseX = Math.round(e.clientX - offsetX);
|
||||
var mouseY = Math.round(e.clientY - offsetY);
|
||||
|
||||
var wasCursorSeResize = isCursorSeResize;
|
||||
|
||||
_this.ctx.rect(_this.resizeCanvas.width - 10, _this.resizeCanvas.height - 10, 9, 9);
|
||||
isCursorSeResize = _this.ctx.isPointInPath(mouseX, mouseY);
|
||||
if (wasCursorSeResize !== isCursorSeResize) {
|
||||
this.style.cursor = isCursorSeResize ? 'se-resize' : 'default';
|
||||
}
|
||||
})
|
||||
.on('keydown', function (e) {
|
||||
if (!_this.isActive()) {
|
||||
return;
|
||||
}
|
||||
|
||||
var x = e.keyCode;
|
||||
if (x === 27) { // ESC
|
||||
_this.pressEscape(_this);
|
||||
} else if (x === 8 || x === 46) { // BACKSPACE or DELETE
|
||||
_this.pressBackspaceOrDelete(_this);
|
||||
}
|
||||
})
|
||||
.on('focus', preventDefault);
|
||||
|
||||
this.resizeCanvas.focus();
|
||||
|
||||
return true;
|
||||
};
|
||||
|
||||
// update the canvas after the resizing
|
||||
this.refresh = function () {
|
||||
if (!this.resizeCanvas.getContext) {
|
||||
return;
|
||||
}
|
||||
|
||||
this.resizeCanvas.width = this.resizeCanvas.clientWidth;
|
||||
this.resizeCanvas.height = this.resizeCanvas.clientHeight;
|
||||
updateCanvas(this.resizeCanvas, this.ctx, this.resizeImg, this.resizeCanvas.width, this.resizeCanvas.height);
|
||||
};
|
||||
};
|
||||
|
||||
// object to interact with canvas
|
||||
var resizeWithCanvas = new ResizeWithCanvas();
|
||||
|
||||
function destroyResizable(trumbowyg) {
|
||||
// clean html code
|
||||
trumbowyg.$ed.find('canvas.resizable')
|
||||
.resizable('destroy')
|
||||
.off('mousedown', preventDefault)
|
||||
.removeClass('resizable');
|
||||
|
||||
resizeWithCanvas.reset();
|
||||
|
||||
trumbowyg.syncCode();
|
||||
}
|
||||
|
||||
$.extend(true, $.trumbowyg, {
|
||||
plugins: {
|
||||
resizimg: {
|
||||
init: function (trumbowyg) {
|
||||
trumbowyg.o.plugins.resizimg = $.extend(true, {},
|
||||
defaultOptions,
|
||||
trumbowyg.o.plugins.resizimg || {},
|
||||
{
|
||||
resizable: {
|
||||
resizeWidth: false,
|
||||
onDragStart: function (ev, $el) {
|
||||
var opt = trumbowyg.o.plugins.resizimg;
|
||||
var x = ev.pageX - $el.offset().left;
|
||||
var y = ev.pageY - $el.offset().top;
|
||||
if (x < $el.width() - opt.minSize || y < $el.height() - opt.minSize) {
|
||||
return false;
|
||||
}
|
||||
},
|
||||
onDrag: function (ev, $el, newWidth, newHeight) {
|
||||
var opt = trumbowyg.o.plugins.resizimg;
|
||||
if (newHeight < opt.minSize) {
|
||||
newHeight = opt.minSize;
|
||||
}
|
||||
newHeight -= newHeight % opt.step;
|
||||
$el.height(newHeight);
|
||||
return false;
|
||||
},
|
||||
onDragEnd: function () {
|
||||
// resize update canvas information
|
||||
resizeWithCanvas.refresh();
|
||||
trumbowyg.syncCode();
|
||||
}
|
||||
}
|
||||
}
|
||||
);
|
||||
|
||||
function initResizable() {
|
||||
trumbowyg.$ed.find('img')
|
||||
.off('click')
|
||||
.on('click', function (e) {
|
||||
// if I'm already do a resize, reset it
|
||||
if (resizeWithCanvas.isActive()) {
|
||||
resizeWithCanvas.reset();
|
||||
}
|
||||
// initialize resize of image
|
||||
resizeWithCanvas.setup(this, trumbowyg.o.plugins.resizimg.resizable);
|
||||
|
||||
preventDefault(e);
|
||||
});
|
||||
}
|
||||
|
||||
trumbowyg.$c.on('tbwinit', function () {
|
||||
initResizable();
|
||||
|
||||
// disable resize when click on other items
|
||||
trumbowyg.$ed.on('click', function (e) {
|
||||
// check if I've clicked out of canvas or image to reset it
|
||||
if ($(e.target).is('img') || e.target.id === resizeWithCanvas.canvasId()) {
|
||||
return;
|
||||
}
|
||||
|
||||
preventDefault(e);
|
||||
resizeWithCanvas.reset();
|
||||
|
||||
// save changes
|
||||
trumbowyg.$c.trigger('tbwchange');
|
||||
});
|
||||
|
||||
trumbowyg.$ed.on('scroll', function () {
|
||||
resizeWithCanvas.reCalcOffset();
|
||||
});
|
||||
});
|
||||
|
||||
trumbowyg.$c.on('tbwfocus tbwchange', initResizable);
|
||||
trumbowyg.$c.on('tbwresize', function () {
|
||||
resizeWithCanvas.reCalcOffset();
|
||||
});
|
||||
|
||||
// Destroy
|
||||
trumbowyg.$c.on('tbwblur', function () {
|
||||
// if I have already focused the canvas avoid destroy
|
||||
if (resizeWithCanvas.isFocusedNow()) {
|
||||
resizeWithCanvas.blurNow();
|
||||
} else {
|
||||
destroyResizable(trumbowyg);
|
||||
}
|
||||
});
|
||||
},
|
||||
destroy: function (trumbowyg) {
|
||||
destroyResizable(trumbowyg);
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
})(jQuery);
|
||||
1
konsultasi/libs/Trumbowyg/plugins/resizimg/trumbowyg.resizimg.min.js
vendored
Normal file
1
konsultasi/libs/Trumbowyg/plugins/resizimg/trumbowyg.resizimg.min.js
vendored
Normal file
@@ -0,0 +1 @@
|
||||
!function(e){"use strict";function i(e){e.stopPropagation(),e.preventDefault()}function t(e){e.$ed.find("canvas.resizable").resizable("destroy").off("mousedown",i).removeClass("resizable"),r.reset(),e.syncCode()}var s={minSize:32,step:4},n=function(){this.resizeCanvas=document.createElement("canvas"),this.resizeCanvas.setAttribute("tabindex","0"),this.resizeCanvas.id="trumbowyg-resizimg-"+ +new Date,this.ctx=null,this.resizeImg=null,this.pressEscape=function(e){e.reset()},this.pressBackspaceOrDelete=function(i){e(i.resizeCanvas).replaceWith(""),i.resizeImg=null};var t,s,n=!1,r=!1,a=function(e){var i=e.getBoundingClientRect();t=i.left,s=i.top},h=function(e,i,t,s,n){return i.translate(.5,.5),i.lineWidth=1,i.drawImage(t,5,5,s-10,n-10),i.beginPath(),i.rect(5,5,s-10,n-10),i.stroke(),i.beginPath(),i.fillStyle="rgb(255, 255, 255)",i.rect(s-10,n-10,9,9),i.fill(),i.stroke(),a(e),i};this.init=function(){var i=this;e(window).on("scroll resize",function(){i.reCalcOffset()})},this.reCalcOffset=function(){a(this.resizeCanvas)},this.canvasId=function(){return this.resizeCanvas.id},this.isActive=function(){return null!==this.resizeImg},this.isFocusedNow=function(){return n},this.blurNow=function(){n=!1},this.reset=function(){null!==this.resizeImg&&(this.resizeImg.width=this.resizeCanvas.clientWidth-10,this.resizeImg.height=this.resizeCanvas.clientHeight-10,this.resizeImg.removeAttribute("style"),e(this.resizeCanvas).replaceWith(e(this.resizeImg)),this.resizeCanvas.removeAttribute("style"),this.resizeImg=null)},this.setup=function(a,o){if(this.resizeImg=a,!this.resizeCanvas.getContext)return!1;n=!0,this.resizeCanvas.width=e(this.resizeImg).width()+10,this.resizeCanvas.height=e(this.resizeImg).height()+10,this.resizeCanvas.style.margin="-5px",this.ctx=this.resizeCanvas.getContext("2d"),e(this.resizeImg).replaceWith(e(this.resizeCanvas)),h(this.resizeCanvas,this.ctx,this.resizeImg,this.resizeCanvas.width,this.resizeCanvas.height),e(this.resizeCanvas).resizable(o).on("mousedown",i);var c=this;return e(this.resizeCanvas).on("mousemove",function(e){var i=Math.round(e.clientX-t),n=Math.round(e.clientY-s),a=r;c.ctx.rect(c.resizeCanvas.width-10,c.resizeCanvas.height-10,9,9),r=c.ctx.isPointInPath(i,n),a!==r&&(this.style.cursor=r?"se-resize":"default")}).on("keydown",function(e){if(c.isActive()){var i=e.keyCode;27===i?c.pressEscape(c):8!==i&&46!==i||c.pressBackspaceOrDelete(c)}}).on("focus",i),this.resizeCanvas.focus(),!0},this.refresh=function(){this.resizeCanvas.getContext&&(this.resizeCanvas.width=this.resizeCanvas.clientWidth,this.resizeCanvas.height=this.resizeCanvas.clientHeight,h(this.resizeCanvas,this.ctx,this.resizeImg,this.resizeCanvas.width,this.resizeCanvas.height))}},r=new n;e.extend(!0,e.trumbowyg,{plugins:{resizimg:{init:function(n){function a(){n.$ed.find("img").off("click").on("click",function(e){r.isActive()&&r.reset(),r.setup(this,n.o.plugins.resizimg.resizable),i(e)})}n.o.plugins.resizimg=e.extend(!0,{},s,n.o.plugins.resizimg||{},{resizable:{resizeWidth:!1,onDragStart:function(e,i){var t=n.o.plugins.resizimg,s=e.pageX-i.offset().left,r=e.pageY-i.offset().top;if(s<i.width()-t.minSize||r<i.height()-t.minSize)return!1},onDrag:function(e,i,t,s){var r=n.o.plugins.resizimg;return s<r.minSize&&(s=r.minSize),s-=s%r.step,i.height(s),!1},onDragEnd:function(){r.refresh(),n.syncCode()}}}),n.$c.on("tbwinit",function(){a(),n.$ed.on("click",function(t){e(t.target).is("img")||t.target.id===r.canvasId()||(i(t),r.reset(),n.$c.trigger("tbwchange"))}),n.$ed.on("scroll",function(){r.reCalcOffset()})}),n.$c.on("tbwfocus tbwchange",a),n.$c.on("tbwresize",function(){r.reCalcOffset()}),n.$c.on("tbwblur",function(){r.isFocusedNow()?r.blurNow():t(n)})},destroy:function(e){t(e)}}}})}(jQuery);
|
||||
Reference in New Issue
Block a user