contentview_Marking.js 14.6 KB
Newer Older
Motohisa Nakano committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 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 76 77 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 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 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 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 242 243 244 245 246 247 248 249 250 251 252 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 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482
/// コンテンツ閲覧画面_マーキングツールバーオーバーレイ
/// <reference path="../common/js/avweb.js" />

/// <reference path="../common/js/screenLock.js" />

/// <reference path="../common/js/common.js" />

/// <reference path="../common/js/i18n.js" />

/// <reference path="../common/js/jquery-1.8.1.min.js" />

/// <reference path="../common/js/jquery-ui-1.8.23.custom.min.js" />

/// <reference path="../common/js/jquery.toastmessage.js" />

/// <reference path="../common/js/pageViewer.js" />


/// ===============================================================================================
/// Marking group [start]
/// ===============================================================================================

// Set default value for easer.
function Marking_SetDefaultValue() {
};

/*
----------------------------------------------------------------------------
Event groups [start]
----------------------------------------------------------------------------
*/
function dlgMarking_dspSave_click() {
    imgMarkerTemp = canvas_marker.toDataURL("image/png;");
	
	var img = new Image();
	img.onload = function () {
	    context_draw.drawImage(img, 0, 0, canvas_draw.width, canvas_draw.height);

	    /*create new entity marking */
	    var marking = new MarkingEntity();
	    marking.contentid = contentID;
	    marking.pageNo = changePageIndex(getPageIndex());
	    marking.content = canvas_draw.toDataURL("image/png");


	    /* insert marking */
	    var arr = ClientData.MarkingData();
	    var nIndexMarking = -1;

	    for (var nIndex = 0; nIndex < arr.length; nIndex++) {
	        if (arr[nIndex].contentid == contentID
			&& arr[nIndex].pageNo == changePageIndex(getPageIndex())) {
	            nIndexMarking = nIndex;
	            break;
	        }
	    }

	    if (isDrawing == true) {/* if has draw image */
	        if (isClearDrawing == true) {
	            arr.splice(nIndexMarking, 1);
	        } else {
	            /* case not exist marking */
	            if (nIndexMarking == -1) {
	                arr.push(marking);
	            } else {
	                /* case exist marking */
	                arr[nIndexMarking] = marking;
	            }
	        }
	    }

	    /*add marking to local storage */
	    ClientData.MarkingData(arr);

	    // Close dialog
	    //$("#dlgMarking").dialog('close');
	    $("#dlgMarking").hide();
	    ClientData.IsAddingMarking(false);
	    $('#draw_canvas').css('display', 'none');

	    /* $('#imgmarkingtoolbar').removeClass('markingToolbar');
	    $('#imgmarkingtoolbar').addClass('markingToolbar_off');
	    $("#imgmarkingtoolbar").removeAttr("style")
	    
	    $('#imgmarking').removeClass('marking_off');
	    $('#imgmarking').addClass('marking');*/

	    /*set flag change marking */
	    ClientData.isChangedMemo(true);

	    ClientData.IsHideToolbar(false);

	    /* draw again*/
	    //drawCanvas();
	    //disableAllControl();	
	    handleDisplayToolbar();
	    /* visible button fullscreen */
	    $('#control_screen_2').show();

	    /* init clear drawing canvas */
	    isClearDrawing = false;
	};
	img.src = imgMarkerTemp;	
	
	context_marker.clearRect(0, 0, canvas_marker.width, canvas_marker.height);
	
	$('#marker_canvas').css('display','none');		 

};

function dlgMarking_dspCancel_click() {
    // Close dialog    
    $("#dlgMarking").hide();  	
    
    /* init clear drawing canvas */
    isClearDrawing = false;
    
    ClientData.IsAddingMarking(false);
	$('#draw_canvas').css('display','none');    
   
    /*$('#imgmarkingtoolbar').removeClass('markingToolbar');
	$('#imgmarkingtoolbar').addClass('markingToolbar_off');
	$("#imgmarkingtoolbar").removeAttr("style")*/
	
    ClientData.IsHideToolbar(false);
    context_draw.clearRect(0, 0, canvas_draw.width, canvas_draw.height);
    
    /* draw again*/
    //drawCanvas();
    //disableAllControl();
    handleDisplayToolbar();
    /* visible button fullscreen */
	$('#control_screen_2').show();   
	
	$('#marker_canvas').css('display','none');	
};

