HTML 5 dynamic videos (not playlist) - Trying to simply the JS code into a an array - html5-video

I have 8 videos that when clicked on their appropiate link they open a modal window - the video then plays. It work very well using the code i have created below however i am sure there must be a better way write this to reduce the JS code.
Guidence would be most welcomed.
- Have not found much on the forum, and nothing that solves this issue. (hence my code works but is very long). - thank you.
NOT WORKING IN IE8*
THE HTML PAGE WITH LINK
<div class="caption"><?php echo tep_image(DIR_IMAGES.'media/video_atr_cm.jpg','CM Computer','','','');?>
<div class="clearfix"></div>
<h5><?php echo ANIMATED_MEDIA ?></h5>
<h3>CM Computer</h3>
</div>
</a>
<div class="thumbnail-pad"><?php echo TEXT_BUTTON_READ_MORE?></div>
</div>
THE MODAL POPUP CONTAINER:
<!-- modal video -->
<div id="modal-gallery-video" class="modal modal-gallery hide fade" tabindex="-1">
<div class="modal-header"> <a class="close" data-dismiss="modal">×</a>
<h3 class="modal-title"></h3>
</div>
<div class="modal-body">
<video id="video1" controls width="560" height="315">
<source id="mp4" src="" type="video/mp4" />
<source id="webm" src="" type="video/webm" />
<source id="ogg" src="" type="video/ogg" />
<object type="application/x-shockwave-flash" data="http://player.longtailvideo.com/player.swf" width="560" height="315">
<param name="movie" value="http://player.longtailvideo.com/player.swf" />
<param name="allowFullScreen" value="true" />
<param name="wmode" value="transparent" />
<param name="flashVars" value="" />
</object>
</video>
</div>
<div class="modal-footer">
<a class="btn btn-success" onclick="playPause()"><i class="icon-play icon-white"></i> <span>Play/Pause</span> </a>
<a class="btn btn-info" onclick="makeSmall()"><span>Small</span></a>
<a class="btn btn-warning" onclick="makeNormal()"><span>Normal</span></a>
<a class="btn btn-info" onclick="makeBig()"><span>Big</span></a>
</div>
</div>
THE JQUERY:
$(function(){
var player = document.getElementById('video1');
var mp4Vid = document.getElementById('mp4');
var oggVid = document.getElementById('ogg');
var webmVid = document.getElementById('webm');
var swfVid = document.getElementById('swf');
document.getElementById('rockmetal').onclick = function() {
player.pause();
$(mp4Vid).attr('src', "img/video/rockmetal.mp4");
$(oggVid).attr('src', "img/video/rockmetal.ogg");
$(webmVid).attr('src', "img/video/rockmetal.webm");
$(swfVid).attr('value', "controlbar=over&file=http%3A%2F%2Fwww.xxxxx.com%2Ftest%2Fimg%2Fvideo%2Frockmetal.mp4");
player.load();
}
document.getElementById('jet').onclick = function() {
player.pause();
$(mp4Vid).attr('src', "img/video/jet.mp4");
$(oggVid).attr('src', "img/video/jet.ogg");
$(webmVid).attr('src', "img/video/jet.webm");
$(swfVid).attr('value', "controlbar=over&file=http%3A%2F%2Fwww.xxxx.com%2Ftest%2Fimg%2Fvideo%2Fjet.mp4");
player.load();
}
document.getElementById('flight').onclick = function() {
player.pause();
$(mp4Vid).attr('src', "img/video/flight.mp4");
$(oggVid).attr('src', "img/video/flight.ogg");
$(webmVid).attr('src', "img/video/flight.webm");
$(swfVid).attr('value', "controlbar=over&file=http%3A%2F%2Fwww.xxxx.com%2Ftest%2Fimg%2Fvideo%2Fflight.mp4");
player.load();
}
document.getElementById('heli').onclick = function() {
player.pause();
$(mp4Vid).attr('src', "img/video/helicopter.mp4");
$(oggVid).attr('src', "img/video/helicopter.ogg");
$(webmVid).attr('src', "img/video/helicopter.webm");
$(swfVid).attr('value', "controlbar=over&file=http%3A%2F%2Fwww.xxxxxx.com%2Ftest%2Fimg%2Fvideo%2Fhelicopter.mp4");
player.load();
}
document.getElementById('sub').onclick = function() {
player.pause();
$(mp4Vid).attr('src', "img/video/sub.mp4");
$(oggVid).attr('src', "img/video/sub.ogg");
$(webmVid).attr('src', "img/video/sub.webm");
$(swfVid).attr('value', "controlbar=over&file=http%3A%2F%2Fwww.xxxxxx.com%2Ftest%2Fimg%2Fvideo%2Fsub.mp4");
player.load();
}
document.getElementById('uav').onclick = function() {
player.pause();
$(mp4Vid).attr('src', "img/video/uav.mp4");
$(oggVid).attr('src', "img/video/uav.ogg");
$(webmVid).attr('src', "img/video/uav.webm");
$(swfVid).attr('value', "controlbar=over&file=http%3A%2F%2Fwww.xxxxxx.com%2Ftest%2Fimg%2Fvideo%2Fuav.mp4");
player.load();
}
document.getElementById('cm').onclick = function() {
player.pause();
$(mp4Vid).attr('src', "img/video/intro.mp4");
$(oggVid).attr('src', "img/video/intro.ogg");
$(webmVid).attr('src', "img/video/intro.webm");
$(swfVid).attr('value', "controlbar=over&file=http%3A%2F%2Fwww.xxxx.com%2Ftest%2Fimg%2Fvideo%2Fintro.mp4");
player.load();
}
document.getElementById('tank').onclick = function() {
player.pause();
$(mp4Vid).attr('src', "img/video/tank.mp4");
$(oggVid).attr('src', "img/video/tank.ogg");
$(webmVid).attr('src', "img/video/tank.webm");
$(swfVid).attr('value', "controlbar=over&file=http%3A%2F%2Fwww.xxxxxxx.com%2Ftest%2Fimg%2Fvideo%2Ftank.mp4");
player.load();
}
});

