Javascript-форум (https://javascript.ru/forum/)
-   Общие вопросы Javascript (https://javascript.ru/forum/misc/)
-   -   Коментарии в модальном окне (https://javascript.ru/forum/misc/61025-komentarii-v-modalnom-okne.html)

Castromen 01.02.2016 10:12

Коментарии в модальном окне
 
Доброе утро.
Помогите поправить JS код:

Функция скрывает длинное коментарие и выводит полностью при наведение на текст.
Хотелось бы что бы не при наведение это происходило а при клике открывалось модальное окно.

Спасибо
<!-- HTML-код модального окна -->
<div id="myModalBox" class="modal fade">
  <div class="modal-dialog">
    <div class="modal-content">
      <!-- Заголовок модального окна -->
      <div class="modal-header">
        <button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
        <h4 class="modal-title">Комментарии</h4>
      </div>
      <!-- Основное содержимое модального окна -->
      <div class="modal-body">
        Содержимое модального окна... ('" + bodyValue + "')
      </div>
      <!-- Футер модального окна -->
      <div class="modal-footer">
        <button type="button" class="btn btn-default" data-dismiss="modal">Закрыть</button>
      </div>
    </div>
  </div>
</div>



(function () { 
 
    // Create object that have the context information about the field that we want to change it's output render  
    var bodyFiledContext = {}; 
    bodyFiledContext.Templates = {}; 
    bodyFiledContext.Templates.Fields = { 
        // Apply the new rendering for Body field on list view 
        "Comments": { "View": bodyFiledTemplate } 
    }; 
 
    SPClientTemplates.TemplateManager.RegisterTemplateOverrides(bodyFiledContext); 
 
})(); 
 
// This function provides the rendering logic 
function bodyFiledTemplate(ctx) { 
 
    var bodyValue = ctx.CurrentItem[ctx.CurrentFieldSchema.Name]; 
 
    //This regex expression use to delete html tags from the Body field 
    var regex = /(<([^>]+)>)/ig; 
 
    bodyValue = bodyValue.replace(regex, ""); 
 
    var newBodyValue = bodyValue; 
 
    if (bodyValue && bodyValue.length >= 100) 
    { 
        newBodyValue = bodyValue.substring(0, 100) + " ..."; 
    } 
 
    return "<span data-placement='left' data-toggle='popover' title='" + bodyValue + "'>" + newBodyValue + "</span>"; 
        
}

destus 01.02.2016 10:59

window.open не помогает?

Castromen 01.02.2016 17:54

destus,
Можете немного поподробнее.

destus 01.02.2016 19:35

Цитата:

Сообщение от Castromen (Сообщение 405932)
destus,
Можете немного поподробнее.

При клике открывать окно через window.open и туда комментарий кидать.

https://learn.javascript.ru/window-methods

<a id="testLink" href="#">Открыть окно</a>
	<script>
	var a = document.getElementById('testLink');
	a.addEventListener('click',function(e){
		var newWin = window.open('javascript:','','width=300,height=300');
		newWin.document.write('Здесь был длинный комментарий');
		newWin.moveBy(a.offsetLeft + 100,a.offsetTop + 100);
		a.preventDefault();
	},
	false);
	</script>

tsigel 02.02.2016 08:18

Только будте осторожны, $ - это не jquery!

<style>

    html, body {
        width: 100%;
        height: 100%;
    }

    .modal {
        display: none;
    }

    .block {
        width: 100%;
        height: 100%;
        background-color: rgba(0,0,0, 0.6);
        position: fixed;
        left: 0;
        top: 0;
    }

    .modal-content {
        border: 1px solid #eee;
        border-radius: 3px;
        position: fixed;
        left: 50%;
        top: 50%;
        background-color: #fff;
        transform: translate(-50%, -50%);
        -webkit-transform: translate(-50%, -50%);
        padding: 10px 15px;
    }

    .modal-content .close {
        position: absolute;
        right: 10px;
        top: 10px;
    }
</style>

<a class="show-modal">Открыть окно</a>
<div class="modal">
    <div class="block"></div>
    <div class="modal-content">
        <div class="close">X</div>
        <div class="header"></div>
        <div class="content"></div>
        <div class="footer"></div>
    </div>
</div>

<script>

    var $ = document.querySelector.bind(document);

    var showModal = function (headerText, contentText, footerText) {
        $('.modal').style.display = 'block';
        $('.header').innerHTML = headerText;
        $('.content').innerHTML = contentText;
        $('.footer').innerHTML = footerText;
    };

    $('.close').addEventListener('click', function () {
        $('.modal').style.display = 'none';
    }, false);

    $('.show-modal').addEventListener('click', function () {
        showModal('Какой-то заголовок!', '<h1>какой-то контент</h1>', 'какой-то футер');
    }, false);

</script>


Часовой пояс GMT +3, время: 09:34.