;(function ( $, window, document, undefined ) { // VARIABLES var selected_drawable; var canvas; var active_object; var drawables = new Array(); //预览默认大小 var canvas_defaults = { frameWidth : 640, frameHeight : 480, maxZoom : "auto", navigator : false, navigatorImagePreview : false, fullscreen : false } var annotation_defaults = { tint_color : "#000000",//tint_color : "#000000", style : 4, popup_width : "auto", popup_height : "auto", popup_position : "right",//top content_type : "text", // or "custom-html" title : "标题", text : "内容", text_color : "#ffffff", html : "", id : "my-annotation-", spot_sys_eqp_type_id : "",//自定义属性 add by luther.zhang 20150721 spot_left : 0, spot_top : 0, spot_width : 44, spot_height : 44, spot_circle : true }; // CLASSES function NDD_Drawable_Canvas(obj, width, height, cb) { this.obj = $(obj); this.obj_img = undefined; this.img = new Image(); this.width = width; this.height = height; this.obj_drawables_container = this.obj.find('.ndd-drawables-container'); this.is_drawing = false; this.obj_temp = undefined; this.event_initial_x = 0; this.event_initial_y = 0; this.temp_pos_x = 0; this.temp_pos_y = 0; this.temp_width = 0; this.temp_height = 0; this.settings = $.extend({}, canvas_defaults); // events this.init(cb); } NDD_Drawable_Canvas.prototype = { init : function(cb) { var self = this; canvas = self; self.obj_img = self.obj.find('img'); if (self.width != 0 && self.height != 0) { self.obj.css({ width : self.width, height : self.height }); self.img.src = self.obj_img.attr('src'); cb(); } else { self.img.onload = function() { self.width = self.img.width; self.height = self.img.height; if (self.width > $('#panel-canvas').width()) { var scale = self.width / $('#panel-canvas').width(); self.width = $('#panel-canvas').width(); self.height = self.height / scale; } if (self.height > $('#panel-canvas').height()) { var scale = self.height / $('#panel-canvas').height(); self.height = $('#panel-canvas').height(); self.width = self.width / scale; } self.obj.css({ width : self.width, height : self.height }); cb(); } self.img.src = self.obj_img.attr('src'); } }, handle_event : function(e) { var self = this; if (e.type == "mousedown") { } if (e.type == "mousemove") { if (!self.is_drawing) { self.is_drawing = true; self.start_drawing(e.pageX, e.pageY); } if (self.is_drawing) { self.draw(e.pageX, e.pageY); } } if (e.type == "mouseup") { if (self.is_drawing) { self.is_drawing = false; self.stop_drawing(); } else if ($(e.target).hasClass('ndd-drawable-canvas') || $(e.target).hasClass('ndd-drawable-canvas-image')) { var x = e.pageX - self.obj.offset().left; var y = e.pageY - self.obj.offset().top; self.create_circle_spot(x, y); } } }, start_drawing : function(pageX, pageY) { var self = this; self.obj_drawables_container.append('
'+ self.text +'
'); }, show : function() { var self = this; self.obj.addClass('ndd-annotation-visible'); self.is_visible = true; if (!self.initialized_dimentions) { self.initialize_dimentions(); } }, hide : function() { var self = this; self.is_visible = false; self.obj.removeClass('ndd-annotation-visible'); }, initialize_dimentions : function() { var self = this; if (self.width == "auto") { self.obj_box.css({ width : "auto" }); self.width = self.obj_box.width(); } else { self.obj_box.css({ width : self.width }); } if (self.height == "auto") { self.obj_box.css({ height : "auto" }); self.height = self.obj_box.height(); } else { self.obj_box.css({ height : self.height }); } if (self.drawable.settings.popup_position == "top") { self.left = -self.width/2 + self.drawable.width/2; self.top = -self.height - 20; if (self.drawable.settings.style != 1 && self.drawable.settings.style != 2 && self.drawable.settings.style != 3 && self.drawable.settings.style != 4) { self.top -= 20; } self.obj_arrow.removeClass('ndd-annotation-arrow-up'); self.obj_arrow.removeClass('ndd-annotation-arrow-left'); self.obj_arrow.removeClass('ndd-annotation-arrow-right'); self.obj_arrow.addClass('ndd-annotation-arrow-down'); self.obj_arrow.css({ left : self.width/2 - 10, top : "100%" }); } if (self.drawable.settings.popup_position == "bottom") { self.left = -self.width/2 + self.drawable.width/2; self.top = self.drawable.height + 20; self.obj_arrow.removeClass('ndd-annotation-arrow-down'); self.obj_arrow.removeClass('ndd-annotation-arrow-left'); self.obj_arrow.removeClass('ndd-annotation-arrow-right'); self.obj_arrow.addClass('ndd-annotation-arrow-up'); self.obj_arrow.css({ left : self.width/2 - 10, top : -10 }); } if (self.drawable.settings.popup_position == "left") { self.left = -self.width - 20; self.top = -self.height/2 + self.drawable.height/2; self.obj_arrow.removeClass('ndd-annotation-arrow-down'); self.obj_arrow.removeClass('ndd-annotation-arrow-left'); self.obj_arrow.removeClass('ndd-annotation-arrow-up'); self.obj_arrow.addClass('ndd-annotation-arrow-right'); self.obj_arrow.css({ left : "100%", top : self.height/2 - 10 }); } if (self.drawable.settings.popup_position == "right") { self.left = self.drawable.width + 20; self.top = -self.height/2 + self.drawable.height/2; self.obj_arrow.removeClass('ndd-annotation-arrow-down'); self.obj_arrow.removeClass('ndd-annotation-arrow-right'); self.obj_arrow.removeClass('ndd-annotation-arrow-up'); self.obj_arrow.addClass('ndd-annotation-arrow-left'); self.obj_arrow.css({ left : -10, top : self.height/2 - 10 }); } self.obj.css({ left : self.left, top : self.top }); }, apply_settings : function(new_settings) { var self = this; // tint color self.obj_box.css({ "background-color" : new_settings.tint_color }); // width self.width = new_settings.popup_width; // height self.height = new_settings.popup_height; // popup position if (new_settings.popup_position == "top") { self.obj_arrow.css({ "border-color" : 'transparent', "border-top-color" : new_settings.tint_color }); } if (new_settings.popup_position == "bottom") { self.obj_arrow.css({ "border-color" : 'transparent', "border-bottom-color" : new_settings.tint_color }); } if (new_settings.popup_position == "left") { self.obj_arrow.css({ "border-color" : 'transparent', "border-left-color" : new_settings.tint_color }); } if (new_settings.popup_position == "right") { self.obj_arrow.css({ "border-color" : 'transparent', "border-right-color" : new_settings.tint_color }); } // content self.title = new_settings.title; self.text = new_settings.text; self.html = new_settings.html; self.content_type = new_settings.content_type; if (self.content_type == "text") { self.obj_content.html(''+ self.text +'
'); } else { self.obj_content.html(self.html); } // text color self.obj_content.css({ color : new_settings.text_color }); self.obj_content.find('h1').css({ color : new_settings.text_color }); self.obj_content.find('p').css({ color : new_settings.text_color }); if (self.is_visible) { self.initialize_dimentions(); } else { self.initialized_dimentions = false; } } }; // FUNCTIONS function init_canvas(width, height, cb) { var tmp = new NDD_Drawable_Canvas($('.ndd-drawable-canvas'), width, height, function() { cb(); }); } function init_global_events() { $(document).on('mousedown', function(e) { active_object = undefined; if ($(e.target).hasClass('ndd-drawable-canvas') || $(e.target).hasClass('ndd-drawable-canvas-image')) { e.preventDefault(); active_object = canvas; active_object.handle_event(e); return false; } if ($(e.target).hasClass('ndd-drawable-active-area')) { e.preventDefault(); active_object = drawables[$(e.target).parent().attr('id')]; active_object.handle_event(e); return false; } if ($(e.target).hasClass('ndd-drawable-rect-handle')) { e.preventDefault(); active_object = drawables[$(e.target).closest('.ndd-drawable-rect').attr('id')]; active_object.handle_event(e); return false; } }); $(document).on('mousemove', function(e) { if (active_object != undefined) { e.preventDefault(); active_object.handle_event(e); return false; } }); $(document).on('mouseup', function(e) { if (active_object != undefined) { active_object.handle_event(e); } //console.info("in"); active_object = undefined; }); } function form_events() { $('form input, form button, form textarea').on('change', function() { refresh_form(); validate_form(function(success) { if (success) { apply_settings(); generate_jquery(); if ($('#radio-editor-mode-preview-label').hasClass('active')) { generate_preview(); } } }); }); $(document).on('keyup', function(e) { if (e.keyCode == 46 && selected_drawable != undefined) { $('#modal-delete').modal(); } }); $('#delete-annotation-button').on('click', function() { if (selected_drawable != undefined) { selected_drawable.obj.remove(); drawables[selected_drawable.id] = undefined; selected_drawable = undefined; refresh_form(); generate_jquery(); if ($('#radio-editor-mode-preview-label').hasClass('active')) { generate_preview(); } } }); $('#radio-editor-mode-jquery-label').on('click', function() { generate_jquery(); }); //点击保存方法 $('#radio-editor-mode-save-label').on('click', function() { apply_settings(); generate_jquery(); var result = $('#well-jquery').text(); if(result.length==35){//如果不设置,默认的长度是 35 alert("请先选择图片区域"); }else{ //alert(result); var url = $('#contextPath').val()+"/pms/sys/eqptype/setUpImage.do"; //保存到后台 var filePath = $('#filePath').val();//图片 上传路径 //alert(filePath); $.post(url,{id :$('#twoRowId').val(),result:result,filePath:filePath}, function(json) { if (json.success) { alert(json.msg); window.opener.queryMdType();//调用父窗口方法 }else{ alert(json.msg); } },'JSON'); } }); $('#radio-editor-mode-preview-label').on('mouseup', function() { setTimeout(function() { generate_preview(); }, 30); }); $('#button-select-jquery').on('click', function() { selectText('well-jquery'); }); $('#textarea-load').on('change', function() { $('#button-load').removeClass('btn-success').removeClass('btn-danger').addClass('btn-primary'); $('#button-load').html('Load'); if ($(this).val().length > 0) { $('#button-load').removeAttr('disabled'); } else { $('#button-load').attr('disabled', 'disabled'); } }); $('#textarea-load').on('keyup', function() { $('#button-load').removeClass('btn-success').removeClass('btn-danger').addClass('btn-primary'); $('#button-load').html('Load'); if ($(this).val().length > 0) { $('#button-load').removeAttr('disabled'); } else { $('#button-load').attr('disabled', 'disabled'); } }); $('#button-load').on('click', function() { if (load_jquery($('#textarea-load').val())) { $(this).removeClass('btn-primary').addClass('btn-success').attr('disabled', 'disabled'); $(this).html(' Success'); } else { $(this).removeClass('btn-primary').addClass('btn-danger').attr('disabled', 'disabled'); $(this).html(' Error'); } }); } function refresh_form() { if ($('#radio-editor-mode-edit').get(0).checked) { $('#panel-editor').show(); $('#panel-preview').hide(); $('#panel-jquery').hide(); $('#panel-load').hide(); } if ($('#radio-editor-mode-preview').get(0).checked) { $('#panel-editor').hide(); $('#panel-preview').show(); $('#panel-jquery').hide(); $('#panel-load').hide(); } if ($('#radio-editor-mode-jquery').get(0).checked) { $('#panel-editor').hide(); $('#panel-preview').hide(); $('#panel-jquery').show(); $('#panel-load').hide(); } if ($('#radio-editor-mode-load').get(0).checked) { $('#panel-editor').hide(); $('#panel-preview').hide(); $('#panel-jquery').hide(); $('#panel-load').show(); } $('#color-tint-color-hex').html($('#color-tint-color').val()); if ($('#checkbox-popup-width-auto').get(0).checked) { $('#input-popup-width').attr('disabled', 'disabled'); $('#input-popup-width').val('100'); $('#input-popup-width-addon').html('%'); } else { $('#input-popup-width').removeAttr('disabled'); $('#input-popup-width-addon').html('px'); } if ($('#checkbox-popup-height-auto').get(0).checked) { $('#input-popup-height').attr('disabled', 'disabled'); $('#input-popup-height').val('100'); $('#input-popup-height-addon').html('%'); } else { $('#input-popup-height').removeAttr('disabled'); $('#input-popup-height-addon').html('px'); } if ($('#radio-content-type-text').get(0).checked) { $('#input-title').removeAttr('disabled'); $('#textarea-text').removeAttr('disabled'); $('#color-text-color').removeAttr('disabled'); $('#textarea-html').attr('disabled', 'disabled'); } $('#color-text-color-hex').html($('#color-text-color').val()); if ($('#radio-content-type-custom-html').get(0).checked) { $('#input-title').attr('disabled', 'disabled'); $('#textarea-text').attr('disabled', 'disabled'); $('#color-text-color').attr('disabled', 'disabled'); $('#textarea-html').removeAttr('disabled'); } if ($('#input-id').val().length > 0) { $('#input-deep-link-url').html('#/ndd_ann/' + $('#input-id').val() + '/'); $('#input-deep-link-url-help').html('Example:' + escapeHTML('') + '');
} else {
$('#input-deep-link-url').html('');
$('#input-deep-link-url-help').html('');
}
// Icon styles
if (selected_drawable != undefined) {
if (selected_drawable.is_rect) {
$('#btn-group-style-rect').show();
$('#btn-group-style-circle').hide();
} else {
$('#btn-group-style-rect').hide();
$('#btn-group-style-circle').show();
}
}
// Navigation
if ($('#checkbox-width-auto').get(0).checked) {
$('#input-width').attr('disabled', 'disabled');
$('#input-width').val('100');
$('#input-width-addon').html('%');
} else {
$('#input-width').removeAttr('disabled');
$('#input-width-addon').html('px');
}
// $('#input-height-addon').html('px');
// }
if ($('#radio-max-zoom-custom').get(0).checked) {
$('#input-max-zoom').removeAttr('disabled');
} else {
$('#input-max-zoom').attr('disabled', 'disabled');
}
if (selected_drawable == undefined) {
disable_form();
} else {
enable_form();
}
}
function validate_form(cb) {
var int_regex = /\D+/; // any number of non-digit characters
var success = true;
// Popup Width
$('#input-popup-width').val($('#input-popup-width').val().trim());
if ($('#input-popup-width').val().match(int_regex) && $('#input-popup-width').val().length > 0) {
$('#input-popup-width').parent().addClass('has-error');
success = false;
} else {
$('#input-popup-width').parent().removeClass('has-error');
}
// Popup Height
$('#input-popup-height').val($('#input-popup-height').val().trim());
if ($('#input-popup-height').val().match(int_regex) && $('#input-popup-height').val().length > 0) {
$('#input-popup-height').parent().addClass('has-error');
success = false;
} else {
$('#input-popup-height').parent().removeClass('has-error');
}
// Width
$('#input-width').val($('#input-width').val().trim());
if ($('#input-width').val().match(int_regex) && $('#input-width').val().length > 0) {
$('#input-width').parent().addClass('has-error');
success = false;
} else {
$('#input-width').parent().removeClass('has-error');
}
// Height
$('#input-height').val($('#input-height').val().trim());
if ($('#input-height').val().match(int_regex) && $('#input-height').val().length > 0) {
$('#input-height').parent().addClass('has-error');
success = false;
} else {
$('#input-height').parent().removeClass('has-error');
}
// Max Zoom
$('#input-max-zoom').val($('#input-max-zoom').val().trim());
if ($('#input-max-zoom').val().match(int_regex) && $('#input-max-zoom').val().length > 0) {
$('#input-max-zoom').parent().addClass('has-error');
success = false;
} else {
$('#input-max-zoom').parent().removeClass('has-error');
}
// ID
$('#input-id').val($('#input-id').val().trim());
cb(success);
}
function load_settings(settings) {
// Tint Color
$('#color-tint-color').val(settings.tint_color);
// Style
if (selected_drawable != undefined) {
if (selected_drawable.is_rect) {
if (settings.style == 1) {
$('#radio-popup-style-rect-1').prop('checked', true).parent().addClass('active');
$('[id*="radio-popup-style-rect-"]').not($('#radio-popup-style-rect-1')).removeAttr('checked').prop('checked', false).parent().removeClass('active');
}
if (settings.style == 2) {
$('#radio-popup-style-rect-2').prop('checked', true).parent().addClass('active');
$('[id*="radio-popup-style-rect-"]').not($('#radio-popup-style-rect-2')).removeAttr('checked').prop('checked', false).parent().removeClass('active');
}
if (settings.style == 3) {
$('#radio-popup-style-rect-3').prop('checked', true).parent().addClass('active');
$('[id*="radio-popup-style-rect-"]').not($('#radio-popup-style-rect-3')).removeAttr('checked').prop('checked', false).parent().removeClass('active');
}
if (settings.style == 4) {
$('#radio-popup-style-rect-4').prop('checked', true).parent().addClass('active');
$('[id*="radio-popup-style-rect-"]').not($('#radio-popup-style-rect-4')).removeAttr('checked').prop('checked', false).parent().removeClass('active');
}
} else {
if (settings.style == 1) {
$('#radio-popup-style-1').prop('checked', true).parent().addClass('active');
$('[id*="radio-popup-style-"]').not($('#radio-popup-style-1')).removeAttr('checked').prop('checked', false).parent().removeClass('active');
}
if (settings.style == 2) {
$('#radio-popup-style-2').prop('checked', true).parent().addClass('active');
$('[id*="radio-popup-style-"]').not($('#radio-popup-style-2')).removeAttr('checked').prop('checked', false).parent().removeClass('active');
}
if (settings.style == 3) {
$('#radio-popup-style-3').prop('checked', true).parent().addClass('active');
$('[id*="radio-popup-style-"]').not($('#radio-popup-style-3')).removeAttr('checked').prop('checked', false).parent().removeClass('active');
}
if (settings.style == 4) {
$('#radio-popup-style-4').prop('checked', true).parent().addClass('active');
$('[id*="radio-popup-style-"]').not($('#radio-popup-style-4')).removeAttr('checked').prop('checked', false).parent().removeClass('active');
}
/*
if (settings.style == 5) {
$('#radio-popup-style-5').prop('checked', true).parent().addClass('active');
$('[id*="radio-popup-style-"]').not($('#radio-popup-style-5')).removeAttr('checked').prop('checked', false).parent().removeClass('active');
}
if (settings.style == 6) {
$('#radio-popup-style-6').prop('checked', true).parent().addClass('active');
$('[id*="radio-popup-style-"]').not($('#radio-popup-style-6')).removeAttr('checked').prop('checked', false).parent().removeClass('active');
}
if (settings.style == 7) {
$('#radio-popup-style-7').prop('checked', true).parent().addClass('active');
$('[id*="radio-popup-style-"]').not($('#radio-popup-style-7')).removeAttr('checked').prop('checked', false).parent().removeClass('active');
}
if (settings.style == 8) {
$('#radio-popup-style-8').prop('checked', true).parent().addClass('active');
$('[id*="radio-popup-style-"]').not($('#radio-popup-style-8')).removeAttr('checked').prop('checked', false).parent().removeClass('active');
}
if (settings.style == 9) {
$('#radio-popup-style-9').prop('checked', true).parent().addClass('active');
$('[id*="radio-popup-style-"]').not($('#radio-popup-style-9')).removeAttr('checked').prop('checked', false).parent().removeClass('active');
}
if (settings.style == 10) {
$('#radio-popup-style-10').prop('checked', true).parent().addClass('active');
$('[id*="radio-popup-style-"]').not($('#radio-popup-style-10')).removeAttr('checked').prop('checked', false).parent().removeClass('active');
}
if (settings.style == 11) {
$('#radio-popup-style-11').prop('checked', true).parent().addClass('active');
$('[id*="radio-popup-style-"]').not($('#radio-popup-style-11')).removeAttr('checked').prop('checked', false).parent().removeClass('active');
}
if (settings.style == 12) {
$('#radio-popup-style-12').prop('checked', true).parent().addClass('active');
$('[id*="radio-popup-style-"]').not($('#radio-popup-style-12')).removeAttr('checked').prop('checked', false).parent().removeClass('active');
}
if (settings.style == 13) {
$('#radio-popup-style-13').prop('checked', true).parent().addClass('active');
$('[id*="radio-popup-style-"]').not($('#radio-popup-style-13')).removeAttr('checked').prop('checked', false).parent().removeClass('active');
}**/
}
}
// Popup width
if (settings.popup_width == "auto") {
$('#checkbox-popup-width-auto').get(0).checked = true;
} else {
$('#checkbox-popup-width-auto').get(0).checked = false;
$('#input-popup-width').val(settings.popup_width);
}
// Popup height
if (settings.popup_height == "auto") {
$('#checkbox-popup-height-auto').get(0).checked = true;
} else {
$('#checkbox-popup-height-auto').get(0).checked = false;
$('#input-popup-height').val(settings.popup_height);
}
// Popup position
if (settings.popup_position == "top") {
$('#radio-popup-position-top').parent().addClass('active');
$('#radio-popup-position-top').get(0).checked = true;
$('#radio-popup-position-bottom').removeAttr('checked').parent().removeClass('active');
$('#radio-popup-position-left').removeAttr('checked').parent().removeClass('active');
$('#radio-popup-position-right').removeAttr('checked').parent().removeClass('active');
}
if (settings.popup_position == "bottom") {
$('#radio-popup-position-top').removeAttr('checked').parent().removeClass('active');
$('#radio-popup-position-bottom').parent().addClass('active');
$('#radio-popup-position-bottom').get(0).checked = true;
$('#radio-popup-position-left').removeAttr('checked').parent().removeClass('active');
$('#radio-popup-position-right').removeAttr('checked').parent().removeClass('active');
}
if (settings.popup_position == "left") {
$('#radio-popup-position-top').removeAttr('checked').parent().removeClass('active');
$('#radio-popup-position-bottom').removeAttr('checked').parent().removeClass('active');
$('#radio-popup-position-left').parent().addClass('active');
$('#radio-popup-position-left').get(0).checked = true;
$('#radio-popup-position-right').removeAttr('checked').parent().removeClass('active');
}
if (settings.popup_position == "right") {
$('#radio-popup-position-top').removeAttr('checked').parent().removeClass('active');
$('#radio-popup-position-bottom').removeAttr('checked').parent().removeClass('active');
$('#radio-popup-position-left').removeAttr('checked').parent().removeClass('active');
$('#radio-popup-position-right').parent().addClass('active');
$('#radio-popup-position-right').get(0).checked = true;
}
// Content type
if (settings.content_type == "text") {
$('#radio-content-type-text').parent().addClass('active');
$('#radio-content-type-text').get(0).checked = true;
$('#radio-content-type-custom-html').removeAttr('checked').parent().removeClass('active');
}
if (settings.content_type == "custom-html") {
$('#radio-content-type-text').removeAttr('checked').parent().removeClass('active');
$('#radio-content-type-custom-html').parent().addClass('active');
$('#radio-content-type-custom-html').get(0).checked = true;
}
// Title
$('#input-title').val(settings.title);
// Text
$('#textarea-text').val(settings.text);
// Text color
$('#color-text-color').val(settings.text_color);
// HTML
$('#textarea-html').val(settings.html);
// ID
$('#input-id').val(settings.id);
// ==================== CANVAS
// width
if (canvas.settings.frameWidth == "auto") {
$('#checkbox-width-auto').get(0).checked = true;
$('#checkbox-width-auto').parent().addClass('active');
} else {
$('#input-width').val(canvas.settings.frameWidth);
$('#checkbox-width-auto').get(0).checked = false;
$('#checkbox-width-auto').parent().removeClass('active');
}
// height
$('#input-height').val(canvas.settings.frameHeight);
// max zoom
if (canvas.settings.maxZoom == "auto") {
$('#radio-max-zoom-1-1').get(0).checked = true;
$('#radio-max-zoom-1-1').parent().addClass('active');
$('#radio-max-zoom-1').removeAttr('checked').parent().removeClass('active');
$('#radio-max-zoom-2').removeAttr('checked').parent().removeClass('active');
$('#radio-max-zoom-3').removeAttr('checked').parent().removeClass('active');
$('#radio-max-zoom-4').removeAttr('checked').parent().removeClass('active');
$('#radio-max-zoom-custom').removeAttr('checked').parent().removeClass('active');
} else if (canvas.settings.maxZoom == 1) {
$('#radio-max-zoom-1').get(0).checked = true;
$('#radio-max-zoom-1').parent().addClass('active');
$('#radio-max-zoom-1-1').removeAttr('checked').parent().removeClass('active');
$('#radio-max-zoom-2').removeAttr('checked').parent().removeClass('active');
$('#radio-max-zoom-3').removeAttr('checked').parent().removeClass('active');
$('#radio-max-zoom-4').removeAttr('checked').parent().removeClass('active');
$('#radio-max-zoom-custom').removeAttr('checked').parent().removeClass('active');
} else if (canvas.settings.maxZoom == 2) {
$('#radio-max-zoom-2').get(0).checked = true;
$('#radio-max-zoom-2').parent().addClass('active');
$('#radio-max-zoom-1-1').removeAttr('checked').parent().removeClass('active');
$('#radio-max-zoom-1').removeAttr('checked').parent().removeClass('active');
$('#radio-max-zoom-3').removeAttr('checked').parent().removeClass('active');
$('#radio-max-zoom-4').removeAttr('checked').parent().removeClass('active');
$('#radio-max-zoom-custom').removeAttr('checked').parent().removeClass('active');
} else if (canvas.settings.maxZoom == 3) {
$('#radio-max-zoom-3').get(0).checked = true;
$('#radio-max-zoom-3').parent().addClass('active');
$('#radio-max-zoom-1-1').removeAttr('checked').parent().removeClass('active');
$('#radio-max-zoom-1').removeAttr('checked').parent().removeClass('active');
$('#radio-max-zoom-2').removeAttr('checked').parent().removeClass('active');
$('#radio-max-zoom-4').removeAttr('checked').parent().removeClass('active');
$('#radio-max-zoom-custom').removeAttr('checked').parent().removeClass('active');
} else if (canvas.settings.maxZoom == 4) {
$('#radio-max-zoom-4').get(0).checked = true;
$('#radio-max-zoom-4').parent().addClass('active');
$('#radio-max-zoom-1-1').removeAttr('checked').parent().removeClass('active');
$('#radio-max-zoom-1').removeAttr('checked').parent().removeClass('active');
$('#radio-max-zoom-2').removeAttr('checked').parent().removeClass('active');
$('#radio-max-zoom-3').removeAttr('checked').parent().removeClass('active');
$('#radio-max-zoom-custom').removeAttr('checked').parent().removeClass('active');
} else {
$('#radio-max-zoom-custom').get(0).checked = true;
$('#radio-max-zoom-custom').parent().addClass('active');
$('#input-max-zoom').val(canvas.settings.maxZoom);
$('#radio-max-zoom-1-1').removeAttr('checked').parent().removeClass('active');
$('#radio-max-zoom-1').removeAttr('checked').parent().removeClass('active');
$('#radio-max-zoom-2').removeAttr('checked').parent().removeClass('active');
$('#radio-max-zoom-3').removeAttr('checked').parent().removeClass('active');
$('#radio-max-zoom-4').removeAttr('checked').parent().removeClass('active');
}
// navigator
if (canvas.settings.navigator) {
$('#checkbox-navigator').get(0).checked = true;
$('#checkbox-navigator').parent().addClass('active');
} else {
$('#checkbox-navigator').get(0).checked = false;
$('#checkbox-navigator').parent().removeClass('active');
}
// navigator image preview
if (canvas.settings.navigatorImagePreview) {
$('#checkbox-navigator-image-preview').get(0).checked = true;
$('#checkbox-navigator-image-preview').parent().addClass('active');
} else {
$('#checkbox-navigator-image-preview').get(0).checked = false;
$('#checkbox-navigator-image-preview').parent().removeClass('active');
}
// fullscreen
if (canvas.settings.fullscreen) {
$('#checkbox-fullscreen').get(0).checked = true;
$('#checkbox-fullscreen').parent().addClass('active');
} else {
$('#checkbox-fullscreen').get(0).checked = false;
$('#checkbox-fullscreen').parent().removeClass('active');
}
refresh_form();
}
function apply_settings() {
if (selected_drawable != undefined) {
var current_settings = selected_drawable.settings;
// Tint Color
current_settings.tint_color = $('#color-tint-color').val();
if (selected_drawable != undefined) {
if (selected_drawable.is_rect) {
// Popup style
if ($('#radio-popup-style-rect-0').get(0).checked) {
current_settings.style = 0;
}
if ($('#radio-popup-style-rect-1').get(0).checked) {
current_settings.style = 1;
}
if ($('#radio-popup-style-rect-2').get(0).checked) {
current_settings.style = 2;
}
if ($('#radio-popup-style-rect-3').get(0).checked) {
current_settings.style = 3;
}
if ($('#radio-popup-style-rect-4').get(0).checked) {
current_settings.style = 4;
}
} else {
if ($('#radio-popup-style-0').get(0).checked) {
current_settings.style = 0;
}
if ($('#radio-popup-style-1').get(0).checked) {
current_settings.style = 1;
}
if ($('#radio-popup-style-2').get(0).checked) {
current_settings.style = 2;
}
if ($('#radio-popup-style-3').get(0).checked) {
current_settings.style = 3;
}
if ($('#radio-popup-style-4').get(0).checked) {
current_settings.style = 4;
}
/**
if ($('#radio-popup-style-5').get(0).checked) {
current_settings.style = 5;
}
if ($('#radio-popup-style-6').get(0).checked) {
current_settings.style = 6;
}
if ($('#radio-popup-style-7').get(0).checked) {
current_settings.style = 7;
}
if ($('#radio-popup-style-8').get(0).checked) {
current_settings.style = 8;
}
if ($('#radio-popup-style-9').get(0).checked) {
current_settings.style = 9;
}
if ($('#radio-popup-style-10').get(0).checked) {
current_settings.style = 10;
}
if ($('#radio-popup-style-11').get(0).checked) {
current_settings.style = 11;
}
if ($('#radio-popup-style-12').get(0).checked) {
current_settings.style = 12;
}
if ($('#radio-popup-style-13').get(0).checked) {
current_settings.style = 13;
}*/
}
}
// Popup width
if ($('#checkbox-popup-width-auto').get(0).checked) {
current_settings.popup_width = "auto";
} else {
current_settings.popup_width = $('#input-popup-width').val();
}
// Popup height
if ($('#checkbox-popup-height-auto').get(0).checked) {
current_settings.popup_height = "auto";
} else {
current_settings.popup_height = $('#input-popup-height').val();
}
// Popup position
if ($('#radio-popup-position-top').get(0).checked) {
current_settings.popup_position = "top";
}
if ($('#radio-popup-position-bottom').get(0).checked) {
current_settings.popup_position = "bottom";
}
if ($('#radio-popup-position-left').get(0).checked) {
current_settings.popup_position = "left";
}
if ($('#radio-popup-position-right').get(0).checked) {
current_settings.popup_position = "right";
}
// Content type
if ($('#radio-content-type-text').get(0).checked) {
current_settings.content_type = "text";
}
if ($('#radio-content-type-custom-html').get(0).checked) {
current_settings.content_type = "custom-html";
}
// Title
current_settings.title = $('#input-title').val();
// Text
current_settings.text = $('#textarea-text').val();
// Text color
current_settings.text_color = $('#color-text-color').val();
// HTML
current_settings.html = $('#textarea-html').val();
// ID
current_settings.id = $('#input-id').val();
selected_drawable.apply_settings(current_settings);
selected_drawable.annotation.apply_settings(current_settings);
}
if (canvas != undefined) {
var current_canvas_settings = canvas.settings;
// width
if ($('#checkbox-width-auto').get(0).checked) {
current_canvas_settings.frameWidth = "auto";
} else {
current_canvas_settings.frameWidth = $('#input-width').val();
}
// height
current_canvas_settings.frameHeight = $('#input-height').val();
// max zoom
if ($('#radio-max-zoom-1-1').get(0).checked) {
current_canvas_settings.maxZoom = "auto";
}
if ($('#radio-max-zoom-1').get(0).checked) {
current_canvas_settings.maxZoom = 1;
}
if ($('#radio-max-zoom-2').get(0).checked) {
current_canvas_settings.maxZoom = 2;
}
if ($('#radio-max-zoom-3').get(0).checked) {
current_canvas_settings.maxZoom = 3;
}
if ($('#radio-max-zoom-4').get(0).checked) {
current_canvas_settings.maxZoom = 4;
}
if ($('#radio-max-zoom-custom').get(0).checked) {
current_canvas_settings.maxZoom = parseFloat($('#input-max-zoom').val());
}
// navigator
current_canvas_settings.navigator = $('#checkbox-navigator').get(0).checked;
// navigator image preview
current_canvas_settings.navigatorImagePreview = $('#checkbox-navigator-image-preview').get(0).checked;
// fullscreen
current_canvas_settings.fullscreen = $('#checkbox-fullscreen').get(0).checked;
canvas.apply_settings(current_canvas_settings);
}
}
function enable_form() { $('#panel-disabler').hide(); }
function disable_form() { $('#panel-disabler').show(); }
function generate_annotation_id() {
return "my-annotation-" + Math.floor(Math.random() * 100000) + 1;
}
function generate_jquery() {
var frameWidth = (canvas.settings.frameWidth == "auto") ? '"100%"' : canvas.settings.frameWidth;
var frameHeight = canvas.settings.frameHeight;
var maxZoom = (canvas.settings.maxZoom == "auto") ? '"auto"' : canvas.settings.maxZoom;
var annotations = new Array();
for (drawable_id in drawables) {
var drawable = drawables[drawable_id];
if (drawable != undefined) {
annotations.push(drawable.settings);
}
}
var result = '$("#the-img-tag").annotatorPro({';
var has_canvas_option = false;
// frame width
if (canvas.settings.frameWidth != canvas_defaults.frameWidth) {
result += "');
}
function generate_preview() {
var plugin_container = $('#plugin-container');
plugin_container.html('');
plugin_container.append('