<script type="text/javascript">
var loading = document.getElementById('player');
$('ul#allvid li').on('click', function() {var lash = $(this).attr('id');
$("#player").html("<source src='img/video/"+lash+".mp4' type='video/mp4'/><source src='img/video/"+lash+".webm' type='video/webm'/><source src='img/video/"+lash+".ogg' type='video/ogg'/><object type='application/x-shockwave-flash' data='img/video/player.swf' width='560' height='315'><param name='movie' value='img/video/player.swf'/><param name='allowFullScreen' value='true'/><param name='wmode' value='transparent'/><param name='flashVars' value='controlbar=over&file=http%3A%2F%2Fwww.xxxx.com%2Fimg%2Fvideo%2F"+lash+".mp4'/></object>");player.pause();player.load();
});
</script>
<!-- modal video -->
<div id="modal-gallery-video" class="modal modal-gallery hide fade" tabindex="-1">
<div class="modal-header"> <a class="close" data-dismiss="modal">x</a>
<h3 class="modal-title"></h3>
</div>
<div class="modal-body">
<video id="player" controls width="560" height="315">
</video>
</div>
<div class="modal-footer"> <a class="btn btn-success" onclick="playPause()"><i class="icon-play"></i> <span>Play/Pause</span> </a> <a class="btn btn-info" onclick="makeSmall()"> <span>Small</span></a> <a class="btn btn-warning" onclick="makeNormal()"><span>Normal</span></a> <a class="btn btn-info" onclick="makeBig()"><span>Big</span></a></div>
</div>

Related

how to change value of v-if condition of current item in loop (on click)

