contentview_Pen.js 13.8 KB
Newer Older
1 2 3 4
/// ===============================================================================================
/// Pen group [start]
/// ===============================================================================================

5 6
//名前空間用のオブジェクトを用意する
var CONTENTVIEW_PEN = {};
7

8 9
CONTENTVIEW_PEN.ShowPen = function(targetId) {
	CONTENTVIEW_PEN.pen_targetDiv = targetId;
10
	I18N.i18nReplaceText();
11 12
	$('#dlgPen').show();
	$('#dlgPen').draggable({ revert: false});
13
	CONTENTVIEW_PEN.Pen_handleColorPickerEvent();
14 15 16 17
			
	$('#dlgPen').center();		
};

18
CONTENTVIEW_PEN.touchStart_BtnOk_Pen = function(e){
19
	e.preventDefault();
20
	CONTENTVIEW_PEN.pen_targetDiv.draggable("destroy");
21
	
22
	CONTENTVIEW_PEN.Pen_dspOK_click();
23 24
};

25
CONTENTVIEW_PEN.touchStart_BtnCancel_Pen = function(e){
26
	e.preventDefault();
27
	CONTENTVIEW_PEN.pen_targetDiv.draggable("destroy");
28
	
29
	CONTENTVIEW_PEN.Pen_dspCancel_click();
30 31
};

32
CONTENTVIEW_PEN.Pen_handleColorPickerEvent = function() {
33
 
Masaru Abe committed
34
	if(CONTENTVIEW_GENERAL.avwUserEnvObj.isIos() || CONTENTVIEW_GENERAL.avwUserEnvObj.isAndroid()){
35 36 37
	 	$('#dlgPen .colorpicker').unbind('mouseenter');
    	$('#dlgPen .colorpicker').unbind('mouseleave');
    	$('#penColorwrapper').unbind('mouseleave');
38 39
    	 document.getElementById('Pen_btnOk').addEventListener('touchstart',CONTENTVIEW_PEN.touchStart_BtnOk_Pen,false);
    	 document.getElementById('Pen_btnCancel').addEventListener('touchstart',CONTENTVIEW_PEN.touchStart_BtnCancel_Pen,false);
40 41 42 43 44 45 46
	}
	else{
		
	 	$('#dlgPen .colorpicker').unbind('mouseenter');
    	$('#dlgPen .colorpicker').unbind('mouseleave');
    	$('#penColorwrapper').unbind('mouseleave');
    	
47 48 49
	 	$('#dlgPen .colorpicker').bind('mouseenter', CONTENTVIEW_PEN.Pen_colorPickerMouseEnterFunction);
    	$('#dlgPen .colorpicker').bind('mouseleave', CONTENTVIEW_PEN.Pen_colorPickerMouseLeaveFunction);
    	$('#penColorwrapper').bind('mouseleave', CONTENTVIEW_PEN.Pen_colorWrapperMouseLeaveFunction);
50 51
	}
    
52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75
	//$('#Pen_btnOk').live('click', CONTENTVIEW_PEN.Pen_dspOK_click);
    $("#Pen_btnOk").on({
    	'click touchend': function(ev){
    		CONTENTVIEW_PEN.Pen_dspOK_click(ev);
    		return false;
    	},
    	'touchstart touchmove': function(){
    		//これを入れないと次にダイアログを開くと表示位置が大きくズレる
    		return false;
    	}
    });
	
	//$('#Pen_btnCancel').live('click', CONTENTVIEW_PEN.Pen_dspCancel_click);
    $("#Pen_btnCancel").on({
    	'click touchend': function(ev){
    		CONTENTVIEW_PEN.Pen_dspCancel_click(ev);
    		return false;
    	},
    	'touchstart touchmove': function(){
    		//これを入れないと次にダイアログを開くと表示位置が大きくズレる
    		return false;
    	}
    });
	
76

77
	CONTENTVIEW_PEN.Pen_SetDefaultValue();
78
	
79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126
	//$('#pen-small-text').live('click', CONTENTVIEW_PEN.penSmallTextClick);
    $("#pen-small-text").on({
    	'click touchend': function(ev){
    		CONTENTVIEW_PEN.penSmallTextClick(ev);
    		return false;
    	},
    	'touchstart touchmove': function(){
    		//これを入れないと次にダイアログを開くと表示位置が大きくズレる
    		return false;
    	}
    });
	
	
	//$('#pen-medium-text').live('click', CONTENTVIEW_PEN.penMediumTextClick);
    $("#pen-medium-text").on({
    	'click touchend': function(ev){
    		CONTENTVIEW_PEN.penMediumTextClick(ev);
    		return false;
    	},
    	'touchstart touchmove': function(){
    		//これを入れないと次にダイアログを開くと表示位置が大きくズレる
    		return false;
    	}
    });
	
	//$('#pen-large-text').live('click', CONTENTVIEW_PEN.penLargeTextClick);
    $("#pen-large-text").on({
    	'click touchend': function(ev){
    		CONTENTVIEW_PEN.penLargeTextClick(ev);
    		return false;
    	},
    	'touchstart touchmove': function(){
    		//これを入れないと次にダイアログを開くと表示位置が大きくズレる
    		return false;
    	}
    });
	
	//$('#pen-oversize-text').live('click', CONTENTVIEW_PEN.penOversizeTextClick);
    $("#pen-oversize-text").on({
    	'click touchend': function(ev){
    		CONTENTVIEW_PEN.penOversizeTextClick(ev);
    		return false;
    	},
    	'touchstart touchmove': function(){
    		//これを入れないと次にダイアログを開くと表示位置が大きくズレる
    		return false;
    	}
    });
127

128
	$('#dlgPen .colorpicker').die();
129
	$('#dlgPen .colorpicker').live('click', CONTENTVIEW_PEN.Pen_colorPickerClickFunction);
130 131 132 133 134 135 136 137 138 139 140
    //$("#dlgPen .colorpicker").on({
    //	'click touchend': function(ev){
    //		CONTENTVIEW_PEN.Pen_colorPickerClickFunction(ev);
    //		return false;
    //	},
    //	'touchstart touchmove': function(){
    //		//これを入れないと次にダイアログを開くと表示位置が大きくズレる
    //		return false;
    //	}
    //});
	
141 142
};

