Update media adding, to allow youtube import, and display the thumbnail when we paste the youtube url.
authorcavaliet
Tue, 22 Mar 2011 12:35:29 +0100
changeset 46 ba02faf089df
parent 45 c3048a2c0758
child 51 28d35ffe83ab
child 55 2e2989c3072c
Update media adding, to allow youtube import, and display the thumbnail when we paste the youtube url.
src/ldt/ldt/ldt_utils/templates/ldt/ldt_utils/create_content.html
src/ldt/ldt/ldt_utils/views.py
src/ldt/ldt/locale/fr/LC_MESSAGES/django.mo
src/ldt/ldt/locale/fr/LC_MESSAGES/django.po
src/ldt/ldt/media/js/jquery.textchange.min.js
src/ldt/ldt/media/js/projectscontents.js
web/static/ldt/js/jquery.textchange.min.js
web/static/ldt/js/projectscontents.js
--- a/src/ldt/ldt/ldt_utils/templates/ldt/ldt_utils/create_content.html	Fri Mar 11 18:47:17 2011 +0100
+++ b/src/ldt/ldt/ldt_utils/templates/ldt/ldt_utils/create_content.html	Tue Mar 22 12:35:29 2011 +0100
@@ -8,6 +8,7 @@
     <script type="text/javascript" src="{{MEDIA_URL}}admin/js/core.js" ></script>
     <script type="text/javascript" src="{% url jsi18n %}" ></script>
     <script type="text/javascript" src="{{LDT_MEDIA_PREFIX}}js/jquery.nyroModal.min.js"></script>    
+    <script type="text/javascript" src="{{LDT_MEDIA_PREFIX}}js/jquery.textchange.min.js"></script>    
 	{{ content_form.media.js }}
 {% endblock %}
 
@@ -36,7 +37,28 @@
 			$(".media_fields").hide();
 			$("#media_field_"+$(e.target).val()).show();
 		});
+        // The textinput's id for external url is id_media-src
+        $('#id_media-src').bind('textchange', function(e) { testUrlValue(e); });
 	});
+    function testUrlValue(e){
+        // First, we remove the current thumbnail if there is one.
+        if($('#media_field_create').children().size()>2){
+            $('#external_thumbnail').remove();
+            $('#media_fields_div').height(50);
+        }
+        // If the pasted text is a youtube url, we get the default thumbnail of the video and display it.
+        url = $('#id_media-src').val();
+        if(url.match("youtube") && url.match("[\\?&]v=([^&#]*)")){
+            results = url.match("[\\?&]v=([^&#]*)");
+            vid = ( results === null ) ? url : results[1].substring(0,11);
+            if(vid.length===11){
+                //$('#id_content-description').val($('#media_field_create') + '<img src="http://img.youtube.com/vi/'+vid+'/default.jpg" alt="Youtube Thumbnail"/>');
+                $('#media_field_create').append('<img id="external_thumbnail" src="http://img.youtube.com/vi/'+vid+'/default.jpg" alt="Youtube Thumbnail"/>');
+                $('#media_fields_div').height(150);
+            }
+        }
+    }
+	
 	
     </script>
 {% endblock %}
--- a/src/ldt/ldt/ldt_utils/views.py	Fri Mar 11 18:47:17 2011 +0100
+++ b/src/ldt/ldt/ldt_utils/views.py	Tue Mar 22 12:35:29 2011 +0100
@@ -751,7 +751,7 @@
                 else:
                     media = None
 
-            if media and not created:                        
+            if media and not created:
                 for attribute in ('external_id', 'external_permalink', 'external_publication_url', 'external_src_url', 'media_creation_date', 'videopath', 'duration', 'description', 'title'):
                     setattr(media, attribute, cleaned_data.get(attribute))
                 mimetype = cleaned_data.get('mimetype_field',None)