In my Vue.js app, I have a list of contacts in a v-for loop, each with a corresponding 'edit' button; I want to toggle the v-if="="!isEditingContact" condition for only the selected contact. I have the index of the button/contact to be edited, but I don't know how to toggle the 'isEditingContact' condition for the selected contact.
My component:
<template>
<div class="container" id="project-edit">
<section class="client-data">
<!-- show static if editMode FALSE -->
<dl v-if="!isEditingClient">
<!-- SNIP-->
</dl>
<!-- show FORM if editMode TRUE -->
<fieldset v-if="isEditingClient">
<!-- SNIP -->
</fieldset>
<div class="buttons">
<button v-if=!isEditingClient id="edit-client" v-on:click="editMode">edit</button>
<button v-if=isEditingClient v-on:click="cancelEdit">cancel</button>
<button v-if=isEditingClient v-on:click="post">save changes</button>
</div>
</section><!-- END .client-data -->
<section class="gig-data">
<!-- show static if editMode FALSE -->
<dl v-if="!isEditingGig">
<!-- SNIP-->
</dl>
<!-- show FORM if editMode TRUE -->
<fieldset v-if="isEditingGig">
<!-- SNIP-->
</fieldset>
<div class="buttons">
<button v-if=!isEditingGig id="edit-gig" v-on:click="editMode">edit</button>
<button v-if=isEditingGig v-on:click="cancelEdit">cancel</button>
<button v-if=isEditingGig v-on:click="post">save changes</button>
</div>
</section><!-- END .gig-data -->
<section class="contacts-wrapper">
<!-- show static if editMode FALSE -->
<dl>
<dt>contacts:</dt>
<dd>
<ul class="contacts">
<li v-if="!isEditingContact" v-for="(contact, ix) in project.contacts" v-bind:key="??">
{{ contact.name }}<br />
{{ contact.title }}<br />
{{ contact.email }}<br />
{{ contact.phone }}
<div class="buttons">
<button v-if=!isEditingContact id="edit-contact" v-on:click="editContact(contact, ix)">edit</button>
<button v-if=isEditingContact v-on:click="cancelEdit">cancel</button>
<button v-if=isEditingContact v-on:click="post">save changes</button>
</div>
</li>
</ul>
<!-- show FORM if editMode TRUE -->
<fieldset v-if="isEditingContact">
<!--
SNIP:
FORM TO BE DISPLAYED IN PLACE OF THE SELECTED CONTACT,
AND W/OUT HIDING OTHER CONTACTS
-->
</fieldset>
</dd>
</dl>
</section>
</div>
</template>
<script>
export default {
props: [ "projectID" ],
components: {
},
data () {
return {
id: this.$route.params.id,
title: "Edit Project",
subtitle: "ID: " + this.$route.params.id,
project: {},
contactInfo: {},
workLocation: true,
submitted: false,
isEditingClient: false,
isEditingGig: false,
isEditingContact: false
}
}, // data
created: function() {
this.$http.get("https://xyz.dataworld.com/projects/" + this.id + ".json")
.then(function(data) {
return data.json();
}).then(function(data) {
this.project = data;
})
}, // created
methods: {
addContactInfo: function(e) {
e.preventDefault();
this.projectID = this.id;
this.project.contacts.push(this.contactInfo);
this.contactInfo = {};
},
editMode: function(e) {
const buttonID = e.currentTarget.id;
switch (buttonID) {
case "edit-client":
this.isEditingClient = !this.isEditingClient;
break;
case "edit-gig":
this.isEditingGig = !this.isEditingGig;
break;
// case "edit-contact": ... this is uselesss, since it would hide all contacts as it shows the form
// this.isEditingContact = !this.isEditingContact;
// break;
default:
}
},
editContact: function(e) {
},
cancelEdit: function() {
this.isEditingClient = false;
this.isEditingGig = false;
this.isEditingContacts = false;
},
post: function() {
console.log(this.project);
this.$http.post("https://sr-giglog.firebaseio.com/projects.json", this.project)
.then(function(data){
this.submitted = true;
}
)} // post function
} // methods
}
</script>
Most commonly this is done by adding a flag to the individual objects in your list. In this case, an editing flag, or whatever you want to call it. You would initialize it with false. You can add this flag either server side or client side. If you want to do it client side it would look something like this:
this.$http.get("https://xyz.dataworld.com/projects/" + this.id + ".json")
.then(data => data.json())
.then(data => {
// add the editing property
for (let contact of data.contacts)
this.$set(contact, 'editing', false)
this.project = data
})
Then, use that property in your template.
<section class="contacts-wrapper">
<!-- show static if editMode FALSE -->
<dl>
<dt>contacts:</dt>
<dd>
<ul class="contacts">
<li v-if="!contact.editing" v-for="(contact, ix) in project.contacts" v-bind:key="??">
{{ contact.name }}<br />
{{ contact.title }}<br />
{{ contact.email }}<br />
{{ contact.phone }}
<div class="buttons">
<button v-if="!contact.editing" id="edit-contact" v-on:click="contact.editing = true">edit</button>
<button v-if="contact.editing" v-on:click="contact.editing = false">cancel</button>
<button v-if="contact.editing" v-on:click="post">save changes</button>
</div>
</li>
</ul>
<!-- show FORM if editMode TRUE -->
<fieldset v-if="contact.edting">
...
</fieldset>
</dd>
</dl>
</section>
You can store editing contact's id and check that inside v-if.
If you stored the id of contact that is being edited in editingContactId then you can modify your code to this:
<ul class="contacts">
<li v-for="(contact, ix) in project.contacts" v-bind:key="??">
{{ contact.name }}<br />
{{ contact.title }}<br />
{{ contact.email }}<br />
{{ contact.phone }}
<div class="buttons">
<button v-if="editingContactId!=contact.id" id="edit-contact" v-on:click="editContact(contact, ix)">edit</button>
<button v-if="editingContactId==contact.id" v-on:click="cancelEdit">cancel</button>
<button v-if="editingContactId==contact.id" v-on:click="post">save changes</button>
</div>
</li>
</ul>
If it helps anyone, here's my revised, working solution (at least this reflects specifically what I was asking to achieve in my OP):
My component:
<template>
<div class="container" id="project-edit">
<section class="client-data">
<!-- show static if editMode FALSE -->
<dl v-if="!isEditingClient">
<!-- SNIP-->
</dl>
<!-- show FORM if editMode TRUE -->
<fieldset v-if="isEditingClient">
<!-- SNIP -->
</fieldset>
<div class="buttons">
<button v-if=!isEditingClient id="edit-client" v-on:click="editMode">edit</button>
<button v-if=isEditingClient v-on:click="cancelEdit">cancel</button>
<button v-if=isEditingClient v-on:click="post">save changes</button>
</div>
</section><!-- END .client-data -->
<section class="gig-data">
<!-- show static if editMode FALSE -->
<dl v-if="!isEditingGig">
<!-- SNIP-->
</dl>
<!-- show FORM if editMode TRUE -->
<fieldset v-if="isEditingGig">
<!-- SNIP-->
</fieldset>
<div class="buttons">
<button v-if=!isEditingGig id="edit-gig" v-on:click="editMode">edit</button>
<button v-if=isEditingGig v-on:click="cancelEdit">cancel</button>
<button v-if=isEditingGig v-on:click="post">save changes</button>
</div>
</section><!-- END .gig-data -->
<section class="contacts-wrapper">
<!-- show static if editMode FALSE -->
<dl>
<dt>contacts:</dt>
<dd>
<li v-for="(contact, ix) in project.contacts">
<!-- show orig data if editMode FALSE -->
<div v-if="!contact.editingContact">
{{ contact.name }} ({{ ix }})<br />
{{ contact.title }}<br />
{{ contact.email }}<br />
{{ contact.phone }}
<div class="buttons">
<button v-if=!contact.editingContact id="edit-contact" v-on:click="contact.editingContact = true">edit</button>
</div>
</div>
<!-- show FORM if editMode TRUE -->
<fieldset v-if="contact.editingContact">
<!-- SNIP: FORM ... -->
<div class="buttons">
<!-- I realize that the v-if attributes are not necessary here -->
<button v-if=contact.editingContact v-on:click="contact.editingContact = false">cancel</button>
<button v-if=contact.editingContact v-on:click="post">save changes</button>
</div>
</fieldset>
</li>
</dd>
</dl>
</section>
</div>
</template>
<script>
export default {
props: [ "projectID" ],
components: {
},
data () {
return {
id: this.$route.params.id,
title: "Edit Project",
subtitle: "ID: " + this.$route.params.id,
project: {},
contactInfo: {},
workLocation: true,
submitted: false,
isEditingClient: false,
isEditingGig: false,
}
}, // data
created: function() {
this.$http.get("https://xyz.dataworld.com/projects/" + this.id + ".json")
.then(data => data.json())
.then(data => {
for (let contact of data.contacts) {
this.$set(contact, 'editingContact', false)
}
this.project = data;
})
}, // created
methods: {
addContactInfo: function(e) {
e.preventDefault();
this.projectID = this.id;
this.project.contacts.push(this.contactInfo);
this.contactInfo = {};
},
editMode: function(e) {
const buttonID = e.currentTarget.id;
switch (buttonID) {
case "edit-client":
this.isEditingClient = !this.isEditingClient;
break;
case "edit-gig":
this.isEditingGig = !this.isEditingGig;
break;
default:
}
},
editContact: function(e) {
},
cancelEdit: function() {
this.isEditingClient = false;
this.isEditingGig = false;
},
post: function() {
console.log(this.project);
this.$http.post("https://sr-giglog.firebaseio.com/projects.json", this.project)
.then(function(data){
this.submitted = true;
}
)} // post function
} // methods
}
</script>
Now, if you'd all just stand by while I prepare my next twelve questions ...