143
CONTENTVIEW_PEN.penSmallTextClick = function(){
144 145 146 147
	$('#pen-size-small').attr('checked','checked');
	$('#pen-size-medium').removeAttr('checked');
	$('#pen-size-large').removeAttr('checked');
	$('#pen-size-oversize').removeAttr('checked');
148
	CONTENTVIEW_PEN.Pen_rdo1_click();
149 150
};

151
CONTENTVIEW_PEN.penMediumTextClick = function(){
152 153 154 155
	$('#pen-size-small').removeAttr('checked');
	$('#pen-size-medium').attr('checked','checked');
	$('#pen-size-large').removeAttr('checked');
	$('#pen-size-oversize').removeAttr('checked');
156
	CONTENTVIEW_PEN.Pen_rdo2_click();
157 158
};

159
CONTENTVIEW_PEN.penLargeTextClick = function(){
160 161 162 163
	$('#pen-size-small').removeAttr('checked');
	$('#pen-size-medium').removeAttr('checked');
	$('#pen-size-large').attr('checked','checked');
	$('#pen-size-oversize').removeAttr('checked');
164
	CONTENTVIEW_PEN.Pen_rdo3_click();
165 166
};

167
CONTENTVIEW_PEN.penOversizeTextClick = function(){
168 169 170 171
	$('#pen-size-small').removeAttr('checked');
	$('#pen-size-medium').removeAttr('checked');
	$('#pen-size-large').removeAttr('checked');
	$('#pen-size-oversize').attr('checked','checked');
172
	CONTENTVIEW_PEN.Pen_rdo4_click();
173 174 175
};

