<commit_before>@extends('layouts.app')

@section('content')
<div class="container">
	<?php
		$count = count($slides); 

		//set up urls

		if ($story->type == 1) {
			$event_type = 'event';
		} else if ($story->type == 2){
			$event_type = 'gacha';
		} else if ($story->type == 3) {
			$event_type = 'character/'.$story->boy_id;
		}
	?>
    <h1><div class="col-xs-6"> {!! Form::text('name_e',$chapter->name_e,['class'=>'form-control name_e','id'=>$chapter->id]) !!} </div>- {{$story->name_e}} <small>({{$count}} slides)</small>

    @if ($chapter->complete == 1)
        <button id="display-chapter" class="btn btn-danger chapter-display" data-id="{{$chapter->id}}" data-display="hide">Hide</button></h1>
    @else 
        <button id="display-chapter" class="btn btn-success chapter-display" data-id="{{$chapter->id}}" data-display="display">Display</button></h1>
    @endif
    @foreach ($slides as $slide)
    <?php
    	//i just had to put zero prefixes
    	$slide_number = str_pad($slide->slide,2,'0',STR_PAD_LEFT);
    ?>
    <div class="row">
    	<div class="col-md-6">
    	<img class="img-responsive" src="/images/translate/{{$event_type}}/{{$story->id}}/{{$chapter->chapter}}_{{$slide_number}}.{{$chapter->file_type}}">
    	</div>
    	<div class="col-md-6">
			<div class="row mobile-hide">
                    <div class="col-md-6">
                        {!! Form::textarea('text_j',$slide->text_j,['class'=>'form-control ajaxTest','id'=>'j-'.$slide->id, 'rows' => 3, 'cols' => 100, 'placeholder'=>'Japanese Text']) !!} 
                    </div>
                    <div class="col-md-6">
                        {!! Form::textarea('text_g',$slide->text_g,['class'=>'form-control ajaxTest','id'=>'j-'.$slide->id, 'rows' => 3, 'cols' => 100, 'placeholder'=>'Generated Text']) !!} 
                    </div>
            </div>
            <br>
			{!! Form::textarea('text_e', $slide->text_e,['class'=>'form-control ajaxTest','id'=>'e-'.$slide->id, 'rows' => 3, 'cols' => 100, 'placeholder'=>'English Text']) !!} 
            <!-- tooltip button -->
                <button class="add-boy-css" data-class="tooltip" data-slide="{{$slide->id}}">Tooltip</button>
            <br>
			{!! Form::textarea('notes', $slide->notes,['class'=>'form-control ajaxTest', 'id'=>'n-'.$slide->id, 'rows' => 3, 'cols' => 100, 'placeholder'=>'Notes']) !!} <br>
			{!! Form::hidden('slide_id', $slide->id) !!}
			{!! Form::hidden('chapter_id', $chapter->id) !!}
			{!! Form::hidden('story_id', $story->id) !!}
			{!! Form::select('boy_id', $boys,$slide->boy_id, ['class'=>'dropdownAjax','id'=>'s-'.$slide->id, 'placeholder' => 'Speaker']) !!}   {{$slide->slide}} | Last updated: <span id="lastupdated-{{$slide->id}}">{{$slide->updated_at}}</span>
			
    	</div>
   	</div>
   	<br><br>
    @endforeach
</div>
            <script>

            //adding in class names to textarea with button press - Christine -2017-09-24
            function getInputSelection(el) {
    var start = 0, end = 0, normalizedValue, range,
        textInputRange, len, endRange;

    if (typeof el.selectionStart == "number" && typeof el.selectionEnd == "number") {
        start = el.selectionStart;
        end = el.selectionEnd;
    } else {
        range = document.selection.createRange();

        if (range && range.parentElement() == el) {
            len = el.value.length;
            normalizedValue = el.value.replace(/\r\n/g, "\n");

            // Create a working TextRange that lives only in the input
            textInputRange = el.createTextRange();
            textInputRange.moveToBookmark(range.getBookmark());

            // Check if the start and end of the selection are at the very end
            // of the input, since moveStart/moveEnd doesn't return what we want
            // in those cases
            endRange = el.createTextRange();
            endRange.collapse(false);

            if (textInputRange.compareEndPoints("StartToEnd", endRange) > -1) {
                start = end = len;
            } else {
                start = -textInputRange.moveStart("character", -len);
                start += normalizedValue.slice(0, start).split("\n").length - 1;

                if (textInputRange.compareEndPoints("EndToEnd", endRange) > -1) {
                    end = len;
                } else {
                    end = -textInputRange.moveEnd("character", -len);
                    end += normalizedValue.slice(0, end).split("\n").length - 1;
                }
            }
        }
    }

    return {
        start: start,
        end: end
    };
}

