meteor - Reinitialize library when new data is available -
i'm developing meteor application use video.js-library.
i have following template:
template(name='foo') .video.embed-responsive.embed-responsive-16by9 richmediacontent video#video.video-js.vjs-default-skin.vjs-big-play-centered(controls='' preload='auto') source(src='{{video.videourl}}' type='video/mp4') p.vjs-no-js {{i18n 'videotagnotsupported'}}
initializing video.js-library after template rendered works fine.
template.foo.onrendered -> videojs document.getelementsbyclassname('video-js')[0], {}
but videojs-library not reinitialized if same template rendered different video (with different richmediacontent).
i've tried move video-part in own template , included in foo-template onrendered-call should called every time new video loaded. doesn't seem work.
do have idea how can reinitialize library if video changes?
thanks in advance!
new answer
indeed, when route changes uses same template, said template not rendered again, therefore js plugin call not trigger second time. can instead call js plugin in onafteraction
call, within route definition:
router.route('/video/:_id', { name: 'video_page', template: 'foo', // ... onafteraction: function () { videojs document.getelementsbyclassname('video-js')[0], {} } });
previous answer
i think looking almighty this.autorun
. @ end of onrendered function, should (i type in pure javascript)
this.autorun(function () { var video = session.get("video"); // reactive data videojs document.getelementsbyclassname('video-js')[0], {} });
the idea first line must include, within autorun function, way reactive data. in case, use session reactive. collections reactive, way videos.findone();
. depend on how you video
element.
what time reactive data changes, callback this.autorun
run again, , video plugin reset.
Comments
Post a Comment