// Choose type of eraser, and draw to canvas
176
CONTENTVIEW_PEN.Pen_chooseType = function(typeValue, color) {
177
	var fillColor;
178
	CONTENTVIEW_PEN.pen_Size = typeValue;
179
	var canvas = document.getElementById('Pen_cvPreviewPen');
180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213
	var penLL = document.getElementById('pen-oversize-text').getElementsByTagName('img')[0];
	var penL = document.getElementById('pen-large-text').getElementsByTagName('img')[0];
	var penM = document.getElementById('pen-medium-text').getElementsByTagName('img')[0];
	var penS = document.getElementById('pen-small-text').getElementsByTagName('img')[0];

	switch(typeValue){
		case 5:
			penS.setAttribute("style", "border: 1px solid #ff0000");
			penM.removeAttribute("style");
			penL.removeAttribute("style");
			penLL.removeAttribute("style");
			break;

		case 12.5:
			penS.removeAttribute("style");
			penM.setAttribute("style", "border: 1px solid #ff0000");
			penL.removeAttribute("style");
			penLL.removeAttribute("style");	
			break;

		case 25:
			penS.removeAttribute("style");
			penM.removeAttribute("style");
			penL.setAttribute("style", "border: 1px solid #ff0000");
			penLL.removeAttribute("style");
			break;

		case 50:
			penS.removeAttribute("style");
			penM.removeAttribute("style");
			penL.removeAttribute("style");
			penLL.setAttribute("style", "border: 1px solid #ff0000");
			break;
	}
214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241

	if (color == null || color == 'undefined') {
		fillColor="#fe0000";
	}
	else{
	    fillColor = '#' + color;
	}
	
    if (canvas.getContext) {
        
        // use getContext to use the canvas for drawing
        var ctx = canvas.getContext('2d');

        // Draw shapes

        ctx.clearRect(0, 0, canvas.width, canvas.height);
        
        ctx.beginPath();

        ctx.arc(canvas.width/2, canvas.height/2, typeValue, 0, 2 * Math.PI, true);
        ctx.fillStyle = fillColor;
        ctx.strokeStyle = fillColor;
        ctx.fill();
        ctx.stroke();
    }
};

// Set default value for Pen.
242
CONTENTVIEW_PEN.Pen_SetDefaultValue = function() {
243 244 245
    var typeValue = undefined;
    var penColor = ClientData.penOpt_color();
    typeValue = ClientData.penOpt_size();
246
    CONTENTVIEW_PEN.pen_Size = typeValue;
247 248
    
    if(penColor != null || penColor != undefined){
249
    	CONTENTVIEW_PEN.pen_chooseColor = penColor;
250 251
    }
    else{
252
    	CONTENTVIEW_PEN.pen_chooseColor = 'fe0000';
253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277
    	penColor = 'fe0000';
    }
    
    if (typeValue == 5) {
        $("#pen-size-small").attr('checked', 'checked');
        $("#pen-size-small").focus();
    }
    else if (typeValue == 12.5) {
        $("#pen-size-medium").attr('checked', 'checked');
        $("#pen-size-medium").focus();
    }
    else if (typeValue == 25) {
        $("#pen-size-large").attr('checked', 'checked');
        $("#pen-size-large").focus();
    }
    else if (typeValue == 50) {
        $("#pen-size-oversize").attr('checked', 'checked');
        $("#pen-size-oversize").focus();
    }
    else {
        typeValue = 5;
        $("#pen-size-small").attr('checked', 'checked');
        $("#pen-size-small").focus();
    }
    
278
    CONTENTVIEW_PEN.Pen_chooseType(typeValue, penColor);
Vo Duc Thang committed
279 280 281 282 283
    //START FIXCSS
    //$('#dlgPen .colorpicker[colorId="'+penColor+'"]').css('border','1px solid #e6e6e6');
    $('#dlgPen .colorpicker[colorId="'+penColor+'"]').addClass('picker-choose-on');
    $('#dlgPen .colorpicker[colorId="'+penColor+'"]').removeClass('picker-choose-off');
    //END FIXCSS
284 285
};

