Good day, 

I am working on this jira : 

http://opencast.jira.com/browse/MH-7135?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel#issue-tabs


Is there a coding style that I can refer to? I am rather new to the
community so I went through some of the code first to see the general
coding style. For example with the engage-ui.js code and all other
engage code that I looked at, the style is as follows: 

Opencast.engage = (function () 
{ 
    var loadProgressPercent = -1; 

    /** 
     * @memberOf Opencast.engage 
     * @description Gets player type ("watch" or "embed") 
     * @return the player type 
     */ 
    function getPlayerType() 
    { 
        var pathname = window.location.pathname; 
        return pathname; 
    } 

    /** 
     * @memberOf Opencast.engage 
     * @description Gets the url to the search service; 
     * @return the search service endpoint url 
     */ 
    function getSearchServiceEpisodeIdURL() 
    { 
        var restEndpoint = "../../search/episode.xml?id="; //
Production 
        //var restEndpoint = "xml/episode.xml?id="; // Activate for
testing purposes 
        //var restEndpoint = "episode-segments.xml?id="; // Activate
for testing purposes 
        return restEndpoint; 
    } 

    function getSearchServiceEpisodeJsonURL() 
    { 
        var restEndpoint = "../../search/episode.json"; // Production 
        return restEndpoint; 
    } 

    /** 
     * @memberOf Opencast.engage 
     * @description Gets the current load progress 
     * @return The current load progress 
     */ 
    function getLoadProgress() 
    { 
        if (loadProgressPercent === -1) return -1; 
        else 
        { 
            var duration = Opencast.Player.getDuration(); 
            return duration * loadProgressPercent / 100; 
        } 
    } 

    /** 
     * @memberOf Opencast.engage 
     * @description Sets the current load progress 
     * @param The current load progress 
     */ 
    function setLoadProgressPercent(value) 
    { 
        if (0 <= value && value <= 100) 
        { 
            loadProgressPercent = value; 
        } 
    } 

    /** 
     * @memberOf Opencast.engage 
     * @description Returns a specific Cookie 
     * @param name Name of the Cookie to return 
     * @return a specific Cookie with the Name 'name' 
     */ 
    function getCookie(name) 
    { 
        var start = document.cookie.indexOf(name + "="); 
        var len = start + name.length + 1; 
        if ((!start) && (name != document.cookie.substring(0,
name.length))) 
        { 
            return null; 
        } 
        if (start == -1) return null; 
        var end = document.cookie.indexOf(';', len); 
        if (end == -1) end = document.cookie.length; 
        return unescape(document.cookie.substring(len, end)); 
    } 

    return { 
        getCookie: getCookie, 
        getPlayerType: getPlayerType, 
        getLoadProgress: getLoadProgress, 
        setLoadProgressPercent: setLoadProgressPercent, 
        getSearchServiceEpisodeIdURL: getSearchServiceEpisodeIdURL, 
        getSearchServiceEpisodeJsonURL: getSearchServiceEpisodeJsonURL

    }; 
}()); 

Functions are defined at the top and then an object literal is returned
at the end with all the members. Although this code works fine is there
a reason why we are not implementing it as follows: 

Opencast.engage = (function () 
{ 
    var loadProgressPercent = -1, 
        that = {}; 

    /** 
     * @memberOf Opencast.engage 
     * @description Gets player type ("watch" or "embed") 
     * @return the player type 
     */ 
    that.getPlayerType = function(){ 
        var pathname = window.location.pathname; 
        return pathname; 
    }; 

    /** 
     * @memberOf Opencast.engage 
     * @description Gets the url to the search service; 
     * @return the search service endpoint url 
     */ 
    that.getSearchServiceEpisodeIdURL = function(){ 
        var restEndpoint = "../../search/episode.xml?id="; //
Production 
        //var restEndpoint = "xml/episode.xml?id="; // Activate for
testing purposes 
        //var restEndpoint = "episode-segments.xml?id="; // Activate
for testing purposes 
        return restEndpoint; 
    }; 

    that.getSearchServiceEpisodeJsonURL = function(){ 
        var restEndpoint = "../../search/episode.json"; // Production 
        return restEndpoint; 
    }; 

    /** 
     * @memberOf Opencast.engage 
     * @description Gets the current load progress 
     * @return The current load progress 
     */ 
    that.getLoadProgress = function(){ 
        if (loadProgressPercent === -1) return -1; 
        else 
        { 
            var duration = Opencast.Player.getDuration(); 
            return duration * loadProgressPercent / 100; 
        } 
    }; 

    /** 
     * @memberOf Opencast.engage 
     * @description Sets the current load progress 
     * @param The current load progress 
     */ 
    that.setLoadProgressPercent = function(value){ 
        if (0 <= value && value <= 100) 
        { 
            loadProgressPercent = value; 
        } 
    }; 

    /** 
     * @memberOf Opencast.engage 
     * @description Returns a specific Cookie 
     * @param name Name of the Cookie to return 
     * @return a specific Cookie with the Name 'name' 
     */ 
    that.getCookie = function(name){ 
        var start = document.cookie.indexOf(name + "="); 
        var len = start + name.length + 1; 
        if ((!start) && (name != document.cookie.substring(0,
name.length))) 
        { 
            return null; 
        } 
        if (start == -1) return null; 
        var end = document.cookie.indexOf(';', len); 
        if (end == -1) end = document.cookie.length; 
        return unescape(document.cookie.substring(len, end)); 
    }; 

    return that; 
}()); 

It would inevitably result in the same thing but could be slightly
cleaner and with less code, especially if an object has many members. I
ask because I would like to implement MH-7135 in a style that is
acceptable to the rest of the community. Kindly advise. 

Regards,  

Edmore Moyo 
UCT 

  



###

UNIVERSITY OF CAPE TOWN 

This e-mail is subject to the UCT ICT policies and e-mail disclaimer
published on our website at
http://www.uct.ac.za/about/policies/emaildisclaimer/ or obtainable from
+27 21 650 9111. This e-mail is intended only for the person(s) to whom
it is addressed. If the e-mail has reached you in error, please notify
the author. If you are not the intended recipient of the e-mail you may
not use, disclose, copy, redirect or print the content. If this e-mail
is not related to the business of UCT it is sent by the sender in the
sender's individual capacity.

###
 
_______________________________________________
Matterhorn-users mailing list
[email protected]
http://lists.opencastproject.org/mailman/listinfo/matterhorn-users

Reply via email to