Binary file src/ldt/ldt/locale/fr/LC_MESSAGES/django.mo has changed
--- a/src/ldt/ldt/locale/fr/LC_MESSAGES/django.po	Fri Mar 11 18:47:17 2011 +0100
+++ b/src/ldt/ldt/locale/fr/LC_MESSAGES/django.po	Tue Mar 22 12:35:29 2011 +0100
@@ -46,7 +46,7 @@
 
 #: .\ldt_utils\forms.py:44
 msgid "create_media"
-msgstr "source serveur de stream"
+msgstr "source externe : fichier streamé, statique, url youtube..."
 
 #: .\ldt_utils\forms.py:44
 msgid "none_media"
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/ldt/ldt/media/js/jquery.textchange.min.js	Tue Mar 22 12:35:29 2011 +0100
@@ -0,0 +1,10 @@
+/*!
+ * jQuery TextChange Plugin
+ * http://www.zurb.com/playground/jquery-text-change-custom-event
+ *
+ * Copyright 2010, ZURB
+ * Released under the MIT License
+ */
+ (function(a){a.event.special.textchange={setup:function(){a(this).data("lastValue",this.contentEditable==="true"?a(this).html():a(this).val());a(this).bind("keyup.textchange",a.event.special.textchange.handler);a(this).bind("cut.textchange paste.textchange input.textchange",a.event.special.textchange.delayedHandler)},teardown:function(){a(this).unbind(".textchange")},handler:function(){a.event.special.textchange.triggerIfChanged(a(this))},delayedHandler:function(){var b=a(this);setTimeout(function(){a.event.special.textchange.triggerIfChanged(b)},
+ 25)},triggerIfChanged:function(b){var c=b[0].contentEditable==="true"?b.html():b.val();if(c!==b.data("lastValue")){b.trigger("textchange",b.data("lastValue"));b.data("lastValue",c)}}};a.event.special.hastext={setup:function(){a(this).bind("textchange",a.event.special.hastext.handler)},teardown:function(){a(this).unbind("textchange",a.event.special.hastext.handler)},handler:function(b,c){c===""&&c!==a(this).val()&&a(this).trigger("hastext")}};a.event.special.notext={setup:function(){a(this).bind("textchange",
+ a.event.special.notext.handler)},teardown:function(){a(this).unbind("textchange",a.event.special.notext.handler)},handler:function(b,c){a(this).val()===""&&a(this).val()!==c&&a(this).trigger("notext")}}})(jQuery);
\ No newline at end of file
--- a/src/ldt/ldt/media/js/projectscontents.js	Fri Mar 11 18:47:17 2011 +0100
+++ b/src/ldt/ldt/media/js/projectscontents.js	Tue Mar 22 12:35:29 2011 +0100
@@ -138,7 +138,7 @@
         filters: ['iframe'],
         sizes: {
             minW: 770,
-            minH: 500
+            minH: 550
         },
         callbacks: {
             afterClose: function(nm) {
@@ -146,7 +146,7 @@
             },
             afterShowCont: function(nm) {
                 nm.store.iframe.width(770);
-                nm.store.iframe.height(500);
+                nm.store.iframe.height(550);
                 nm.store.iframe.load(function() {
                     var form_status = $(this).contents().find("#content_form_status").val(); 
                     if(form_status === 'saved' || form_status === 'deleted' ) {
@@ -164,7 +164,7 @@
         filters: ['iframe'],
         sizes: {
             minW: 770,
-            minH: 500
+            minH: 550
         },
         callbacks: {
             afterClose: function(nm) {
@@ -172,7 +172,7 @@
             },
             afterShowCont: function(nm) {
                 nm.store.iframe.width(770);
-                nm.store.iframe.height(500);
+                nm.store.iframe.height(550);
                 nm.store.iframe.load(function() {
                       var form_status = $(this).contents().find("#content_form_status").val(); 
                       if(form_status === 'saved' || form_status === 'deleted') {
@@ -240,7 +240,7 @@
         callbacks: {
             afterShowCont: function(nm) {
                 nm.store.iframe.width(600);
-                nm.store.iframe.height(500);
+                nm.store.iframe.height(600);
                 var iframe = nm.store.iframe;
                 iframe.load(function(){
                     var form_status = $(this).contents().find("#project_form_status").val(); 
@@ -311,7 +311,7 @@
         filters: ['iframe'],
         sizes: {
             minH:680, 
-            minW:500
+            minW:600
         },
         callbacks: {
             afterClose: function(nm) {
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/web/static/ldt/js/jquery.textchange.min.js	Tue Mar 22 12:35:29 2011 +0100
@@ -0,0 +1,10 @@
+/*!
+ * jQuery TextChange Plugin
+ * http://www.zurb.com/playground/jquery-text-change-custom-event
+ *
+ * Copyright 2010, ZURB
+ * Released under the MIT License
+ */
+ (function(a){a.event.special.textchange={setup:function(){a(this).data("lastValue",this.contentEditable==="true"?a(this).html():a(this).val());a(this).bind("keyup.textchange",a.event.special.textchange.handler);a(this).bind("cut.textchange paste.textchange input.textchange",a.event.special.textchange.delayedHandler)},teardown:function(){a(this).unbind(".textchange")},handler:function(){a.event.special.textchange.triggerIfChanged(a(this))},delayedHandler:function(){var b=a(this);setTimeout(function(){a.event.special.textchange.triggerIfChanged(b)},
+ 25)},triggerIfChanged:function(b){var c=b[0].contentEditable==="true"?b.html():b.val();if(c!==b.data("lastValue")){b.trigger("textchange",b.data("lastValue"));b.data("lastValue",c)}}};a.event.special.hastext={setup:function(){a(this).bind("textchange",a.event.special.hastext.handler)},teardown:function(){a(this).unbind("textchange",a.event.special.hastext.handler)},handler:function(b,c){c===""&&c!==a(this).val()&&a(this).trigger("hastext")}};a.event.special.notext={setup:function(){a(this).bind("textchange",
+ a.event.special.notext.handler)},teardown:function(){a(this).unbind("textchange",a.event.special.notext.handler)},handler:function(b,c){a(this).val()===""&&a(this).val()!==c&&a(this).trigger("notext")}}})(jQuery);
\ No newline at end of file
--- a/web/static/ldt/js/projectscontents.js	Fri Mar 11 18:47:17 2011 +0100
+++ b/web/static/ldt/js/projectscontents.js	Tue Mar 22 12:35:29 2011 +0100
@@ -138,7 +138,7 @@
         filters: ['iframe'],
         sizes: {
             minW: 770,
-            minH: 500
+            minH: 550
         },
         callbacks: {
             afterClose: function(nm) {
@@ -146,7 +146,7 @@
             },
             afterShowCont: function(nm) {
                 nm.store.iframe.width(770);
-                nm.store.iframe.height(500);
+                nm.store.iframe.height(550);
                 nm.store.iframe.load(function() {
                     var form_status = $(this).contents().find("#content_form_status").val(); 
                     if(form_status === 'saved' || form_status === 'deleted' ) {
@@ -164,7 +164,7 @@
         filters: ['iframe'],
         sizes: {
             minW: 770,
-            minH: 500
+            minH: 550
         },
         callbacks: {
             afterClose: function(nm) {
@@ -172,7 +172,7 @@
             },
             afterShowCont: function(nm) {
                 nm.store.iframe.width(770);
-                nm.store.iframe.height(500);
+                nm.store.iframe.height(550);
                 nm.store.iframe.load(function() {
                       var form_status = $(this).contents().find("#content_form_status").val(); 
                       if(form_status === 'saved' || form_status === 'deleted') {
@@ -240,7 +240,7 @@
         callbacks: {
             afterShowCont: function(nm) {
                 nm.store.iframe.width(600);
-                nm.store.iframe.height(500);
+                nm.store.iframe.height(600);
                 var iframe = nm.store.iframe;
                 iframe.load(function(){
                     var form_status = $(this).contents().find("#project_form_status").val(); 
@@ -311,7 +311,7 @@
         filters: ['iframe'],
         sizes: {
             minH:680, 
-            minW:500
+            minW:600
         },
         callbacks: {
             afterClose: function(nm) {