function dlgMarking_dspPgClear_click() {
    
    // Close dialog
     context_draw.clearRect(0, 0, canvas_draw.width, canvas_draw.height);
     context_marker.clearRect(0, 0, canvas_marker.width, canvas_marker.height);

     isClearDrawing = true;
     
     /* clear on local */
     var arr = ClientData.MarkingData();	
};

/* draw marker canvas to draw canvas */
function canvasMarkerToCanvasDraw(){
    imgMarkerTemp = canvas_marker.toDataURL("image/png;");
	
	var img = new Image();
	img.onload = function () {
	    context_draw.drawImage(img, 0, 0, canvas_draw.width, canvas_draw.height);
	};
	img.src = imgMarkerTemp;	
	
	context_marker.clearRect(0, 0, canvas_marker.width, canvas_marker.height);
	
	 $('#marker_canvas').css('display','none');		 
};


function dlgMarking_imgPen_click() {
    // Choose pen
    $("#dlgMarking_imgMaker").removeClass();
    $("#dlgMarking_imgPen").addClass('toolbar_icon_on');
    $("#dlgMarking_imgEraser").removeClass();

    ClientData.MarkingType("pen");
    markingType = "pen";
    
    canvasMarkerToCanvasDraw();
    
    setDefaultImageForMarking();
};
function dlgMarking_imgPenOption_click() {
	/*disable button */
	disableButtonMarking();
	//ClientData.IsAddingMarking(false);
	/* display dialog overlay */
    $("#overlay").show();
    isAddingMarking = ClientData.IsAddingMarking();
	
    // Show option of pen
    ShowPen($('#dlgPen'));
    
    /* draw maker canvas */
    if(markingType == "maker"){
   		canvasMarkerToCanvasDraw();
    }
    
    ClientData.MarkingType("pen");
    markingType = "pen";
    
    $('#dlgMarking_imgPenOption').removeClass();
	$('#dlgMarking_imgPenOption').addClass('pen_option_selected');
	
	setDefaultImageForMarking();
	
};
function dlgMarking_imgMaker_click() {
    // Choose maker
    $("#dlgMarking_imgMaker").addClass('toolbar_icon_on');
    $("#dlgMarking_imgPen").removeClass();
    $("#dlgMarking_imgEraser").removeClass();

    ClientData.MarkingType("maker");
    markingType = "maker";
    $('#marker_canvas').css('display','block');    
    
    setDefaultImageForMarking();
};
function dlgMarking_imgMakerOption_click() {
	/*disable button */
	disableButtonMarking();
	//ClientData.IsAddingMarking(false);
	 /* display dialog overlay */
    $("#overlay").show();
    isAddingMarking = ClientData.IsAddingMarking();
	
    // Show option of maker
    ShowMaker($('#dlgMaker'));
    
    ClientData.MarkingType("maker");
    markingType = "maker";
    $('#marker_canvas').css('display','block');   
    
    $('#dlgMarking_imgMakerOption').removeClass();
	$('#dlgMarking_imgMakerOption').addClass('maker_option_selected');
	
	setDefaultImageForMarking();
};
function dlgMarking_imgEraser_click() {
    // Choose eraser
    $("#dlgMarking_imgMaker").removeClass();
    $("#dlgMarking_imgPen").removeClass();
    $("#dlgMarking_imgEraser").addClass('toolbar_icon_on');

    ClientData.MarkingType("eraser");
    markingType = "eraser";
    canvasMarkerToCanvasDraw(); 
    
    setDefaultImageForMarking(); 
};
function dlgMarking_imgEraserOption_click() {
	/*disable button */
	disableButtonMarking();
	//ClientData.IsAddingMarking(false);
	/* display dialog overlay */
    $("#overlay").show();
	isAddingMarking = ClientData.IsAddingMarking();
	
    // Show option of maker
    ShowEraser();
    
    /* draw maker canvas */
    if(markingType == "maker"){
   		canvasMarkerToCanvasDraw();
    }
    
    ClientData.MarkingType("eraser");
    markingType = "eraser";
    
    $('#dlgMarking_imgEraserOption').removeClass();
	$('#dlgMarking_imgEraserOption').addClass('eraser_option_selected');
	
	setDefaultImageForMarking();
};