function replaceSelectedText(el, text) {
    var sel = getInputSelection(el), val = el.value;
    el.value = val.slice(0, sel.start) + text + val.slice(sel.end);
}


$('.add-boy-css').on('click',function(){
    var text = window.getSelection().toString();
    
    //this would have to be the closest text area.
    var slideID = $(this).data("slide");
    var className = $(this).data("class");
    
    //get selected text
    var text = window.getSelection().toString();
    var el = document.getElementById("e-"+slideID);

    //check if its a tooltip and do special case, other wise boy class name
    if (className == 'tooltip') {
        //addin bootstraptooltip text
        //<span data-toggle="tooltip" title="bread filled with red bean paste">anpan</span>
        replaceSelectedText(el, '<span data-toggle="tooltip" title="">'+text+'</span>');
    } else {
        //wrap selected text in a class with boy's name <span class="Tori">text</span>
        replaceSelectedText(el, '<span class="'+className+'">'+text+'</span>');
    }



    //save added classes 
    var slideName = 'text_e';
    var slideValue = $('#e-'+slideID).val();

    slideContentAjax(slideID,slideName,slideValue);

});





	//lets copy code<commit_msg>Add italic and bold options to translation UI<commit_after>@extends('layouts.app')

@section('content')
<div class="container">
	<?php
		$count = count($slides); 

		//set up urls

		if ($story->type == 1) {
			$event_type = 'event';
		} else if ($story->type == 2){
			$event_type = 'gacha';
		} else if ($story->type == 3) {
			$event_type = 'character/'.$story->boy_id;
		}
	?>
    <h1><div class="col-xs-6"> {!! Form::text('name_e',$chapter->name_e,['class'=>'form-control name_e','id'=>$chapter->id]) !!} </div>- {{$story->name_e}} <small>({{$count}} slides)</small>

    @if ($chapter->complete == 1)
        <button id="display-chapter" class="btn btn-danger chapter-display" data-id="{{$chapter->id}}" data-display="hide">Hide</button></h1>
    @else 
        <button id="display-chapter" class="btn btn-success chapter-display" data-id="{{$chapter->id}}" data-display="display">Display</button></h1>
    @endif
    @foreach ($slides as $slide)
    <?php
    	//i just had to put zero prefixes
    	$slide_number = str_pad($slide->slide,2,'0',STR_PAD_LEFT);
    ?>
    <div class="row">
    	<div class="col-md-6">
    	<img class="img-responsive" src="/images/translate/{{$event_type}}/{{$story->id}}/{{$chapter->chapter}}_{{$slide_number}}.{{$chapter->file_type}}">
    	</div>
    	<div class="col-md-6">
			<div class="row mobile-hide">
                    <div class="col-md-6">
                        {!! Form::textarea('text_j',$slide->text_j,['class'=>'form-control ajaxTest','id'=>'j-'.$slide->id, 'rows' => 3, 'cols' => 100, 'placeholder'=>'Japanese Text']) !!} 
                    </div>
                    <div class="col-md-6">
                        {!! Form::textarea('text_g',$slide->text_g,['class'=>'form-control ajaxTest','id'=>'j-'.$slide->id, 'rows' => 3, 'cols' => 100, 'placeholder'=>'Generated Text']) !!} 
                    </div>
            </div>
            <br>
			{!! Form::textarea('text_e', $slide->text_e,['class'=>'form-control ajaxTest','id'=>'e-'.$slide->id, 'rows' => 3, 'cols' => 100, 'placeholder'=>'English Text']) !!} 
                <!-- italics button -->    
                <button class="add-boy-css" data-class="italics" data-slide="{{$slide->id}}">italic</button>    
                <!-- bold button -->    
                <button class="add-boy-css" data-class="bold" data-slide="{{$slide->id}}">bold</button>                                
                <!-- tooltip button -->
                <button class="add-boy-css" data-class="tooltip" data-slide="{{$slide->id}}">Tooltip</button>
            <br>
			{!! Form::textarea('notes', $slide->notes,['class'=>'form-control ajaxTest', 'id'=>'n-'.$slide->id, 'rows' => 3, 'cols' => 100, 'placeholder'=>'Notes']) !!} <br>
			{!! Form::hidden('slide_id', $slide->id) !!}
			{!! Form::hidden('chapter_id', $chapter->id) !!}
			{!! Form::hidden('story_id', $story->id) !!}
			{!! Form::select('boy_id', $boys,$slide->boy_id, ['class'=>'dropdownAjax','id'=>'s-'.$slide->id, 'placeholder' => 'Speaker']) !!}   {{$slide->slide}} | Last updated: <span id="lastupdated-{{$slide->id}}">{{$slide->updated_at}}</span>
			
    	</div>
   	</div>
   	<br><br>
    @endforeach
