Sign up here and you can log into the forum!

Library: Content.include.js

The WDTVExt plugin depot. Plugins/libraries/code only

Library: Content.include.js   

Postby recliq » Sun May 23, 2010 9:03 am

There is an issue when multiple plugins add content to a single page as explained here -> http://forum.wdlxtv.com/viewtopic.php?f=48&t=577&start=10#p4092

To avoid this i wrote a little function which you can include and use in your scripts.
I recommend creating a folder common inside your plugins folder and put this in there.

Content.include.js
Code: Select all
traceln("Include.Content: Start loading Content include")

function Content() {
   this.oldContent = ""
   this.addContent = ""
   this.newContent = ""
}

Content.prototype.add = function(page, add) {
   if(!page.extraContent) {
      page.extraContent = ""
   }

   this.oldContent = page.extraContent;
   this.addContent = add;
   this.newContent = <wrapper></wrapper>;

    if (this.oldContent) {
        if (this.oldContent.length() > 0) {
            if (this.oldContent.wrapper.length() > 0) {
                this.newContent.wrapper += this.oldContent.wrapper
            } else {
                this.newContent.wrapper += this.oldContent
            }
        }
    }

    if (this.addContent) {
        if (this.addContent.length() > 0) {
            if (this.addContent.wrapper.length() > 0) {
                this.newContent.wrapper += this.addContent.wrapper
            } else {
                this.newContent.wrapper += this.addContent
            }
        }
    }
    page.extraContent = this.newContent;
    return
}

traceln("Include.Content: End loading Content include");


In your plugin first include the file and create a new instance inside your plugin:
Code: Select all
function YourPlugin(path) {
    ...
    // this plugin resides in plugins/YourPlugin/
    include(this.rootPath + "../common/Content.include.js")
    this.Content = new Content()
    ...
}


then use it in onPageCreated event like this:
Code: Select all
YourPlugin.prototype.onPageCreated = function(page) {
    ....
    var extraContent = <wrapper>
        <some nice xml elements/>
    </wrapper>;
    this.Content.add(page, extraContent);
   ...
}