function dlgMarking_imgMin_click() {
    //$("#dlgMarking_body").slideToggle('fast');
    $("#dlgMarking_imgMin").hide();  
    $("#dlgMarking_imgMax").show();
	$("#dlgMarking_body").removeClass('markingBoxBody_on');
    $("#dlgMarking_body").addClass('markingBoxBody_off');
    //$('#dlgMarking').dialog({ height: 80});
    //$('#dlgMarking').css('height', '29px');
};
function dlgMarking_imgMax_click() {
    //$("#dlgMarking_imgMin").slideToggle('fast');
    $("#dlgMarking_imgMax").hide();
    $("#dlgMarking_imgMin").show();
	$("#dlgMarking_body").addClass('markingBoxBody_on');
    $("#dlgMarking_body").removeClass('markingBoxBody_off');
    //$('#dlgMarking').dialog({height: 350});
    //$('#dlgMarking').css('height', '300px');
};
function dlgMarking_imgClose_click() {
    $("#dlgMarking").hide();
    ClientData.IsHideToolbar(true);
    disableAllControl();
    
};
/*
----------------------------------------------------------------------------
Event groups [ end ]
----------------------------------------------------------------------------
*/

function setDefaultImageForMarking(){	
	/* pen */
	if(markingType == "pen"){
		$('#dlgMarking_imgPen').removeClass();
		$('#dlgMarking_imgPen').addClass('pen_selected');
		
	}else{
		$('#dlgMarking_imgPen').removeClass();
		$('#dlgMarking_imgPen').addClass('pen_hover');
	}
	
	/* maker */
	if(markingType == "maker"){
		$('#dlgMarking_imgMaker').removeClass();
		$('#dlgMarking_imgMaker').addClass('maker_selected');
		
	}else{
		$('#dlgMarking_imgMaker').removeClass();
		$('#dlgMarking_imgMaker').addClass('maker_hover');
	}
	
	/* maker */
	if(markingType == "eraser"){
		$('#dlgMarking_imgEraser').removeClass();
		$('#dlgMarking_imgEraser').addClass('eraser_selected');
		
	}else{
		$('#dlgMarking_imgEraser').removeClass();
		$('#dlgMarking_imgEraser').addClass('eraser_hover');
	}
};

/* disable all button on dialog marking */
function disableButtonMarking(){
	$('#dlgMarking_dspSave').unbind('click');
	$('#dlgMarking_dspCancel').unbind('click');
	$('#dlgMarking_dspPgClear').unbind('click');
	$('#dlgMarking_imgMin').unbind('click');
	$('#dlgMarking_imgMax').unbind('click');
	$('#dlgMarking_imgClose').unbind('click');
	$('#dlgMarking_imgPen').unbind('click');
	$('#dlgMarking_imgPenOption').unbind('click');
	$('#dlgMarking_imgMaker').unbind('click');
	$('#dlgMarking_imgMakerOption').unbind('click');
	$('#dlgMarking_imgEraser').unbind('click');
	$('#dlgMarking_imgEraserOption').unbind('click');
	
	/* set cursor default*/
	$("#dlgMarking_dspSave").css('cursor', 'default');
	$("#dlgMarking_dspCancel").css('cursor', 'default');
	$("#dlgMarking_dspPgClear").css('cursor', 'default');
	$("#dlgMarking_imgMin").css('cursor', 'default');
	$("#dlgMarking_imgMax").css('cursor', 'default');
	$("#dlgMarking_imgClose").css('cursor', 'default');
	$("#dlgMarking_imgPen").css('cursor', 'default');
	$("#dlgMarking_imgPenOption").css('cursor', 'default');
	$("#dlgMarking_imgMaker").css('cursor', 'default');
	$("#dlgMarking_imgMakerOption").css('cursor', 'default');
	$("#dlgMarking_imgEraser").css('cursor', 'default');
	$("#dlgMarking_imgEraserOption").css('cursor', 'default');
	
	
};