Add class on click in vuejs

My vue template:
<div
class="col-sm-4 col-xs-6 thumb"
v-for="(photo, index) in photos"
#click.prevent="check(index)"
>
<a class="thumbnail" :class="{'active': photo.checked}">
<img class="img-responsive" :src="photo.picture" alt="">
</a>
</div>
My check() method:
check(index) {
if(!("checked" in this.photos[index]))
this.photos[index].checked = true
else
this.photos[index].checked = !this.photos[index].checked
},
Everything seems correct but it's not working. What could the problem be?
Vue cannot detect changes to an index of an array.
Get a reference to the photo object of the index passed to check() and then use Vue.set() to update the array like so:
check(index) {
let photo = this.photos[index];
if (!("checked" in photo)) {
photo.checked = true
} else {
photo.checked = !photo.checked
}
Vue.set(this.photos, index, photo);
},
Here's a fiddle.
How about just #click.prevent="$set(photo, 'checked', !photo.checked)" and forget the handler?
<div class="col-sm-4 col-xs-6 thumb" v-for="(photo, index) in photos"
#click.prevent="$set(photo, 'checked', !photo.checked)">
<a class="thumbnail" :class="{'active': photo.checked}">
<img class="img-responsive" :src="photo.picture" alt="">
</a>
</div>
If you want to use the handler:
<div class="col-sm-4 col-xs-6 thumb" v-for="(photo, index) in photos"
#click.prevent="check(photo)">
And
check(photo) {
this.$set(photo, 'checked', !photo.checked)
},