286
CONTENTVIEW_PEN.Pen_colorPickerMouseLeaveFunction = function() {
Vo Duc Thang committed
287 288 289 290 291 292

	//START FIXCSS
    //$(this).css('border','1px solid white');    
    //$('#dlgMaker .colorpicker[colorId="'+makerColor+'"]').css('border','1px solid #e6e6e6');
    $(this).addClass('picker-choose-off');
    $(this).removeClass('picker-choose-on');
293 294
    $('#dlgPen .colorpicker[colorId="' + CONTENTVIEW_PEN.pen_chooseColor + '"]').addClass('picker-choose-on');
    $('#dlgPen .colorpicker[colorId="' + CONTENTVIEW_PEN.pen_chooseColor + '"]').removeClass('picker-choose-off');
Vo Duc Thang committed
295
    //END FIXCSS
296 297
};

298
CONTENTVIEW_PEN.Pen_colorPickerMouseEnterFunction = function() {
Vo Duc Thang committed
299 300 301 302 303
	//START FIXCSS
    //$(this).css('border','1px solid #e6e6e6');
    $(this).removeClass('picker-choose-off');
    $(this).addClass('picker-choose-on');
    //END FIXCSS
304
	var color = $(this).attr('colorId');
305
	CONTENTVIEW_PEN.Pen_chooseType(CONTENTVIEW_PEN.pen_Size, color);
306 307
};

308
CONTENTVIEW_PEN.Pen_colorPickerClickFunction = function() {
Vo Duc Thang committed
309
	//START FIXCSS
310
    //$('#dlgMaker .colorpicker[colorId="' + CONTENTVIEW_MAKER.maker_chooseColor + '"]').css('border', '1px solid white');
Vo Duc Thang committed
311
    //$(this).css('border','1px solid #e6e6e6');
312 313
    $('#dlgPen .colorpicker[colorId="' + CONTENTVIEW_PEN.pen_chooseColor + '"]').addClass('picker-choose-off');
    $('#dlgPen .colorpicker[colorId="' + CONTENTVIEW_PEN.pen_chooseColor + '"]').removeClass('picker-choose-on');
Vo Duc Thang committed
314 315 316
    $(this).addClass('picker-choose-on');
    $(this).removeClass('picker-choose-off');
    //END FIXCSS
317 318
    CONTENTVIEW_PEN.pen_chooseColor = $(this).attr('colorId');
    CONTENTVIEW_PEN.Pen_chooseType(CONTENTVIEW_PEN.pen_Size, CONTENTVIEW_PEN.pen_chooseColor);
319 320
};

321 322
CONTENTVIEW_PEN.Pen_rdo1_click = function() {
	CONTENTVIEW_PEN.Pen_chooseType(5, CONTENTVIEW_PEN.pen_chooseColor);  
323
};
324 325
CONTENTVIEW_PEN.Pen_rdo2_click = function() {
	CONTENTVIEW_PEN.Pen_chooseType(12.5, CONTENTVIEW_PEN.pen_chooseColor);
326
};
327 328
CONTENTVIEW_PEN.Pen_rdo3_click = function() {
	CONTENTVIEW_PEN.Pen_chooseType(25, CONTENTVIEW_PEN.pen_chooseColor);
329
};
330 331
CONTENTVIEW_PEN.Pen_rdo4_click = function() {
	CONTENTVIEW_PEN.Pen_chooseType(50, CONTENTVIEW_PEN.pen_chooseColor);
332 333 334
};