/* enable all button con dialog marking */
function enableButtonMarking(){
	disableButtonMarking();
	$('#dlgMarking_dspSave').bind('click',dlgMarking_dspSave_click);
	$('#dlgMarking_dspCancel').bind('click',dlgMarking_dspCancel_click);
	$('#dlgMarking_dspPgClear').bind('click',dlgMarking_dspPgClear_click);
	$('#dlgMarking_imgMin').bind('click',dlgMarking_imgMin_click);
	$('#dlgMarking_imgMax').bind('click',dlgMarking_imgMax_click);
	$('#dlgMarking_imgClose').bind('click',dlgMarking_imgClose_click);
	$('#dlgMarking_imgPen').bind('click',dlgMarking_imgPen_click);
	$('#dlgMarking_imgPenOption').bind('click',dlgMarking_imgPenOption_click);
	$('#dlgMarking_imgMaker').bind('click',dlgMarking_imgMaker_click);
	$('#dlgMarking_imgMakerOption').bind('click',dlgMarking_imgMakerOption_click);
	$('#dlgMarking_imgEraser').bind('click',dlgMarking_imgEraser_click);
	$('#dlgMarking_imgEraserOption').bind('click',dlgMarking_imgEraserOption_click);	
	
	/* set cursor pointer*/
	$("#dlgMarking_dspSave").css('cursor', 'pointer');
	$("#dlgMarking_dspCancel").css('cursor', 'pointer');
	$("#dlgMarking_dspPgClear").css('cursor', 'pointer');
	$("#dlgMarking_imgMin").css('cursor', 'pointer');
	$("#dlgMarking_imgMax").css('cursor', 'pointer');
	$("#dlgMarking_imgClose").css('cursor', 'pointer');
	$("#dlgMarking_imgPen").css('cursor', 'pointer');
	$("#dlgMarking_imgPenOption").css('cursor', 'pointer');
	$("#dlgMarking_imgMaker").css('cursor', 'pointer');
	$("#dlgMarking_imgMakerOption").css('cursor', 'pointer');
	$("#dlgMarking_imgEraser").css('cursor', 'pointer');
	$("#dlgMarking_imgEraserOption").css('cursor', 'pointer');
};

function ShowMarking() {
    //$("#dlgMarking_body").show();
    //$("#dlgMarking_body").addClass('markingBoxBody_on');
    //$("#dlgMarking_body").removeClass('markingBoxBody_on');
    
    
    //$('#dlgMarking').dialog({ height: 350 });
    //$('#dlgMarking').css('height', '300px');

    //$('#dlgMarking').dialog("open");
    $('#dlgMarking').css('top', '40px');
	$('#dlgMarking').css('left', '10px');
    $('#dlgMarking').show();
    //$('#dlgMarking').fadeIn('fast');	
	    
//    $('#dlgMarking').center();
//    $('#dlgMarking').top();
//    $('#dlgMarking').bottom();

    //$(".ui-dialog-titlebar").hide();
    Marking_SetDefaultValue();
    //$("#dlgMarking_imgMin").show();
   // $("#dlgMarking_imgMax").hide();

    dlgMarking_imgPen_click();
    
    setDefaultImageForMarking();
    
	$('#dlgMarking_imgPenOption').removeClass();
	$('#dlgMarking_imgPenOption').addClass('pen_option_hover');
	
	$('#dlgMarking_imgMakerOption').removeClass();
	$('#dlgMarking_imgMakerOption').addClass('maker_option_hover');
	
	$('#dlgMarking_imgEraserOption').removeClass();
	$('#dlgMarking_imgEraserOption').addClass('eraser_option_hover');
};

// Setting dialog
$(function () {
	
    $("#dlgMarking_dspSave").click(dlgMarking_dspSave_click);
    $("#dlgMarking_dspCancel").click(dlgMarking_dspCancel_click);
    $("#dlgMarking_dspPgClear").click(dlgMarking_dspPgClear_click);

    // Icons
    $("#dlgMarking_imgMin").click(dlgMarking_imgMin_click);
    $("#dlgMarking_imgMax").click(dlgMarking_imgMax_click);
    $("#dlgMarking_imgClose").click(dlgMarking_imgClose_click);
    $("#dlgMarking_imgPen").click(dlgMarking_imgPen_click);
    $("#dlgMarking_imgPenOption").click(dlgMarking_imgPenOption_click);
    $("#dlgMarking_imgMaker").click(dlgMarking_imgMaker_click);
    $("#dlgMarking_imgMakerOption").click(dlgMarking_imgMakerOption_click);
    $("#dlgMarking_imgEraser").click(dlgMarking_imgEraser_click);
    $("#dlgMarking_imgEraserOption").click(dlgMarking_imgEraserOption_click);
    /*
    $('#dlgMarking').dialog({
        autoOpen: false,
        title: '',
        modal: false,
        resizable: false,
        width: 300,
        height: 350
    });
    */
    $('#dlgMarking').draggable({
        revert: false
    });
   

});
/// ===============================================================================================
/// Marking group [ end ]
/// ===============================================================================================