... this of course doesn't help if a plugin which doesn't add the content in a propper way gets loaded after your plugins, so i would like to suggest to always take care of this issue when writing plugins which add extraContent. :!:
­WDLXTV Project Maintainer
-:] If you like my contributions feel free to donate for a beer or a new flash drive. ...and always remember: RTFM! (README, FAQ, WIKI) [:-
User avatar
recliq
WDLXTV Team
 
Posts: 5022
Joined: Thu Apr 15, 2010 8:09 am
Location: Kiel, Germany

Re: Library: Content.include.js   

Postby Tyrate » Mon Jun 07, 2010 2:54 pm

recliq wrote:In your plugin first include the file and create a new instance inside your plugin:
Code: Select all
function YourPlugin(path) {
    ...
    // this plugin resides in plugins/YourPlugin/
    include(this.rootPath + "../common/Content.include.js")
    this.Content = new Content()
    ...
}


then use it in onPageCreated event like this:
Code: Select all
YourPlugin.prototype.onPageCreated = function(page) {
    ....
    var extraContent = <wrapper>
        <some nice xml elements/>
    </wrapper>;
    this.Content.add(page, extraContent);
   ...
}


Ok I created the common folder placed it in the WDTVExt plugin folder, then created the Content.include.js file and placed it into the common folder. The next 2 steps is where I'm a little unclear on. For example I'm trying to use the MediaMark and SubDownloader and I'm not sure where to add your code mark ups at inside the .js file.

For example (mediamark) by Krypto
Code: Select all
function MediaMark(path)
{   
    this.rootPath = path;
   this.currentMedia = "";
   this.fileHashValue = "";
   this.iconMode      = 1;

   // Configuration - Start   
   this.usbPath = this.rootPath; // if you want to place it on an xmounted drive you need specify the path like this for example "/tmp/media/usb/USB2/NAS/plugins/MediaMark/";
   this.iconFilename = "/images/checkMark.png";
   this.videoFilename = "mediaMark.log";
   // Configuration - End
   
   traceln("Plugin.MediaMark: base path is " + this.rootPath);
}


Do I add the script inside the original or do i copy your script over the old?

Code: Select all
function MediaMark(path)
{
    ...
    // this plugin resides in plugins/YourPlugin/
    include(this.rootPath + "../common/Content.include.js")
    this.Content = new Content()
    ...

    this.rootPath = path;
   this.currentMedia = "";
   this.fileHashValue = "";
   this.iconMode      = 1;

   // Configuration - Start   
   this.usbPath = this.rootPath; // if you want to place it on an xmounted drive you need specify the path like this for example "/tmp/media/usb/USB2/NAS/plugins/MediaMark/";
   this.iconFilename = "/images/checkMark.png";
   this.videoFilename = "mediaMark.log";
   // Configuration - End
   
   traceln("Plugin.MediaMark: base path is " + this.rootPath);
}


...and basically it's the same question for the second script as well?
Tyrate
WDTVer
 
Posts: 24
Joined: Fri Apr 23, 2010 7:16 am

Re: Library: Content.include.js   

Postby recliq » Tue Jun 08, 2010 2:35 pm

add
Code: Select all
include(this.rootPath + "../common/Content.include.js")
this.Content = new Content()

to the existing code in the plugin.

Code: Select all
    function MediaMark(path)
    {   
        this.rootPath = path;

       include(this.rootPath + "../common/Content.include.js")
       this.Content = new Content()

       this.currentMedia = "";
       this.fileHashValue = "";
       this.iconMode      = 1;

       // Configuration - Start   
       this.usbPath = this.rootPath; // if you want to place it on an xmounted drive you need specify the path like this for example "/tmp/media/usb/USB2/NAS/plugins/MediaMark/";
       this.iconFilename = "/images/checkMark.png";
       this.videoFilename = "mediaMark.log";
       // Configuration - End
       
       traceln("Plugin.MediaMark: base path is " + this.rootPath);
    }

­WDLXTV Project Maintainer
-:] If you like my contributions feel free to donate for a beer or a new flash drive. ...and always remember: RTFM! (README, FAQ, WIKI) [:-
User avatar
recliq
WDLXTV Team
 
Posts: 5022
Joined: Thu Apr 15, 2010 8:09 am
Location: Kiel, Germany

Re: Library: Content.include.js   

Postby Tyrate » Wed Jun 09, 2010 3:55 pm

Thank you but I still can't get it right. What about about the 2nd part of the script? How's that enter in the plugin?

Code: Select all
YourPlugin.prototype.onPageCreated = function(page) {
    ....
    var extraContent = <wrapper>
        <some nice xml elements/>
    </wrapper>;
    this.Content.add(page, extraContent);
   ...
}
Tyrate
WDTVer
 
Posts: 24
Joined: Fri Apr 23, 2010 7:16 am

Re: Library: Content.include.js   

Postby recliq » Thu Jun 10, 2010 4:01 am

Hey Tyrate,

in MediaMark plugin code search for this:
Code: Select all
         if (page.markupFileName == "basic_browse_preview.xml")
         {
            page.extraContent +=
            <wrapper>
               <image name="markIcon" image="@@markIcon" x="1070" y="450" w="40" h="40" scale="100" />
            </wrapper>         
         }
         else
         {
            page.extraContent +=
            <wrapper>
               <image name="markIcon" image="@@markIcon" x="1150" y="665" w="40" h="40" scale="100" />
            </wrapper>         
         }


and change it to this:
Code: Select all
         if (page.markupFileName == "basic_browse_preview.xml")
         {
            var extraContent =
            <wrapper>
               <image name="markIcon" image="@@markIcon" x="1070" y="450" w="40" h="40" scale="100" />
            </wrapper>         
         }
         else
         {
            var extraContent =
            <wrapper>
               <image name="markIcon" image="@@markIcon" x="1150" y="665" w="40" h="40" scale="100" />
            </wrapper>         
         }
         this.Content.add(page, extraContent)
­WDLXTV Project Maintainer
-:] If you like my contributions feel free to donate for a beer or a new flash drive. ...and always remember: RTFM! (README, FAQ, WIKI) [:-
User avatar
recliq
WDLXTV Team
 
Posts: 5022
Joined: Thu Apr 15, 2010 8:09 am
Location: Kiel, Germany

Re: Library: Content.include.js   

Postby Tyrate » Thu Jun 10, 2010 3:55 pm

Thank you... I know it's not easy dealing with newbies and noobs like me!
Tyrate
WDTVer
 
Posts: 24
Joined: Fri Apr 23, 2010 7:16 am


Return to WDTVExt plugins

Who is online

Users browsing this forum: No registered users and 1 guest