</div>
            <script>

            //adding in class names to textarea with button press - Christine -2017-09-24
            function getInputSelection(el) {
    var start = 0, end = 0, normalizedValue, range,
        textInputRange, len, endRange;

    if (typeof el.selectionStart == "number" && typeof el.selectionEnd == "number") {
        start = el.selectionStart;
        end = el.selectionEnd;
    } else {
        range = document.selection.createRange();

        if (range && range.parentElement() == el) {
            len = el.value.length;
            normalizedValue = el.value.replace(/\r\n/g, "\n");

            // Create a working TextRange that lives only in the input
            textInputRange = el.createTextRange();
            textInputRange.moveToBookmark(range.getBookmark());

            // Check if the start and end of the selection are at the very end
            // of the input, since moveStart/moveEnd doesn't return what we want
            // in those cases
            endRange = el.createTextRange();
            endRange.collapse(false);

            if (textInputRange.compareEndPoints("StartToEnd", endRange) > -1) {
                start = end = len;
            } else {
                start = -textInputRange.moveStart("character", -len);
                start += normalizedValue.slice(0, start).split("\n").length - 1;

                if (textInputRange.compareEndPoints("EndToEnd", endRange) > -1) {
                    end = len;
                } else {
                    end = -textInputRange.moveEnd("character", -len);
                    end += normalizedValue.slice(0, end).split("\n").length - 1;
                }
            }
        }
    }

    return {
        start: start,
        end: end
    };
}

function replaceSelectedText(el, text) {
    var sel = getInputSelection(el), val = el.value;
    el.value = val.slice(0, sel.start) + text + val.slice(sel.end);
}


$('.add-boy-css').on('click',function(){
    var text = window.getSelection().toString();
    
    //this would have to be the closest text area.
    var slideID = $(this).data("slide");
    var className = $(this).data("class");
    
    //get selected text
    var text = window.getSelection().toString();
    var el = document.getElementById("e-"+slideID);

    //check if its a tooltip and do special case, other wise boy class name
    if (className == 'tooltip') {
        //addin bootstraptooltip text
        //<span data-toggle="tooltip" title="bread filled with red bean paste">anpan</span>
        replaceSelectedText(el, '<span data-toggle="tooltip" title="">'+text+'</span>');
    } else if (className == 'italics') {
        //add italic text
        replaceSelectedText(el, '<em>'+text+'</em>');        
    } else if (className == 'bold') {
        //add italic text
        replaceSelectedText(el, '<strong>'+text+'</strong>');        
    } else {
        //wrap selected text in a class with boy's name <span class="Tori">text</span>
        replaceSelectedText(el, '<span class="'+className+'">'+text+'</span>');
    }



    //save added classes 
    var slideName = 'text_e';
    var slideValue = $('#e-'+slideID).val();

    slideContentAjax(slideID,slideName,slideValue);

});





	//lets copy code
{'fraction_non_alphanumeric': 0.19587039908593815, 'fraction_numerical': 0.0076715906308659106, 'mean_word_length': 2.5212643678160918, 'pattern_counts': {'":': 0, '<': 107, '<?xml version=': 0, '>': 225, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3504573', 'n_tokens_mistral': 3975, 'n_tokens_neox': 3755, 'n_words': 790}