Selenuim/Protractor can't find or click in textbox

I have a code from a website as follows and I want to use the 5th line from code segment below <input type="text" placeholder="Enter Workflow Name"
Code
<div class="workflow-container ng-scope" data-ng-controller="sourceCode.Designer.uiComponents.conciergeScreen.templates.NewWorkflowController">
<div class="input">
<div class="wrapper top" data-ng-class="{'fill': hosted === true}">
<label class="welcome">What should your workflow be called?</label>
<input type="text" placeholder="Enter Workflow Name" class="workflow-name-textbox ng-valid ng-not-empty ng-touched ng-dirty ng-valid-parse" data-ng-class="{'error': errors.error}" autofocus="" data-ng-focus="select($event)" data-ng-model="conciergetitle" data-ng-model-options="{ updateOn: 'default blur', debounce: { default: 300, blur: 300 } }" data-ng-change="inputchange(designeritems)" data-ng-keyup="$event.keyCode == 13 && createnewstudioitem(designerItems[0], conciergetitle, $event)" style="">
<div class="errogory">
<div class="summary">
<!-- ngIf: errors.error || errors.category -->
</div>
<div class="category" data-ng-click="categorypicker($event)">
<label>Folder</label>
<i class="icon icon-set-assetbrowser icon-size16 ic-categoryserver"></i>
Workflow
</div>
</div>
<div class="concierge-button-grid">
<div class="concierge-button-container">
<button id="createWorkflow" data-button-error="false" class="concierge-button button-command" data-ng-disabled="!newWorkflowReady" data-ng-class="{ 'error': errors.button, 'is-disabled error' : errors.button }" data-ng-click="createnewstudioitem(designerItems[0], conciergetitle, $event)" disabled="disabled">
<!-- ngIf: !errors.button --><span data-ng-bind="getString('new_workflow_create_button')" data-ng-if="!errors.button" class="ng-binding ng-scope">Create</span><!-- end ngIf: !errors.button -->
<!-- ngIf: errors.button -->
</button>
</div>
<div class="concierge-button-container">
<button id="discardWorkflow" class="concierge-button concierge-button-discard button-command tertiary" data-ng-click="discard()">
<span data-ng-bind="getString('discard_workflow_button')" class="ng-binding">Discard</span>
</button>
</div>
</div>
</div>
<!-- ngIf: showrecent -->
<!-- ngIf: showrecent -->
</div>
I want to click in the textbox so that I can clear the text. I have tried the following:
describe("New Screen", function () {
it("Should give textbox a new name", function () {
browser.sleep(10000);
console.log('Enter new name');
var editName = element.all(by.className('.workflow-name-textbox'));
editName.first().click().then(function () {
console.log('Clicked on Create');
})
browser.sleep(10000);
})
I get a error: Index out of bound. Trying to access element at index: 0 ...
if I change my code above to:
var editName = element.all(by.css('.workflow-name-textbox'));
editName.click().then(function () {
console.log('Clicked on Create');
I dont get errors but I dont see any clicking going on.
I know my protractor works because I have navigated to this page using similar code.
Do anyone have suggestions what else I could try.
I had to go two iFrames down:
//Parent
browser.switchTo().frame('Iframe1');
//Child
browser.switchTo().frame('Iframe2');
//var NewTextBox = browser.findElement(by.css('.name-textbox')).clear();
var NewTextBox = element.all(by.css('.name-textbox'));
NewTextBox.clear().then(function () {
console.log('Clear text');
Did you tried this way instead of element.all.
element.all return a list elemenet and element return only single element.
var NewTextBox = element(by.css('.workflow-name-textbox'));
or
var NewTextBox = element(by.xpath('//input[#placeholder='Enter Workflow Name']'));

Why I can not see the data in an input field when I use the knockout with: binding

I want to make a dynamic dialog box. For that I need some data like title, content and viewmodel. The title and the content will be shown. But the viewmodel not bind correctly. To see the problem, I prefilled the first_name with 'foo'. But it should be 'my first name'.
To make the modal dialog dynamic, we have a modalDialog object that must be filled with the specific data. The openDialog function fill this data and open it.
Normally the dynamic part will be load by requirejs. For demonstrate the problem, I have made it here much easier.
Here the html code:
<!-- the dynamic modal dialog -->
<div id="modal-dialog" class="modal fade" role="dialog" data-backdrop="static" data-bind="css: modalDialog.classes">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-bind="click: modalDialog.close">×</button>
<h4 class="modal-title" data-bind="html: modalDialog.title"></h4>
</div>
<div data-bind="with: modalDialog.viewModel">
<div class="modal-body" data-bind="html: $parent.modalDialog.content"></div>
</div>
<div class="modal-footer" data-bind="foreach: modalDialog.buttons">
<button type="button" class="btn btn-primary" data-bind="click: action, text: label"></button>
</div>
</div>
</div>
</div>
<!-- Test button for open the dialog -->
<button type="button" class="btn btn-info" data-bind="click: testDialog">Open modal</button>
Here the javascript code for the modal dialog viewmodel:
// the main viewmodel
var appVM = {
modalDialog:
{
title: ko.observable(''),
content: ko.observable(''),
viewModel: ko.observable(this),
buttons: ko.observableArray([]),
classes: ko.observable(''),
open: function()
{
$("#modal-dialog").modal('show');
},
close: function()
{
$("#modal-dialog").modal('hide');
}
},
openDialog: function(title, content, viewModel, buttons, classes)
{
if (!viewModel)
viewModel = appVM;
if (!buttons)
buttons = [{action: appVM.modalDialog.close, label: 'Close'}];
if (!classes)
classes = '';
appVM.modalDialog.title(title);
appVM.modalDialog.content(content);
appVM.modalDialog.buttons(buttons);
appVM.modalDialog.classes(classes);
appVM.modalDialog.viewModel(viewModel);
appVM.modalDialog.open();
},
testDialog: function()
{
var vm = new userViewModel();
var title = 'Test Title';
var html = dialogContent;
var buttons = [
{ action: vm.onSave, label: 'Apply' },
{ action: appVM.modalDialog.close, label: 'Cancel' }
];
appVM.openDialog(title, html, vm, buttons);
}
};
ko.applyBindings(appVM);
At least the code for the dynamic data:
// the user data
function User(data)
{
var self = this;
self.first_name = ko.observable(data.first_name).extend({required: true});
self.last_name = ko.observable(data.last_name).extend({required: true});
}
// the user viewmodel
function userViewModel()
{
var self = this;
self.user = ko.observable(new User(
{
first_name: 'my first name',
last_name: 'my last name'
}));
self.onSave = function()
{
alert('save data');
};
}
// The loaded content for the dialog
var dialogContent = ' \
<div class="clearfix"> \
<div class="col-xs-12"> \
<div class="row form-group"> \
<label class="col-xs-12 col-sm-4 col-md-3">Vorname:</label> \
<input class="col-xs-12 col-sm-8 col-md-9" type="text" data-bind="textInput: user().first_name" title="" value="foo"/> \
</div> \
<div class="row form-group"> \
<label class="col-xs-12 col-sm-4 col-md-3">Nachname:</label> \
<input class="col-xs-12 col-sm-8 col-md-9" type="text" data-bind="textInput: user().last_name" title=""/> \
</div> \
</div> \
</div> \
';
You can try it here:
http://jsfiddle.net/p8zbfw65/
Update
With the Tip from Roy it works like expected. I inserted the boundHtml binding
ko.bindingHandlers.boundHtml = {
update: function(element, valueAccessor, allBindings, viewModel, bindingContext) {
const contentHtml = ko.unwrap(valueAccessor());
element.innerHTML = contentHtml;
ko.applyBindingsToDescendants(bindingContext, element)
}
};
and changed the html: $parent.modalDialog.content
to boundHtml: $parent.modalDialog.content
The html binding inserts HTML but does not apply bindings to it. You will need a custom binding handler to do that. I wrote a simple one here.

Forms in Pop yii

I tried to insert a form in Pop up..I used the partial method to redirect it.
I written the pop up code in my controller action.
And I need to insert a form there which I created through GII.
A got an out put but the form is outside the Pop Up..
Can anybody tell me hoe can I Achieve this....
Controller
public function actionpopup($id)
{
//$this->render('/offerEvents/Details',array(
//'model'=>OfferEvents::model()->findByAttributes(array('id'=>$id)), ));
$OfferEventsList = OfferEvents::model()->findAllByAttributes(array('id' => $id));
foreach($OfferEventsList as $Listdata)
{ $titnw=$Listdata['title']; $details=$Listdata['description'];
$discountper=$Listdata['discountper']; $discountperamt=$Listdata['discountperamt'];
$strdaate=$Listdata['startdate']; $enddaate=$Listdata['enddate']; $evoftype=$Listdata['type']; }
$cmuserid=$Listdata['createdby'];
if($Listdata['createdby']==0){ $createdbyname="Admin"; } else { $createdbyname=$Listdata->company->companyname; }
$locationnw=$Listdata->location;
$offrimage=$Listdata->image;
if($offrimage!=""){ $imgUrls=$offrimage; } else { $imgUrls='image-not-available.png'; }
$infowinimgpaths='theme/images/OfferEvents/orginal/'.$imgUrls;
if (file_exists($infowinimgpaths)) { $infowinimgpathSrcs=Yii::app()->baseUrl.'/'.$infowinimgpaths; } else
{ $infowinimgpathSrcs=Yii::app()->baseUrl.'/theme/images/OfferEvents/image-not-available.png'; }
if (Yii::app()->user->id!='' && Yii::app()->user->id!=1){
$subcribeemailid=Yii::app()->user->email; $logsts=1;
$countsubscribe = Newsfeeds::model()->countByAttributes(array('emailid' => $subcribeemailid,'cuserid' => $cmuserid));
} else { $subcribeemailid=''; $countsubscribe=0; $logsts=0; }
$PopupdetailText='<div class="modal-dialog-1">
<div class="modal-content">
<div class="modal-header login_modal_header">
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
<h2 class="modal-title" id="myModalLabel">'.$titnw.' </h2>
</div>
<div class="container-1">
<div class="row">
<div class="col-sm-7 detail-text">
<h2 class="title"> ';
if($evoftype==0){ $PopupdetailText.='Offer Price: '.$discountperamt.'
<font style="font-size: 15px;">[ Up To '.$discountper.'% Discount ]</font>'; }
$PopupdetailText.='</h2><p>Details: </p>
<p>'.$details.'</p>
<p>Location: '.$locationnw.'</p>
<p>Expires in: '.$enddaate.'</p>';
if($countsubscribe==0){
$PopupdetailText.='<p>Shared by: '.$createdbyname.'
<button type="button" class="btn btn-success btn-xs" Onclick="subcribefeed('.$logsts.','.$cmuserid.')" >Subscribe NewsFeed</button></p>';
} else {
$PopupdetailText.='<p>Shared by: '.$createdbyname.'
<button type="button" class="btn btn-success disabled btn-xs" >Already Subscribed NewsFeed</button></p>';
}
$PopupdetailText.='<div class="form-group" id="subcribefrm" style="display:none;background-color: #eee; padding: 12px; width: 82%;">
<input type="text" id="subemailid" placeholder="Enter EmailID here" value="'.$subcribeemailid.'" style="width: 100%;" class="form-control login-field">
<br/>
Subscribe Feeds </div> ';
// if($evoftype==0){ $PopupdetailText.='<p>Offer Price:<b> $'.$discountperamt.'</b></p>'; }
$PopupdetailText.='<p>
<img src="'.Yii::app()->baseUrl.'/theme/site/images/yes.png"/>Yes
<img src="'.Yii::app()->baseUrl.'/theme/site/images/no.png"/>No
<img src="'.Yii::app()->baseUrl.'/theme/site/images/comments.png"/>Comments
<img src="'.Yii::app()->baseUrl.'/theme/site/images/share.png"/>Share</p>
<br/>
<form>
<div class="form-group">';
$userComment=new Comments;
$this->renderPartial('/comments/_form', array('model' => $userComment));
$PopupdetailText.='</div>
<div class="form-group">
<input type="text" id="username" placeholder="Enter the below security code here" value="" class="form-control login-field">
</div>
<div class="form-group">
<p><img src="'.Yii::app()->baseUrl.'/theme/site/images/capcha.png"/>Cant read? Refresh</p>
</div>
<div class="form-group">
Post Commets
</div>
</form>
</div>
<div class="col-sm-5">
<img src="'.$infowinimgpathSrcs.'" width="100%"/>
</div>
</div>
</div>
<div class="clearfix"></div>
<div class="modal-footer login_modal_footer">
</div>
</div>
</div>
<script>
function subcribefeed(staus,cid)
{
if(staus==0){
$("#subcribefrm").toggle(); }
else { subcribefeedAdd(cid); }
}
function subcribefeedAdd(cid)
{
subusremail=$("#subemailid").val();
var re = /[A-Z0-9._%+-]+#[A-Z0-9.-]+.[A-Z]{2,4}/igm;
if (subusremail == "" || !re.test(subusremail))
{ alert("Invalid EmailID ."); }
else {
postData ={
"email" :subusremail,
"cid" :cid
}
$.ajax({
type: "POST",
data: postData ,
url: "'.Yii::app()->baseUrl.'/newsfeeds/create",
success: function(msg){
if(msg=="Success"){ showdetails('.$id.'); alert("news feed subscribe successfully."); }
else if(msg=="available"){ alert("Already subscribe News Feed for this Commercial user."); }
else { alert("Error ."); }
}
});
}
}
</script> ';
echo $PopupdetailText;
}
renderPartial has a 3rd parameter return. If you set that to TRUE it will return the rendered form instead of echoing it. You can use it as follows:
$PopupdetailText .= $this->renderPartial('/comments/_form', array('model' => $userComment), TRUE);