Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Web Development
  3. JavaScript
  4. Need help understanding this piece of code

Need help understanding this piece of code

Scheduled Pinned Locked Moved JavaScript
6 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • J Offline
    J Offline
    Jaime Premy
    wrote on last edited by
    #1

    Hi there, new on this forum and looking for help with some code I found at Cross Browser RDLC Printing - CodeProject. The author didn't include source or demo files and does not reply to my comments either, so I turned to this forum for help. The author supposedly shows a tip on how to create a print button for rdlc reportviewer for non IE browsers: **...If not, we should create a client-side print icon button on the fly. How to create one that exactly looks like the original print button? The answer is so straightforward, by copying the markup for the original button. Here is what RDLC uses for creating the print icon:

    $print = $('

    ');

    * Notice that we created a JavaScript object which represents the markup.

    This icon must be added to the RDLC viewer toolbar and this is how to find the toolbar object on the client-side:

    var findtoolbar = function () {
    var $all = $('table div');
    for (var i = 0, len = $all.length; i < len; i++) {
    if ($($all[i]).css('background-image').toLowerCase().indexOf('toolbar_bk.png') != -1)
    return $($all[i]);
    }
    return null;
    }

    As you see, there is no solid identification method for the toolbar, so we used a combination of certain properties like background image along with the order of objects in the DOM...

    Well he does not show WHERE and HOW to actually add the icon to the toolbar. I tried to do

    $(document).ready(function () {
    findtoolbar.add($print);
    });

    and it threw an error (of course?), but with my limited knowledge of javascript and jquery, that's all I could come up with. So I was hoping someone here could help me make some sense out of this ;-). Thanks in advance.

    The perfect woman: cooks good food and never says no in the middle of the night.**

    Z 1 Reply Last reply
    0
    • J Jaime Premy

      Hi there, new on this forum and looking for help with some code I found at Cross Browser RDLC Printing - CodeProject. The author didn't include source or demo files and does not reply to my comments either, so I turned to this forum for help. The author supposedly shows a tip on how to create a print button for rdlc reportviewer for non IE browsers: **...If not, we should create a client-side print icon button on the fly. How to create one that exactly looks like the original print button? The answer is so straightforward, by copying the markup for the original button. Here is what RDLC uses for creating the print icon:

      $print = $('

      ');

      * Notice that we created a JavaScript object which represents the markup.

      This icon must be added to the RDLC viewer toolbar and this is how to find the toolbar object on the client-side:

      var findtoolbar = function () {
      var $all = $('table div');
      for (var i = 0, len = $all.length; i < len; i++) {
      if ($($all[i]).css('background-image').toLowerCase().indexOf('toolbar_bk.png') != -1)
      return $($all[i]);
      }
      return null;
      }

      As you see, there is no solid identification method for the toolbar, so we used a combination of certain properties like background image along with the order of objects in the DOM...

      Well he does not show WHERE and HOW to actually add the icon to the toolbar. I tried to do

      $(document).ready(function () {
      findtoolbar.add($print);
      });

      and it threw an error (of course?), but with my limited knowledge of javascript and jquery, that's all I could come up with. So I was hoping someone here could help me make some sense out of this ;-). Thanks in advance.

      The perfect woman: cooks good food and never says no in the middle of the night.**

      Z Offline
      Z Offline
      ZurdoDev
      wrote on last edited by
      #2

      Jaime Premy wrote:

      with my limited knowledge of javascript and jquery,

      The code you have posted is essentially a way to hack a webpage. So, having a limited knowledge or JavaScript is going to make this tough for you, which I suppose you already know. I suggest putting a breakpoint in the code and then seeing what it does. You're essentially trying to inject your own code into a Microsoft product and trick it into using what you have. In other words, I would be surprised if it worked all the time anyway. It is an unsupported hack. That article is also 2 years old and browsers have changed a bit since then. Also, the report viewer control I know changes often between versions so make sure you are using version 11, which is what the article says it supports.

      There are only 10 types of people in the world, those who understand binary and those who don't.

      J 1 Reply Last reply
      0
      • Z ZurdoDev

        Jaime Premy wrote:

        with my limited knowledge of javascript and jquery,

        The code you have posted is essentially a way to hack a webpage. So, having a limited knowledge or JavaScript is going to make this tough for you, which I suppose you already know. I suggest putting a breakpoint in the code and then seeing what it does. You're essentially trying to inject your own code into a Microsoft product and trick it into using what you have. In other words, I would be surprised if it worked all the time anyway. It is an unsupported hack. That article is also 2 years old and browsers have changed a bit since then. Also, the report viewer control I know changes often between versions so make sure you are using version 11, which is what the article says it supports.

        There are only 10 types of people in the world, those who understand binary and those who don't.

        J Offline
        J Offline
        Jaime Premy
        wrote on last edited by
        #3

        Well my problem at this point is really how to add the js generated button to the toolbar. This hack is necessary since ms simply did not update reportviewer for compatibility with modern browsers, not even IE.

        The perfect woman: cooks good food and never says no in the middle of the night.

        Z 1 Reply Last reply
        0
        • J Jaime Premy

          Well my problem at this point is really how to add the js generated button to the toolbar. This hack is necessary since ms simply did not update reportviewer for compatibility with modern browsers, not even IE.

          The perfect woman: cooks good food and never says no in the middle of the night.

          Z Offline
          Z Offline
          ZurdoDev
          wrote on last edited by
          #4

          I believe this code does it,

          var findtoolbar = function () {
          var $all = $('table div');
          for (var i = 0, len = $all.length; i < len; i++) {
          if ($($all[i]).css('background-image').toLowerCase().indexOf('toolbar_bk.png') != -1)
          return $($all[i]);
          }
          return null;
          }

          Like I said, this looks like a hack to inject your own code into existing MS product so there is no guarantee that it will work.

          There are only 10 types of people in the world, those who understand binary and those who don't.

          J 1 Reply Last reply
          0
          • Z ZurdoDev

            I believe this code does it,

            var findtoolbar = function () {
            var $all = $('table div');
            for (var i = 0, len = $all.length; i < len; i++) {
            if ($($all[i]).css('background-image').toLowerCase().indexOf('toolbar_bk.png') != -1)
            return $($all[i]);
            }
            return null;
            }

            Like I said, this looks like a hack to inject your own code into existing MS product so there is no guarantee that it will work.

            There are only 10 types of people in the world, those who understand binary and those who don't.

            J Offline
            J Offline
            Jaime Premy
            wrote on last edited by
            #5

            Humm..., this is the code for finding the toolbar. My problem is how to ADD the javascript generated button to the toolbar...

            The perfect woman: cooks good food and never says no in the middle of the night.

            Z 1 Reply Last reply
            0
            • J Jaime Premy

              Humm..., this is the code for finding the toolbar. My problem is how to ADD the javascript generated button to the toolbar...

              The perfect woman: cooks good food and never says no in the middle of the night.

              Z Offline
              Z Offline
              ZurdoDev
              wrote on last edited by
              #6

              Yes, I have understood you every time. What you are not getting is that you need to debug the code. I don't have the answer for you but that person took the time to write an article and I trust that it is correct. So, findtoolbar is code to find the toolbar but if it is in the article it's important for a reason. The $print part looks like it is the actual button. I believe, as I have stated, that findtoolbar is an existing Microsoft function that gets called already. The article, I believe, is hoping that this new findtoolbar function will get called instead of the built-in one and this new one works in chrome and firefox.

              There are only 10 types of people in the world, those who understand binary and those who don't.

              1 Reply Last reply
              0
              Reply
              • Reply as topic
              Log in to reply
              • Oldest to Newest
              • Newest to Oldest
              • Most Votes


              • Login

              • Don't have an account? Register

              • Login or register to search.
              • First post
                Last post
              0
              • Categories
              • Recent
              • Tags
              • Popular
              • World
              • Users
              • Groups