// Event of button OK
335
CONTENTVIEW_PEN.Pen_dspOK_click = function() {	
336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353
    // Set selected value to local storage
    var typeValue = undefined;

    if ($("#pen-size-small").attr('checked') == 'checked') {
        typeValue = 5;
    }
    else if ($("#pen-size-medium").attr('checked') == 'checked') {
        typeValue = 12.5;
    }
    else if ($("#pen-size-large").attr('checked') == 'checked') {
        typeValue = 25;
    }
    else if ($("#pen-size-oversize").attr('checked') == 'checked') {
        typeValue = 50;
    }

    // Set value to local
    ClientData.penOpt_size(typeValue);
354 355 356
    ClientData.penOpt_color(CONTENTVIEW_PEN.pen_chooseColor);
    CONTENTVIEW_PEN.pen_Size = typeValue;
    //c = CONTENTVIEW_PEN.pen_chooseColor;    
357 358
    
    /*enable button */
359
	CONTENTVIEW_MARKING.enableButtonMarking();
360
	ClientData.IsAddingMarking(true);
361 362 363
	CONTENTVIEW_GENERAL.isAddingMarking = ClientData.IsAddingMarking();
	CONTENTVIEW_GENERAL.penSize = ClientData.penOpt_size();
	CONTENTVIEW_GENERAL.penColor = ClientData.penOpt_color();
364 365
    
    // Close dialog
366
	CONTENTVIEW_PEN.pen_targetDiv.hide();
367 368 369 370 371 372 373 374 375
	
	/* unlock dialog overlay */
	$("#overlay").hide();
	
	$('#dlgMarking_imgPenOption').removeClass();
	$('#dlgMarking_imgPenOption').addClass('pen_option_hover');
};

// Event of button cancel
376
CONTENTVIEW_PEN.Pen_dspCancel_click = function() {
377
  	/*enable button */
378
	CONTENTVIEW_MARKING.enableButtonMarking();
379
	ClientData.IsAddingMarking(true);
380
	CONTENTVIEW_GENERAL.isAddingMarking = ClientData.IsAddingMarking();
381 382
	
    // Close dialog 
383
	CONTENTVIEW_PEN.pen_targetDiv.hide();
384 385 386 387 388 389 390 391 392
    
    /* unlock dialog overlay */
	$("#overlay").hide();
	
	$('#dlgMarking_imgPenOption').removeClass();
	$('#dlgMarking_imgPenOption').addClass('pen_option_hover');
  
};

393 394 395
CONTENTVIEW_PEN.Pen_colorWrapperMouseLeaveFunction = function() {
	CONTENTVIEW_PEN.Pen_chooseType(CONTENTVIEW_PEN.pen_Size, CONTENTVIEW_PEN.pen_chooseColor);
    //$('#dlgPen .colorpicker[colorId="' + CONTENTVIEW_PEN.pen_chooseColor + '"]').css('border', '1px solid #e6e6e6');
Vo Duc Thang committed
396
	//START FIXCSS
397 398 399
    //$('#dlgMaker .colorpicker[colorId="' + CONTENTVIEW_MAKER.maker_chooseColor + '"]').css('border', '1px solid #e6e6e6');
    $('#dlgPen .colorpicker[colorId="' + CONTENTVIEW_PEN.pen_chooseColor + '"]').addClass('picker-choose-on');
    $('#dlgPen .colorpicker[colorId="' + CONTENTVIEW_PEN.pen_chooseColor + '"]').removeClass('picker-choose-off');
Vo Duc Thang committed
400
    //END FIXCSS
401
};
402

403 404 405 406 407 408 409 410 411 412
$(function () {
	//CONTENTVIEW_PEN.ready();
});

CONTENTVIEW_PEN.ready = function(){
	CONTENTVIEW_PEN.pen_Size = undefined;
	CONTENTVIEW_PEN.pen_targetDiv = undefined;
	CONTENTVIEW_PEN.pen_chooseColor = undefined;
};