5 Replies Latest reply on Jan 21, 2013 3:23 AM by Diircee

    Help with JavaScript

    Diircee Level 1

      Hi, i need help

      I have the code with row

       

       

      this.attributes.buyLabel = price == "free" ? "Baixar" : price || price == "$0.00" ? "Comprar "+price+"" : price;

      I need that variable price in code is blue

      price == "$0.00" ? "Comprar "+price+"" : price;

      But that the code does not change

      price == "free" ? "Baixar" : price

      Someone help me?

       

      Thanks

      Dirce

        • 1. Re: Help with JavaScript
          Test Screen Name Most Valuable Participant

          I have a question, which is related to this, when I started looking for an answer to this question...

           

          I know that rich text is represented internally as a subset of XHTML (so far as I can see). Is there any JavaScript method to directly work with that XHTML, or is there only the abstraction represented by an array of Span and properties like Field.richValue?

          • 2. Re: Help with JavaScript
            Diircee Level 1

            Hi,   This file is connected with html.

             

            This is full code

             

             

            $(document).ready(function() {

                      var init = function() {

             

                                var parseIssues = function(xml) {

                                          var issueNodes = xml.getElementsByTagName("issue");

                                          var len = issueNodes.length;

                                          if (len > 0) {

                                                    var issues = [];

                                                    for (var i = 0; i < len; i++) {

                                                              var issueNode = issueNodes[i];

             

                                                              var issue = {};

                                                              var attributes = issueNode.attributes;

                                                              issue.id = attributes.getNamedItem("id").value;

                                                              issue.formatVersion = attributes.getNamedItem("formatVersion").value;

                                                              issue.version = attributes.getNamedItem("version").value;

                                                              issue.subpath = attributes.getNamedItem("subpath").value;

             

                                                              var childNodes = issueNode.childNodes;

                                                              var numNodes = childNodes.length;

                                                              for (var j = 0; j < numNodes; j++) {

                                                                        if (childNodes[j].nodeType == 1) {

                                                                                  var nodeName = childNodes[j].nodeName;

                                                                                  if (nodeName != "libraryPreviewUrl")

                                                                                            issue[nodeName] = childNodes[j].firstChild.nodeValue;

                                                                                  else

                                                                                            issue[nodeName] = $.trim(childNodes[j].firstChild.nodeValue);

             

                                                                                  if (childNodes[j].nodeName == "libraryPreviewUrl") {

                                                                                            issue.hasLandscapeImage = childNodes[j].attributes.getNamedItem("landscapeVersion").value == "1";

                                                                                            issue.hasPortraitImage = childNodes[j].attributes.getNamedItem("portraitVersion").value == "1";

                                                                                  }

                                                                        }

                                                              }

             

                                                              issues.push(issue);

                                                    }

             

                                                    return issues;

                                          }

                                          else

                                          {

                                                    return null;

                                          }

                                }

             

                                          var Folio = Backbone.Model.extend({

                                          initialize: function() {

                                                    var folio = folioDataHash[this.attributes.id];

                                                    if (folio) {

                                                              if (folio.state == 100 || folio.state == 200) {

                                                                        var price = folioDataHash[this.attributes.id].price.toLowerCase();

                                                                        this.attributes.buyLabel = price == "free" ? "Baixar" : price || price == "$0.00" ? "Comprar "+price+"" : price;

                                                              } else {

                                                                        this.attributes.buyLabel = "Visualizar";

                                                              }

                                                    }

             

             

             

                                                    else {

                                                              this.attributes.buyLabel = "Comprar";

                                                    }

                                          }

             

                                });

             

                                var FolioCollection = Backbone.Collection.extend({

                                          model: Folio,

             

                                          url: FULFILLMENT_URL,

             

                                          parse: parseIssues

                                });

             

                                var FolioItemView = Backbone.View.extend({

                                          tagName:  "div",

             

                                          className: "folio",

             

                                          template: _.template("<img src='<%= libraryPreviewUrl %>/portrait' width='160' height='222' /><div id='title'><%= magazineTitle %></div><div id='issuenumber'><%=issueNumber%></div><div class='buyButton' id='<%= id %>'><%= buyLabel %></div>"),

             

                                          render: function() {

                                                    $(this.el).html(this.template(this.model.toJSON()));

                                                    return this;

                                          },

                                });

             

                                var FolioView = Backbone.View.extend({

                                          el: $("#foliosContainer"),

             

                                          pageIndex: 0,

             

                                          initialize: function() {

                                                    var html  = "<div id='foliosContainer'>";

                                                              html +=           "<div id='folios'>";

                                                              html +=                              "<table id='subscribe'>"; // Ugh: Use a table for layout rather than an image map otherwise the entire region gets a click rather than just a button. This is also faster to implement than placing buttons.

                                                              html +=                                        "<tr><td colspan='3'><a href='http://google.com.br'><img src='banner.png' width='768' height='395'></a></td></tr>";

                                                              html += "</table>";

                                                              html +=                    "</div>";

                                                              html += "</div>";

             

                                                    $("body").append(html)

                                                    _.bindAll(this, "removeMissingFolios");

                                                    folioCollection.bind("all", this.removeMissingFolios);

             

                                                    var scope = this;

                                                    $("#more").click(function(){ scope.addFolios()});

             

                                                    if (adobeExists()) {

             

                                                              adobe.dps.store.getFolioData(this.getFolioDataHandler);

                                                    } else { // API doesn't exist so testing on desktop.

                                                              folioCollection.fetch({dataType: 'xml'});

                                                    }

                                          getFolioDataHandler: function(data) {

                                                    var len = data.length;

             

                                                    if (len == 0) {

                                                              if (!this.interval) {

                                                                        var scope = this;

                                                                        this.interval = setInterval(function() {

                                                                                  adobe.dps.store.getFolioData(function(data) {

                                                                                            scope.getFolioDataHandler(data);

                                                                                  });

                                                                        }, 1000);

                                                              }

             

                                                              return;

                                                    }

             

                                                    clearInterval(this.interval);

             

                                                    for (var i = 0; i < len; i++) {

                                                              folioDataHash[data[i].id] = data[i];

                                                    }

             

                                                    folioCollection.fetch({dataType: 'xml'});

                                          },

             

             

                                          addFolios: function() {

             

                                                    var numFoliosPerPage = this.pageIndex == 0 ? 10 : 12;

                                                    var delta = this.pageIndex == 0 ? 0 : -2;

                                                    var numFolios = Math.min(this.pageIndex * numFoliosPerPage + numFoliosPerPage + delta, folioCollection.length);

                                                    var scope = this;

                                                    for (var i = this.pageIndex * numFoliosPerPage + delta; i < numFolios; i++) {

                                                              var folio = folioCollection.at(i);

                                                              var view = new FolioItemView({model: folio});

                                                              $("#folios").append(view.render().el);

                                                              $("#" + folio.attributes.id).click(function(e){ scope.buy(e) });

                                                    }

             

                                                    this.pageIndex += 1;

                                          },

             

                                          buy: function(e) {

                                                    var folio = folioDataHash[e.currentTarget.id];

                                                    if (folio.state == 100)

                                                              adobe.dps.store.buyFolio(folio.productId);

                                                              adobe.dps.store.viewFolio(folio.productId);

                                          },

             

                                          removeMissingFolios: function() {

                                                    if (adobeExists()) {

                                                              var len = folioCollection.length;

                                                              for (var i = len - 1; i >= 0; i--) {

                                                                        var folio = folioCollection.at(i);

             

                                                                        if (!folioDataHash[folio.attributes.id]){

                                                                                  folioCollection.remove(folio, {silent: true});

                                                                        }

                                                              }

                                                    }

             

                                                    this.addFolios();

                                          }

                                });

             

             

             

                                          return itExists;

                                }

             

                                var folioDataHash = {};

             

                                var folioCollection = new FolioCollection();

                                var folioView = new FolioView();

                      }

             

                      if (window.connected)

                                init();

                      else

                                window.onnetworkconnection = init;

            });

             

            • 3. Re: Help with JavaScript
              Diircee Level 1

              Got It

               

              JS

              this.attributes.buyLabel = price == "free" ? "Baixar" : price || price == "$0.00" ? "Comprar "+price+"" : price;

               

              Css 

               

              #azul{font-size:12px;color:#2021C0;} 

               

               

              Dirce

              • 4. Re: Help with JavaScript
                Test Screen Name Most Valuable Participant

                There is no CSS with Acrobat JavaScript. Are you sure you're in the right forum?

                • 5. Re: Help with JavaScript
                  Diircee Level 1

                  Sorry,  I put this code rs,

                   

                  this.attributes.buyLabel = price == "free" ? "Baixar" : price || price == "$0.00" ? "Comprar "+price+"" : price; 

                   

                  Sorry if I put in the wrong forum, was a little confused