window.key = require('keymaster');
window.tippy = tippy;
require('jquery.scrollto');
+require('jquery-contextmenu');
function LinkEditor() {
this.single = ['mobilefirst', 'portrait'].indexOf(FLUIDBOOK_DATA.settings.mobileNavigationType) >= 0;
if (e.keyCode == 32) {
$("#linkeditor-main").addClass('grab');
return false;
+ } else if (e.keyCode == 18) {
+ $("#linkeditor-main").addClass('duplicate');
+ return false;
}
$this.rulers.moveRuler();
});
$(window).on('keyup', function (e) {
if (e.keyCode == 32) {
$this.zoom.resetZoomDrag();
+ }else if(e.keyCode==18){
+ $("#linkeditor-main").removeClass('duplicate');
+ return false;
}
$this.rulers.moveRuler();
});
$(document).on('mousedown', "#linkeditor-main", function (e) {
+ if (key.alt) {
+ $this.links.duplicateLinkClick();
+ return;
+ }
if ($(this).hasClass('grab') && $this.zoom.zoom > 1) {
$this.zoomdragging = {
x: e.pageX,
hasChanged: function () {
this.save.hasChanged();
+ this.updateFBElements(true);
},
updateFBElements: function (force) {
},
_updateFBElements: function (force) {
+ console.log('_updateFBElements');
let $this = this;
let selector = '[fb-ref]';
if (force !== true) {
});
+(function (old) {
+ $.fn.attr = function () {
+ if (arguments.length === 0) {
+ if (this.length === 0) {
+ return null;
+ }
+
+ var obj = {};
+ $.each(this[0].attributes, function () {
+ if (this.specified) {
+ obj[this.name] = this.value;
+ }
+ });
+ return obj;
+ }
+ return old.apply(this, arguments);
+ };
+})($.fn.attr);
this.magnetValuesX = [];
this.magnetValuesY = [];
+ this.lastSelectedLink = null;
+ this.lastSelectedLinkData = {'width': 100, 'height': 100, 'to': '', type: '2', target: '_blank'};
+
this.init();
}
key('ctrl+down', function () {
$this.offsetSelectedLinks('top', 10);
});
+
+ setInterval(function () {
+ $this.checkLastSelectedLink();
+ }, 250);
},
mouseUp: function () {
}
$(l).addClass('selected');
this.currentSelection.push(l);
+ this.lastSelectedLink = l;
+ },
+
+ checkLastSelectedLink: function () {
+ if (this.lastSelectedLink === null || $(this.lastSelectedLink).length === 0) {
+ return;
+ }
+ this.lastSelectedLinkData = this.getLinkData(this.lastSelectedLink);
},
+ getLinkData: function (l) {
+ var res = {};
+ var attributes = $(l).attr();
+ var skip = ['fb-ref', 'fb-update'];
+ for (var key in attributes) {
+ if (key.indexOf('fb-') !== 0 || skip.indexOf(key) >= 0) {
+ continue;
+ }
+ res[key.substring(3)] = attributes[key];
+ }
+ return res;
+ },
deselectAllLinks: function () {
this.currentSelection = [];
addLink: function (link) {
let $this = this;
+ let change = false;
if (link.uid === undefined) {
- link.uid = generateUID();
+ link.uid = this.linkeditor.utils.generateUID();
LINKS[link.uid] = link;
- this.linkeditor.rulers.updateRulersMagnetValues();
- this.linkeditor.hasChanged();
+ change = true;
}
let attrs = {};
$.each(link, function (k, v) {
- if ($this.linkeditor.dimensionProperties.indexOf(k) >= 0) {
- attrs['fb-' + k] = v;
- } else {
- attrs['data-' + k] = v;
- }
+ attrs['fb-' + k] = v;
});
+ attrs['fb-ref']="editor";
+ attrs['fb-update']="1";
let e = $('<div class="link" fb-ref="editor" fb-update="1"></div>');
$(e).attr(attrs);
$("#linkeditor-links").append(e);
+ if (change) {
+ this.linkeditor.rulers.updateRulersMagnetValues();
+ this.linkeditor.hasChanged();
+ }
+ return e;
},
updateMagnetValues: function () {
});
},
+ duplicateLinkClick: function () {
+ var data = this.lastSelectedLinkData;
+ var pos = this.linkeditor.globalToFluidbook(this.linkeditor.mx, this.linkeditor.my, this.linkeditor.single);
+ data.left = pos.x;
+ data.top = pos.y;
+ data.page = this.linkeditor.currentPage;
+ delete data.uid;
+ let link = this.addLink(data);
+ this.deselectAllLinks();
+ this.selectLink($(link));
+ },
+
deleteSelection: function () {
$(".link.selected").each(function () {
delete LINKS[$(this).data('uid')];
$("#linkeditor-links").html('');
},
};
+
module.exports = LinkeditorLinks;
<div class="ruler-bar" id="linkeditor-ruler-x"></div>
<div class="ruler-bar" id="linkeditor-ruler-y"></div>
</div>
+ <div draggable="false" id="linkeditor-duplicatelink-overlay"></div>
<div draggable="false" id="linkeditor-canvas">
<div draggable="false" id="linkeditor-zoom">
<div draggable="false" id="linkeditor-fluidbook">
@push('after_styles')
<style>
@foreach(\App\SubForms\Link\Base::types() as $type)
- .link[data-type="{{$type['type']}}"] {
+ .link[fb-type="{{$type['type']}}"] {
color: {{$type['color']}};
background-color: {{\Cubist\Util\Graphics\Color::colorToCSS($type['color'],0.25)}};
}