<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">

    <title>OpenPicker - Installation and Usage </title>

     <!-- Bootstrap core CSS -->
    <link href="/dist/css/bootstrap.min.css" rel="stylesheet">

    <script type="text/javascript">
      (function(window,document) {
        window.openpicker = {};
        var op = document.createElement('script'); op.type = 'text/javascript'; op.async = true;
        op.src = ('https:' == document.location.protocol ? 'https://' : 'http://') + '<%=host%>/script/v1.js?t=<%=timestamp%>';
        var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(op, s);
      })(window,document);
    </script>  
  


  </head>

  <body>

    

    <div class="container">

      <div class="blog-header">
        <h1 class="blog-title">OpenPicker</h1>
        <p class="lead blog-description">Your OpenPicker installation is ready.</p>
      </div>

      <div class="row">

        <div class="col-sm-7 blog-main">

          <div class="blog-post">
            <h2 class="blog-post-title">Add javascript to your site</h2>
            <p class="lead blog-description">Copy Paste the folllowing code snippet, anywhere on the page where you want to user OpenPicker.</p>
            <textarea class="form-control" rows="10" readonly>
&lt;script type=&quot;text/javascript&quot;&gt;
  (function(window,document) {
    window.openpicker = {};
    var op = document.createElement('script'); op.type = 'text/javascript'; op.async = true;
    op.src = ('https:' == document.location.protocol ? 'https://' : 'http://') + '<%=host%>/script/v1.js?t=<%=timestamp%>';
    var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(op, s);
  })(window,document);
&lt;/script&gt;  
            </textarea>
          </div><!-- /.blog-post -->

          <div class="blog-post">
            <h2 class="blog-post-title">Use OpenPicker</h2>
            <textarea class="form-control" rows="9" readonly>
      $('#buttonImage').click(function(){
          window.openpicker.getFiles({mimetypes: "image/*" ,conversions:['crop','rotate'],cropRatio: 1/1},function(openpickerResponse){
            console.log("Open Picker Response is");
            console.log(openpickerResponse);
              $('#uploadedImage').attr('src',openpickerResponse.file.url);
              $('#uploadedImage').show();
          });
      });
            </textarea>
          </div><!-- /.blog-post -->


        </div><!-- /.blog-main -->

        <div class="col-sm-5 ">
          <div class="sidebar-module sidebar-module-inset" style="text-align:center">
            <h4>Try Uploading a File</h4>
            <div> 
              <button id="buttonImage" class="btn btn-success btn-md" style="width: 140px; height: 37px;"> Upload Image </button>
              <button id="buttonFile" class="btn btn-success btn-md" style="width: 140px; height: 37px;"> Upload a File </button>
            </div>
            <div style="padding: 5px; margin-right: 10px;">
              <iframe id="uploadedFile" src="" width="500" height="300" style="display: none;"></iframe>
              <img id="uploadedImage" src="" style="display: none; width: 100%; height: auto;">
              <span id="generalUploadedFile" class="glyphicon glyphicon-file" style=" display:none; font-size: 100px;width: 50px;margin: 20px 100px;color: #b1adad;"></span>
              <p id="fileName" style="display: none; text-align: center;color: #809393;"></p>
            </div>
          </div>
        </div><!-- /.blog-sidebar -->

      </div><!-- /.row -->

    </div><!-- /.container -->

    


    <!-- Bootstrap core JavaScript
    ================================================== -->
    <!-- Placed at the end of the document so the pages load faster -->
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.2/jquery.min.js"></script>
    <script>window.jQuery || document.write('<script src="../../assets/js/vendor/jquery.min.js"><\/script>')</script>
    <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js"></script>
    <script type="text/javascript">
      $('#buttonImage').click(function(){
          window.openpicker.getFiles({mimetypes: "image/*" ,conversions:['crop','rotate'],cropRatio: 1/1},function(openpickerResponse){
            console.log("Open Picker Response is");
            console.log(openpickerResponse);
              $('#uploadedImage').attr('src',openpickerResponse.file.url);
              $('#uploadedImage').show();
              $('#fileName').html(openpickerResponse.file.name);
              $('#fileName').show();
          });
      });      
      $('#buttonFile').click(function(){
          window.openpicker.getFiles({mimetypes: "*/*" ,conversions:['crop','rotate'],cropRatio: 1/1},function(openpickerResponse){
            console.log("Open Picker Response is");
            console.log(openpickerResponse);
            //check whether the file is viewable natively avaialable browser
            if(openpickerResponse.file.name.match(/(mp4|mp3|mpeg|pdf)$/i)){
              $('#uploadedFile').attr('src',openpickerResponse.file.url);
              $('#uploadedFile').show();
            }  
            else{
              $('#generalUploadedFile').show();
            } 
            $('#fileName').html(openpickerResponse.file.name);
            $('#fileName').show();
          });
      });
    </script>

    
  </body>
</html>
