Permalink
Browse files

Vish.Editor.Object module

  • Loading branch information...
1 parent b58867b commit e52d409a00a2a7329db7fa117fa37594885c5a78 @agordillo agordillo committed Apr 16, 2012
View
@@ -236,7 +236,7 @@
</div>
<div id="tab_flash_repo_content_preview_metadata"></div>
<div id="tab_flash_repo_content_preview_foot">
- <button type="button" class="okButton" onclick="VISH.Editor.Flash.Repository.addSelectedFlash()">Add</button>
+ <button type="button" class="okButton" onclick="VISH.Editor.Object.Repository.addSelectedObject()">Add</button>
</div>
</div>
</div>
@@ -327,8 +327,9 @@
<script type="text/javascript" src="js/VISH.Editor.Image.js"></script>
<script type="text/javascript" src="js/VISH.Editor.Image.Repository.js"></script>
<script type="text/javascript" src="js/VISH.Editor.Image.Flikr.js"></script>
- <script type="text/javascript" src="js/VISH.Editor.Flash.js"></script>
- <script type="text/javascript" src="js/VISH.Editor.Flash.Repository.js"></script>
+ <script type="text/javascript" src="js/VISH.Editor.Object.js"></script>
+ <script type="text/javascript" src="js/VISH.Editor.Object.Flash.js"></script>
+ <script type="text/javascript" src="js/VISH.Editor.Object.Repository.js"></script>
<script type="text/javascript" src="js/VISH.Editor.Text.js"></script>
<script type="text/javascript" src="js/VISH.Editor.API.js"></script>
<script type="text/javascript" src="js/VISH.Editor.SlidesUtilities.js"></script>
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@@ -1,20 +1,8 @@
-VISH.Editor.Flash = (function(V,$,undefined){
-
- var init = function(){
- VISH.Editor.Flash.Repository.init();
- var urlInput = $("#tab_flash_from_url_content").find("input.url");
- $(urlInput).watermark('Paste SWF file URL');
- var uploadInput = $("#tab_flash_upload_content").find("input.upload");
- $(uploadInput).watermark('Select SWF file to upload');
- }
+VISH.Editor.Object.Flash = (function(V,$,undefined){
- var onLoadTab = function(tab){
+ var drawFlashObjectWithSource = function(src){
- }
-
-
- var drawFlashObject = function(src){
var current_area = VISH.Editor.getCurrentArea();
var template = VISH.Editor.getTemplate();
@@ -51,29 +39,15 @@ VISH.Editor.Flash = (function(V,$,undefined){
dimension: "x",
skin: "blue",
onstatechange: function( value ){
- _resizeObject(idToResize,325*value);
+ VISH.Editor.Object.resizeObject(idToResize,325*value);
}
});
$("#" + idToDrag).draggable({cursor: "move"});
}
-
- /*
- * Resize object and its wrapper automatically
- */
- var _resizeObject = function(id,width){
- $("#" + id).width(width);
- var height = $("#" + id).height();
-
- var parent = $("#" + id).parent();
- $(parent).width(width);
- $(parent).height(height);
- }
return {
- init: init,
- onLoadTab: onLoadTab,
- drawFlashObject : drawFlashObject
+ drawFlashObjectWithSource : drawFlashObjectWithSource
};
}) (VISH, jQuery);
@@ -1,16 +1,16 @@
-VISH.Editor.Flash.Repository = (function(V,$,undefined){
+VISH.Editor.Object.Repository = (function(V,$,undefined){
var carrouselDivId = "tab_flash_repo_content_carrousel";
var previewDivId = "tab_flash_repo_content_preview";
- var currentFlash = new Array();
- var selectedFlash = null;
+ var currentObject = new Array();
+ var selectedObject = null;
var init = function(){
var myInput = $("#tab_flash_repo_content").find("input[type='search']");
$(myInput).watermark('Search content');
$(myInput).keydown(function(event) {
if(event.keyCode == 13) {
- VISH.Editor.Flash.Repository.requestData($(myInput).val());
+ _requestData($(myInput).val());
$(myInput).blur();
}
});
@@ -19,7 +19,7 @@ VISH.Editor.Flash.Repository = (function(V,$,undefined){
var onLoadTab = function(){
var previousSearch = ($("#tab_flash_repo_content").find("input[type='search']").val()!="");
if(! previousSearch){
- _renderFlashPreview(null);
+ _renderObjectPreview(null);
_requestInicialData();
}
}
@@ -28,14 +28,14 @@ VISH.Editor.Flash.Repository = (function(V,$,undefined){
* Request inicial data to the server.
*/
var _requestInicialData = function(){
- VISH.Editor.API.requestRecomendedFlash(VISH.Editor.Flash.Repository.onDataReceived,VISH.Editor.Flash.Repository.onAPIError);
+ VISH.Editor.API.requestRecomendedFlash(VISH.Editor.Object.Repository.onDataReceived,VISH.Editor.Object.Repository.onAPIError);
}
/*
* Request data to the server.
*/
- var requestData = function(text){
- VISH.Editor.API.requestFlashes(text,VISH.Editor.Flash.Repository.onDataReceived,VISH.Editor.Flash.Repository.onAPIError);
+ var _requestData = function(text){
+ VISH.Editor.API.requestFlashes(text,VISH.Editor.Object.Repository.onDataReceived,VISH.Editor.Object.Repository.onAPIError);
}
/*
@@ -46,22 +46,39 @@ VISH.Editor.Flash.Repository = (function(V,$,undefined){
//Clean previous content
VISH.Editor.Carrousel.cleanCarrousel(carrouselDivId);
- //Clean previous flash
- currentFlash = new Array();
+ //Clean previous object
+ currentObject = new Array();
var content = "";
- $.each(data, function(index, flash) {
- //Flash preview... [flashid]
- content = content + "<div style='width:150px' flashid='" + flash.id + "' class='carrousel_object_wrapper'>" + flash.content + "</div>"
- currentFlash[flash.id]=flash;
+ $.each(data, function(index, object) {
+ var objectInfo = VISH.Editor.Object.getObjectInfo(object.content)
+ var imageSource = null;
+
+ switch (objectInfo.type){
+ case "swf":
+ imageSource = "/images/carrousel/swf.png"
+ break;
+ case "youtube":
+ imageSource = "/images/carrousel/youtube.png"
+ break;
+ case "html":
+ imageSource = "/images/carrousel/iframe.png"
+ break;
+ default:
+ imageSource = "/images/carrousel/object.jpeg"
+ break;
+ }
+
+ content = content + "<img src='" + imageSource + "' objectId='" + object.id + "'>"
+ currentObject[object.id]=object;
});
$("#" + carrouselDivId).html(content);
$(".carrousel_object_wrapper").children().addClass("carrousel_object");
_autoResizeObjects();
- VISH.Editor.Carrousel.createCarrousel(carrouselDivId,1,VISH.Editor.Flash.Repository.onClickCarrouselElement);
+ VISH.Editor.Carrousel.createCarrousel(carrouselDivId,1,VISH.Editor.Object.Repository.onClickCarrouselElement);
}
var onAPIError = function(){
@@ -71,22 +88,22 @@ VISH.Editor.Flash.Repository = (function(V,$,undefined){
var onClickCarrouselElement = function(event){
- var flashId = $(event.target).attr("flashid");
-// var renderedFlash = VISH.Renderer.renderFlash(currentFlash[flashId],"preview");
-// _renderFlashPreview(renderedFlash,currentFlash[flashId]);
- selectedFlash = currentFlash[flashId];
- addSelectedFlash();
+ var objectId = $(event.target).attr("objectid");
+// var renderedObject = VISH.Renderer.renderObject(currentObject[objectId],"preview");
+// _renderObjectPreview(renderedObject,currentObject[objectId]);
+ selectedObject = currentObject[objectId];
+ addSelectedObject();
}
- var _renderFlashPreview = function(renderedFlash,flash){
-// var flashArea = $("#" + previewDivId).find("#tab_flash_repo_content_preview_flash");
+ var _renderObjectPreview = function(renderedObject,object){
+// var objectArea = $("#" + previewDivId).find("#tab_flash_repo_content_preview_flash");
// var metadataArea = $("#" + previewDivId).find("#tab_flash_repo_content_preview_metadata");
-// $(flashArea).html("");
+// $(objectArea).html("");
// $(metadataArea).html("");
-// if((renderedFlash)&&(flash)){
-// $(flashArea).append(renderedFlash);
-// var table = _generateTable(flash.author,flash.title,flash.description);
+// if((renderedObject)&&(object)){
+// $(objectArea).append(renderedObject);
+// var table = _generateTable(object.author,object.title,object.description);
// $(metadataArea).html(table);
// }
}
@@ -128,12 +145,12 @@ VISH.Editor.Flash.Repository = (function(V,$,undefined){
}
- var addSelectedFlash = function(){
- if(selectedFlash!=null){
- var content = $(selectedFlash.content)
+ var addSelectedObject = function(){
+ if(selectedObject!=null){
+ var content = $(selectedObject.content)
var src = _getSourceFromObject(content)
if(src){
- VISH.Editor.Flash.drawFlashObject(src);
+ VISH.Editor.Object.drawObject(src);
}
$.fancybox.close();
}
@@ -152,10 +169,9 @@ VISH.Editor.Flash.Repository = (function(V,$,undefined){
return {
init : init,
onLoadTab : onLoadTab,
- requestData : requestData,
onDataReceived : onDataReceived,
onAPIError : onAPIError,
- addSelectedFlash : addSelectedFlash,
+ addSelectedObject : addSelectedObject,
onClickCarrouselElement : onClickCarrouselElement
};
@@ -0,0 +1,125 @@
+VISH.Editor.Object = (function(V,$,undefined){
+
+ var init = function(){
+ VISH.Editor.Object.Repository.init();
+ var urlInput = $("#tab_flash_from_url_content").find("input.url");
+ $(urlInput).watermark('Paste SWF file URL');
+ var uploadInput = $("#tab_flash_upload_content").find("input.upload");
+ $(uploadInput).watermark('Select SWF file to upload');
+ }
+
+ var onLoadTab = function(){
+ }
+
+ var drawObject = function(object){
+ var objectInfo = getObjectInfo(object);
+
+ switch (objectInfo.wrapper){
+ case null:
+ //Draw object from source
+
+ switch (objectInfo.type){
+ case "swf":
+ V.Editor.Object.Flash.drawFlashObjectWithSource(object);
+ break;
+ case "youtube":
+ //V.Editor.Video.Youtube.drawVideoObject(object);
+ break;
+ default:
+ console.log("Unrecognized object source type: " + objectInfo.type)
+ break;
+ }
+
+ case "EMBED":
+ break;
+ case "OBJECT":
+ break;
+ case "IFRAME":
+ break;
+ default:
+ console.log("Unrecognized object wrapper: " + objectInfo.wrapper)
+ break;
+ }
+ }
+
+
+ /*
+ * Wrapper can be: "embed","object, "iframe" or null if the object is a source url without wrapper.
+ * Type is the source type and can be: "swf" , "youtube" , etc.
+ *
+ */
+ function objectInfo(wrapper,sourceType) {
+ this.wrapper=wrapper;
+ this.type=sourceType;
+ }
+
+ /*
+ * Return object type
+ */
+ var getObjectInfo = function(object){
+ var wrapper = null;
+
+ //Determine wrapper
+ var element = $(object)[0];
+ if(typeof element != 'undefined'){
+ var wrapper = element.tagName;
+ }
+
+ //Determine source type
+ var source = _getSourceFromObject(object,wrapper);
+ var type = _getTypeFromSource(source);
+
+ return new objectInfo(wrapper,type);
+ }
+
+ var _getSourceFromObject = function (object,wrapper){
+ switch (wrapper){
+ case null:
+ return object;
+ case "EMBED":
+ return $(object).attr("src");
+ case "OBJECT":
+ if (typeof $(object).attr("src") != 'undefined'){
+ return $(object).attr("src");
+ }
+ if (typeof $(object).attr("data") != 'undefined'){
+ return $(object).attr("data");
+ }
+ return "source not founded";
+ case "IFRAME":
+ return $(object).attr("src");
+ default:
+ console.log("Unrecognized object wrapper: " + wrapper)
+ break;
+ }
+ }
+
+ var _getTypeFromSource = function(source){
+ if(typeof source != "string"){
+ return "Invalid source"
+ }
+ return source.split('.').pop();
+ }
+
+ /*
+ * Resize object and its wrapper automatically
+ */
+ var resizeObject = function(id,width){
+ $("#" + id).width(width);
+ var height = $("#" + id).height();
+
+ var parent = $("#" + id).parent();
+ $(parent).width(width);
+ $(parent).height(height);
+ }
+
+
+ return {
+ init : init,
+ onLoadTab : onLoadTab,
+ drawObject : drawObject,
+ getObjectInfo : getObjectInfo,
+ resizeObject : resizeObject
+ };
+
+}) (VISH, jQuery);
View
@@ -41,7 +41,7 @@ VISH.Editor = (function(V,$,undefined){
V.Debugging.init(true);
V.Editor.Text.init();
V.Editor.Video.init();
- V.Editor.Flash.init();
+ V.Editor.Object.init();
//Remove overflow from fancybox
// $($("#fancybox-content").children()[0]).css('overflow','hidden')
@@ -134,13 +134,13 @@ VISH.Editor = (function(V,$,undefined){
//Flash
case "tab_flash_from_url":
- VISH.Editor.Flash.onLoadTab("url");
+ VISH.Editor.Object.onLoadTab("url");
break;
case "tab_flash_upload":
- VISH.Editor.Flash.onLoadTab("upload");
+ VISH.Editor.Object.onLoadTab("upload");
break;
case "tab_flash_repo":
- VISH.Editor.Flash.Repository.onLoadTab();
+ VISH.Editor.Object.Repository.onLoadTab();
break;
@@ -163,7 +163,7 @@ VISH.Editor = (function(V,$,undefined){
V.Editor.Image.drawImage($("#"+id_to_get).val());
break;
case "flash_embed_code":
- V.Editor.Flash.drawFlashObject($("#"+id_to_get).val())
+ V.Editor.Object.drawObject($("#"+id_to_get).val())
break;
case "video_url":
V.Editor.Video.HTML5.drawVideoWithUrl($("#"+id_to_get).val())
Oops, something went wrong.

0 comments on commit e52d409

Please sign in to comment.