Bugzilla – Attachment 25432 Details for
Bug 10858
Browse selected biblios - OPAC
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 10858: Browse selected biblios - bootstrap
Bug-10858-Browse-selected-biblios---bootstrap.patch (text/plain), 27.06 KB, created by
Jonathan Druart
on 2014-02-19 10:41:18 UTC
(
hide
)
Description:
Bug 10858: Browse selected biblios - bootstrap
Filename:
MIME Type:
Creator:
Jonathan Druart
Created:
2014-02-19 10:41:18 UTC
Size:
27.06 KB
patch
obsolete
>From a75c2c8a5b97a2f97613f317bb9e570fb5c9615a Mon Sep 17 00:00:00 2001 >From: Jonathan Druart <jonathan.druart@biblibre.com> >Date: Mon, 25 Nov 2013 12:47:14 +0100 >Subject: [PATCH] Bug 10858: Browse selected biblios - bootstrap > >Add the changes from bug 10858 to the bootstrap theme. > >Test plan: >- Launch a search at the OPAC >- Check some biblios >- Go on another page >- Check some biblios >- Come back to the first page and check that already checked biblio is > automatically checked. >- Click on the "Browse selected biblios >>" link >- Check that you are able to browse results you had checked. > >In addition to prog and ccsr templates, this patch allows to add >selected biblios (from multiple pages) to the cart or a list. >To test: >- check some biblios from several pages >- add them to the cart >- add them to a list >--- > .../bootstrap/en/includes/opac-bottom.inc | 4 + > .../bootstrap/en/includes/page-numbers.inc | 4 +- > .../opac-tmpl/bootstrap/en/modules/opac-detail.tt | 70 +++---- > .../opac-tmpl/bootstrap/en/modules/opac-results.tt | 36 +++- > koha-tmpl/opac-tmpl/bootstrap/js/basket.js | 42 +++-- > koha-tmpl/opac-tmpl/bootstrap/js/commons.js | 72 +++++++ > .../lib/jquery/plugins/jquery.cookie.min.js | 1 + > .../bootstrap/lib/jquery/plugins/jquery.json.js | 199 ++++++++++++++++++++ > 8 files changed, 377 insertions(+), 51 deletions(-) > create mode 100644 koha-tmpl/opac-tmpl/bootstrap/js/commons.js > create mode 100644 koha-tmpl/opac-tmpl/bootstrap/lib/jquery/plugins/jquery.cookie.min.js > create mode 100644 koha-tmpl/opac-tmpl/bootstrap/lib/jquery/plugins/jquery.json.js > >diff --git a/koha-tmpl/opac-tmpl/bootstrap/en/includes/opac-bottom.inc b/koha-tmpl/opac-tmpl/bootstrap/en/includes/opac-bottom.inc >index 8bb4ccd..913b5a2 100644 >--- a/koha-tmpl/opac-tmpl/bootstrap/en/includes/opac-bottom.inc >+++ b/koha-tmpl/opac-tmpl/bootstrap/en/includes/opac-bottom.inc >@@ -79,6 +79,10 @@ > <script type="text/javascript" src="[% interface %]/[% theme %]/lib/jquery/jquery-ui.js"></script> > <script type="text/javascript" src="[% interface %]/[% theme %]/lib/bootstrap/js/bootstrap.min.js"></script> > <script type="text/javascript" src="[% interface %]/[% theme %]/js/global.js"></script> >+<script type="text/javascript" src="[% interface %]/[% theme %]/lib/jquery/jquery.js"></script> >+<script type="text/javascript" src="[% interface %]/[% theme %]/lib/jquery/plugins/jquery.json.js"></script> >+<script type="text/javascript" src="[% interface %]/[% theme %]/lib/jquery/plugins/jquery.cookie.min.js"></script> >+<script type="text/javascript" src="[% interface %]/[% theme %]/js/commons.js"></script> > <script type="text/javascript"> > Modernizr.load([ > // Test need for polyfill >diff --git a/koha-tmpl/opac-tmpl/bootstrap/en/includes/page-numbers.inc b/koha-tmpl/opac-tmpl/bootstrap/en/includes/page-numbers.inc >index 1c113d8..6cc5c08 100644 >--- a/koha-tmpl/opac-tmpl/bootstrap/en/includes/page-numbers.inc >+++ b/koha-tmpl/opac-tmpl/bootstrap/en/includes/page-numbers.inc >@@ -8,11 +8,11 @@ > [% IF ( PAGE_NUMBER.highlight ) %] > <li class="active"><a href="#">[% PAGE_NUMBER.pg %]</a></li> > [% ELSE %] >- <li><a href="/cgi-bin/koha/opac-search.pl?[% query_cgi |html %][% limit_cgi |html %]&offset=[% PAGE_NUMBER.offset %][% IF ( sort_by ) %]&sort_by=[% sort_by |html%][% END %]">[% PAGE_NUMBER.pg %]</a></li> >+ <li><a class="nav" href="/cgi-bin/koha/opac-search.pl?[% query_cgi |html %][% limit_cgi |html %]&offset=[% PAGE_NUMBER.offset %][% IF ( sort_by ) %]&sort_by=[% sort_by |html%][% END %]">[% PAGE_NUMBER.pg %]</a></li> > [% END %] > [% END %] > [% IF ( next_page_offset ) %] >- <li><a href="/cgi-bin/koha/opac-search.pl?[% query_cgi |html %][% limit_cgi |html %]&offset=[% next_page_offset %][% IF ( sort_by ) %]&sort_by=[% sort_by |html %][% END %]">Next »</a></li> >+ <li><a class="nav" href="/cgi-bin/koha/opac-search.pl?[% query_cgi |html %][% limit_cgi |html %]&offset=[% next_page_offset %][% IF ( sort_by ) %]&sort_by=[% sort_by |html %][% END %]">Next »</a></li> > [% END %] > </ul> > </div> >diff --git a/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-detail.tt b/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-detail.tt >index 46f73db..3266218 100644 >--- a/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-detail.tt >+++ b/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-detail.tt >@@ -1027,7 +1027,7 @@ > <span>Previous</span> > [% END %] > </li> >- <li class="back_results"><a href="opac-search.pl?[% busc |url %]" title="Back to the results search list">Back to results</a></li> >+ <li class="back_results"><a href="opac-search.pl?[% busc |url %]" title="Back to the results search list" class="searchwithcontext">Back to results</a></li> > <li class="right_results"> > [% IF ( next ) %]<a href="[% next %]" title="See: [% IF ( nextTitle ) %][% nextTitle |html %][% ELSE %]next biblio[% END %]">Next »</a> > [% ELSE %] >@@ -1049,33 +1049,35 @@ > </div> > [% END # / IF OpacBrowseResults && busc %] > >- [% INCLUDE 'opac-detail-sidebar.inc' %] >- >- [% IF ( NovelistSelectProfile && NovelistSelectView == 'right') %] >- <div id="NovelistSelect"> >- <h4>Novelist Select</h4> >- <div data-novelist-novelistselect=[% normalized_isbn %]></div> >- </div> >- [% END %] >- >- [% IF ( Babeltheque ) %] >- <div class="babeltheque_adds"> >- <div id="BW_critiques_aj"></div> >- <div id="BW_citations_aj"></div> >- </div> >- [% END %] >- >- [% IF ( SocialNetworks ) %] >- <div id="social_networks" class="clearfix"> >- <span>Share</span> >- <div><a id="facebook" href="http://www.facebook.com/sharer.php?u=[% current_url |url %]&t=[% title |url %]" title="Share on Facebook">Facebook</a></div> >- <div><a id="linkedin" href="http://www.linkedin.com/shareArticle?mini=true&url=[% current_url |url %]&title=[% title |url %]" title="Share on LinkedIn">LinkedIn</a></div> >- <div><a id="delicious" href="http://www.delicious.com/save?url=[% current_url |url %]&title=[% title |url %]" title="Share on Delicious">Delicious</a></div> >- <div><a id="email" href="mailto:?subject=[% title |url %]&body=[% title |url %]%20([% current_url |url %])" title="Share by email">Email</a></div> >- <div><div class="g-plusone" data-size="small" data-count="false"></div></div> >- <div><a id="twitter" href="https://twitter.com/share" class="twitter-share-button" data-count="none" data-text="[% title %]" data-lang="[% lang %]">Tweet</a></div> >- </div> >- [% END %] >+ <div id="sidebar"> >+ [% INCLUDE 'opac-detail-sidebar.inc' %] >+ >+ [% IF ( NovelistSelectProfile && NovelistSelectView == 'right') %] >+ <div id="NovelistSelect"> >+ <h4>Novelist Select</h4> >+ <div data-novelist-novelistselect=[% normalized_isbn %]></div> >+ </div> >+ [% END %] >+ >+ [% IF ( Babeltheque ) %] >+ <div class="babeltheque_adds"> >+ <div id="BW_critiques_aj"></div> >+ <div id="BW_citations_aj"></div> >+ </div> >+ [% END %] >+ >+ [% IF ( SocialNetworks ) %] >+ <div id="social_networks" class="clearfix"> >+ <span>Share</span> >+ <div><a id="facebook" href="http://www.facebook.com/sharer.php?u=[% current_url |url %]&t=[% title |url %]" title="Share on Facebook">Facebook</a></div> >+ <div><a id="linkedin" href="http://www.linkedin.com/shareArticle?mini=true&url=[% current_url |url %]&title=[% title |url %]" title="Share on LinkedIn">LinkedIn</a></div> >+ <div><a id="delicious" href="http://www.delicious.com/save?url=[% current_url |url %]&title=[% title |url %]" title="Share on Delicious">Delicious</a></div> >+ <div><a id="email" href="mailto:?subject=[% title |url %]&body=[% title |url %]%20([% current_url |url %])" title="Share by email">Email</a></div> >+ <div><div class="g-plusone" data-size="small" data-count="false"></div></div> >+ <div><a id="twitter" href="https://twitter.com/share" class="twitter-share-button" data-count="none" data-text="[% title %]" data-lang="[% lang %]">Tweet</a></div> >+ </div> >+ [% END %] >+ </div> > </div> <!-- / .ulactioncontainer --> > </div> <!-- / .span4 --> > </div> <!-- / .row-fluid --> >@@ -1364,6 +1366,7 @@ > renderPagIndexList(pag_index_ini, $("#listResults")); > } > $("#a_listResults").click(function(e) { >+ $("#sidebar").toggle(); > if (arrPagination.length > 0) { > e.preventDefault(); > var navigation = $(".results-pagination"); >@@ -1383,6 +1386,7 @@ > e.preventDefault(); > var navigation = $(".results-pagination"); > navigation.hide(); >+ $("#sidebar").toggle(); > }); > [% END %] > [% IF ( OPACShelfBrowser ) %] >@@ -1547,8 +1551,9 @@ > var timeoutRFW; > var totalPagItemList = 10; > >- function rewindList() >+ function rewindList(e) > { >+ e.preventDefault(); > var ul = $("#listResults"); > var li_ini = ul.children(':first').next(); > var index_ini = pag_index_ini; >@@ -1566,8 +1571,9 @@ > } > }//rewindList > >- function forwardList() >+ function forwardList(e) > { >+ e.preventDefault(); > var ul = $("#listResults"); > var li_ini = ul.children(':first').next(); > var index_ini = pag_index_ini; >@@ -1598,7 +1604,7 @@ > var ini = index - 1; > var end = ini + totalPagItemList - 1; > li = $("<li />"); >- html = (index > pag_index_ini)?"<a href='#' id='rew_list_index' onclick='rewindList()' title='" + _("Click to rewind the list to") + " " + ini + " - " + end + "'>«</a>":"«"; >+ html = (index > pag_index_ini)?"<a href='#' id='rew_list_index' onclick='rewindList(event)' title='" + _("Click to rewind the list to") + " " + ini + " - " + end + "'>«</a>":"«"; > li.html(html); > ul.append(li); > var title = ""; >@@ -1620,7 +1626,7 @@ > li = $("<li />"); > ini = index + 1; > end = (arrPagination.length > index + totalPagItemList)?index + totalPagItemList:arrPagination.length - 1; >- html = (end <= arrPagination.length - 1 && (end - index) >= totalPagItemList)?"<a href='#' id='fw_list_index' onclick='forwardList()' title='" + _("Click to forward the list to") + " " + ini + " - " + end + "'>»</a>":"»"; >+ html = (end <= arrPagination.length - 1 && (end - index) >= totalPagItemList)?"<a href='#' id='fw_list_index' onclick='forwardList(event)' title='" + _("Click to forward the list to") + " " + ini + " - " + end + "'>»</a>":"»"; > li.html(html); > ul.append(li); > }//renderPagIndexList >diff --git a/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-results.tt b/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-results.tt >index 8f0a089..40a687d 100644 >--- a/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-results.tt >+++ b/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-results.tt >@@ -162,6 +162,7 @@ > Tag status here. > </div> > [% END %] >+ <span class="details_link"><a href="#">Browse selected records</a></span> > </span> <!-- / .links --> > </div> <!-- / #selections-toolbar --> > >@@ -626,11 +627,14 @@ function tagAdded() { > > function enableCheckboxActions(){ > // Enable/disable controls if checkboxes are checked >- var checkedBoxes = $(".checkboxed input:checkbox:checked"); >+ var bibnums = getContextBiblioNumbers(); > var controls = $("#selections-toolbar .links a, #selections-toolbar .links input, #selections-toolbar .links select, , #selections-toolbar .links label") >- if ($(checkedBoxes).size()) { >+ if ( bibnums.length > 0 ) { > $("#selections").html(_("With selected titles: ")); > $(controls).removeClass("disabled"); >+ // Hide or show details link >+ // Update with first biblionumber in queue >+ $(".details_link a").attr("href", "/cgi-bin/koha/opac-detail.pl?biblionumber=" + bibnums[0]); > } else { > $("#selections").html(_("Select titles to: ")); > $(controls).addClass("disabled"); >@@ -657,6 +661,7 @@ function highlightOn() { > $(".highlight_toggle").toggle(); > } > [% END %] >+ > $(document).ready(function(){ > [% IF ( OpacHighlightedWords ) %] > $('a.title').each(function() { >@@ -665,9 +670,27 @@ $(document).ready(function(){ > [% END %] > > $(".cb").click(function(){ >+ if ( $(this).is(':checked') == true ) { >+ addBibToContext( $(this).val() ); >+ } else { >+ delBibToContext( $(this).val() ); >+ } > enableCheckboxActions(); > }); >- enableCheckboxActions(); >+ >+ >+ $("#bookbag_form").ready(function(){ >+ $("#bookbag_form").unCheckCheckboxes(); >+ var bibnums = getContextBiblioNumbers(); >+ if (bibnums) { >+ for (var i=0; i < bibnums.length; i++) { >+ var id = ('#bib' + bibnums[i]); >+ if ($(id)) { >+ $(id).attr('checked', true); >+ } >+ } >+ } >+ }); > > [% IF ( IDreamBooksResults ) %] > $('.idbresult').each(function() { >@@ -806,11 +829,17 @@ $(document).ready(function(){ > $("#CheckAll").click(function(){ > $("#bookbag_form").checkCheckboxes(); > enableCheckboxActions(); >+ $("#bookbag_form").find("input[type='checkbox'][name='biblionumber']").each(function(){ >+ $(this).change(); >+ } ); > return false; > }); > $("#CheckNone").click(function(){ > $("#bookbag_form").unCheckCheckboxes(); > enableCheckboxActions(); >+ $("#bookbag_form").find("input[type='checkbox'][name='biblionumber']").each(function(){ >+ $(this).change(); >+ } ); > return false; > }); > >@@ -912,7 +941,6 @@ $(document).ready(function(){ > }); > }); > [% END %] >- > }); > //]]> > </script> >diff --git a/koha-tmpl/opac-tmpl/bootstrap/js/basket.js b/koha-tmpl/opac-tmpl/bootstrap/js/basket.js >index 675dc0a..d3a1c9b 100644 >--- a/koha-tmpl/opac-tmpl/bootstrap/js/basket.js >+++ b/koha-tmpl/opac-tmpl/bootstrap/js/basket.js >@@ -157,17 +157,25 @@ function SelectAll(){ > } > > function addMultiple(){ >+ var bibnums = getContextBiblioNumbers(); > var c_value = ""; >- if(document.bookbag_form.biblionumber.length > 0) { >- for (var i=0; i < document.bookbag_form.biblionumber.length; i++) { >- if (document.bookbag_form.biblionumber[i].checked) { >- c_value = c_value + document.bookbag_form.biblionumber[i].value + "/"; >- } >+ if ( bibnums.length > 0 ) { >+ for ( var i = 0 ; i < bibnums.length ; i++ ) { >+ c_value = c_value + bibnums[i] + "/"; > } > addSelRecords(c_value); > } else { >- c_value = c_value + document.bookbag_form.biblionumber.value + "/"; >- addSelRecords(c_value); >+ if(document.bookbag_form.biblionumber.length > 0) { >+ for (var i=0; i < document.bookbag_form.biblionumber.length; i++) { >+ if (document.bookbag_form.biblionumber[i].checked) { >+ c_value = c_value + document.bookbag_form.biblionumber[i].value + "/"; >+ } >+ } >+ addSelRecords(c_value); >+ } else { >+ c_value = c_value + document.bookbag_form.biblionumber.value + "/"; >+ addSelRecords(c_value); >+ } > } > } > >@@ -433,20 +441,28 @@ function addSelToShelf() { > /// vShelfAdd() builds url string for multiple-biblio adds. > > function vShelfAdd() { >- bibs= new Array; >+ var bibnums = getContextBiblioNumbers(); >+ bibs = new Array; >+ if ( bibnums.length > 0 ) { >+ for ( var i = 0 ; i < bibnums.length ; i++ ) { >+ bibs.push("biblionumber=" + bibnums[i]); >+ } >+ return bibs.join("&"); >+ } else { > if(document.bookbag_form.biblionumber.length > 0) { >- for (var i=0; i < document.bookbag_form.biblionumber.length; i++) { >- if (document.bookbag_form.biblionumber[i].checked) { >- bibs.push("biblionumber=" + document.bookbag_form.biblionumber[i].value); >- } >+ for (var i=0; i < document.bookbag_form.biblionumber.length; i++) { >+ if (document.bookbag_form.biblionumber[i].checked) { >+ bibs.push("biblionumber=" + document.bookbag_form.biblionumber[i].value); > } >- if (bibs.length == 0) { showListsUpdate(MSG_NO_RECORD_SELECTED); } >+ } >+ if (bibs.length == 0) { showListsUpdate(MSG_NO_RECORD_SELECTED); } > return bibs.join("&"); > } else { > if (document.bookbag_form.biblionumber.checked) { > return "biblionumber=" + document.bookbag_form.biblionumber.value; > } > } >+ } > } > > function showCart(){ >diff --git a/koha-tmpl/opac-tmpl/bootstrap/js/commons.js b/koha-tmpl/opac-tmpl/bootstrap/js/commons.js >new file mode 100644 >index 0000000..490bfdf >--- /dev/null >+++ b/koha-tmpl/opac-tmpl/bootstrap/js/commons.js >@@ -0,0 +1,72 @@ >+// Extends jQuery API >+// http://www.wskidmore.com/downloads/jquery-uniqueArray.min.js >+jQuery.extend({uniqueArray:function(e){if($.isArray(e)){var c={};var a,b;for(b=0,a=e.length;b<a;b++){var d=e[b].toString();if(c[d]){e.splice(b,1);a--;b--}else{c[d]=true}}}return(e)}}); >+ >+function removeByValue(arr, val) { >+ for(var i=0; i<arr.length; i++) { >+ if(arr[i] == val) { >+ arr.splice(i, 1); >+ break; >+ } >+ } >+} >+ >+function paramOfUrl( url, param ) { >+ param = param.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]"); >+ var regexS = "[\\?&]"+param+"=([^&#]*)"; >+ var regex = new RegExp( regexS ); >+ var results = regex.exec( url ); >+ if( results == null ) { >+ return ""; >+ } else { >+ return results[1]; >+ } >+} >+ >+function addBibToContext( bibnum ) { >+ var bibnums = getContextBiblioNumbers(); >+ bibnums.push(bibnum); >+ setContextBiblioNumbers( bibnums ); >+ //var store = sessionStorage.getItem( "bibs_selected" ); >+} >+ >+function delBibToContext( bibnum ) { >+ var bibnums = getContextBiblioNumbers(); >+ removeByValue( bibnums, bibnum ); >+ setContextBiblioNumbers( $.uniqueArray( bibnums ) ); >+} >+ >+function setContextBiblioNumbers( bibnums ) { >+ //sessionStorage.setItem("bibs_selected", JSON.stringify( bibnums ) ); >+ $.cookie('bibs_selected', JSON.stringify( bibnums )); >+} >+ >+function getContextBiblioNumbers() { >+ //var r = sessionStorage.getItem("bibs_selected"); >+ var r = $.cookie('bibs_selected'); >+ if ( r ) { >+ return JSON.parse(r); >+ } >+ r = new Array(); >+ return r; >+} >+ >+function resetSearchContext() { >+ setContextBiblioNumbers( new Array() ); >+} >+ >+$(document).ready(function(){ >+ // forms with action leading to search >+ $("form[action*='opac-search.pl']").submit(function(){ >+ resetSearchContext(); >+ }); >+ // any link to launch a search except navigation links >+ $("[href*='opac-search.pl?']").not(".nav").not('.searchwithcontext').click(function(){ >+ resetSearchContext(); >+ }); >+ // any link to a detail page from the results page. >+ $("#bookbag_form a[href*='opac-detail.pl?']").click(function(){ >+ resetSearchContext(); >+ }); >+}); >+ >diff --git a/koha-tmpl/opac-tmpl/bootstrap/lib/jquery/plugins/jquery.cookie.min.js b/koha-tmpl/opac-tmpl/bootstrap/lib/jquery/plugins/jquery.cookie.min.js >new file mode 100644 >index 0000000..eb129db >--- /dev/null >+++ b/koha-tmpl/opac-tmpl/bootstrap/lib/jquery/plugins/jquery.cookie.min.js >@@ -0,0 +1 @@ >+jQuery.cookie=function(b,j,m){if(typeof j!="undefined"){m=m||{};if(j===null){j="";m.expires=-1}var e="";if(m.expires&&(typeof m.expires=="number"||m.expires.toUTCString)){var f;if(typeof m.expires=="number"){f=new Date();f.setTime(f.getTime()+(m.expires*24*60*60*1000))}else{f=m.expires}e="; expires="+f.toUTCString()}var l=m.path?"; path="+(m.path):"";var g=m.domain?"; domain="+(m.domain):"";var a=m.secure?"; secure":"";document.cookie=[b,"=",encodeURIComponent(j),e,l,g,a].join("")}else{var d=null;if(document.cookie&&document.cookie!=""){var k=document.cookie.split(";");for(var h=0;h<k.length;h++){var c=jQuery.trim(k[h]);if(c.substring(0,b.length+1)==(b+"=")){d=decodeURIComponent(c.substring(b.length+1));break}}}return d}}; >\ No newline at end of file >diff --git a/koha-tmpl/opac-tmpl/bootstrap/lib/jquery/plugins/jquery.json.js b/koha-tmpl/opac-tmpl/bootstrap/lib/jquery/plugins/jquery.json.js >new file mode 100644 >index 0000000..a7b0211 >--- /dev/null >+++ b/koha-tmpl/opac-tmpl/bootstrap/lib/jquery/plugins/jquery.json.js >@@ -0,0 +1,199 @@ >+/** >+ * jQuery JSON plugin 2.4-alpha >+ * >+ * @author Brantley Harris, 2009-2011 >+ * @author Timo Tijhof, 2011-2012 >+ * @source This plugin is heavily influenced by MochiKit's serializeJSON, which is >+ * copyrighted 2005 by Bob Ippolito. >+ * @source Brantley Harris wrote this plugin. It is based somewhat on the JSON.org >+ * website's http://www.json.org/json2.js, which proclaims: >+ * "NO WARRANTY EXPRESSED OR IMPLIED. USE AT YOUR OWN RISK.", a sentiment that >+ * I uphold. >+ * @license MIT License <http://www.opensource.org/licenses/mit-license.php> >+ */ >+(function ($) { >+ 'use strict'; >+ >+ var escape = /["\\\x00-\x1f\x7f-\x9f]/g, >+ meta = { >+ '\b': '\\b', >+ '\t': '\\t', >+ '\n': '\\n', >+ '\f': '\\f', >+ '\r': '\\r', >+ '"' : '\\"', >+ '\\': '\\\\' >+ }, >+ hasOwn = Object.prototype.hasOwnProperty; >+ >+ /** >+ * jQuery.toJSON >+ * Converts the given argument into a JSON representation. >+ * >+ * @param o {Mixed} The json-serializable *thing* to be converted >+ * >+ * If an object has a toJSON prototype, that will be used to get the representation. >+ * Non-integer/string keys are skipped in the object, as are keys that point to a >+ * function. >+ * >+ */ >+ $.toJSON = typeof JSON === 'object' && JSON.stringify ? JSON.stringify : function (o) { >+ if (o === null) { >+ return 'null'; >+ } >+ >+ var pairs, k, name, val, >+ type = $.type(o); >+ >+ if (type === 'undefined') { >+ return undefined; >+ } >+ >+ // Also covers instantiated Number and Boolean objects, >+ // which are typeof 'object' but thanks to $.type, we >+ // catch them here. I don't know whether it is right >+ // or wrong that instantiated primitives are not >+ // exported to JSON as an {"object":..}. >+ // We choose this path because that's what the browsers did. >+ if (type === 'number' || type === 'boolean') { >+ return String(o); >+ } >+ if (type === 'string') { >+ return $.quoteString(o); >+ } >+ if (typeof o.toJSON === 'function') { >+ return $.toJSON(o.toJSON()); >+ } >+ if (type === 'date') { >+ var month = o.getUTCMonth() + 1, >+ day = o.getUTCDate(), >+ year = o.getUTCFullYear(), >+ hours = o.getUTCHours(), >+ minutes = o.getUTCMinutes(), >+ seconds = o.getUTCSeconds(), >+ milli = o.getUTCMilliseconds(); >+ >+ if (month < 10) { >+ month = '0' + month; >+ } >+ if (day < 10) { >+ day = '0' + day; >+ } >+ if (hours < 10) { >+ hours = '0' + hours; >+ } >+ if (minutes < 10) { >+ minutes = '0' + minutes; >+ } >+ if (seconds < 10) { >+ seconds = '0' + seconds; >+ } >+ if (milli < 100) { >+ milli = '0' + milli; >+ } >+ if (milli < 10) { >+ milli = '0' + milli; >+ } >+ return '"' + year + '-' + month + '-' + day + 'T' + >+ hours + ':' + minutes + ':' + seconds + >+ '.' + milli + 'Z"'; >+ } >+ >+ pairs = []; >+ >+ if ($.isArray(o)) { >+ for (k = 0; k < o.length; k++) { >+ pairs.push($.toJSON(o[k]) || 'null'); >+ } >+ return '[' + pairs.join(',') + ']'; >+ } >+ >+ // Any other object (plain object, RegExp, ..) >+ // Need to do typeof instead of $.type, because we also >+ // want to catch non-plain objects. >+ if (typeof o === 'object') { >+ for (k in o) { >+ // Only include own properties, >+ // Filter out inherited prototypes >+ if (hasOwn.call(o, k)) { >+ // Keys must be numerical or string. Skip others >+ type = typeof k; >+ if (type === 'number') { >+ name = '"' + k + '"'; >+ } else if (type === 'string') { >+ name = $.quoteString(k); >+ } else { >+ continue; >+ } >+ type = typeof o[k]; >+ >+ // Invalid values like these return undefined >+ // from toJSON, however those object members >+ // shouldn't be included in the JSON string at all. >+ if (type !== 'function' && type !== 'undefined') { >+ val = $.toJSON(o[k]); >+ pairs.push(name + ':' + val); >+ } >+ } >+ } >+ return '{' + pairs.join(',') + '}'; >+ } >+ }; >+ >+ /** >+ * jQuery.evalJSON >+ * Evaluates a given json string. >+ * >+ * @param str {String} >+ */ >+ $.evalJSON = typeof JSON === 'object' && JSON.parse ? JSON.parse : function (str) { >+ /*jshint evil: true */ >+ return eval('(' + str + ')'); >+ }; >+ >+ /** >+ * jQuery.secureEvalJSON >+ * Evals JSON in a way that is *more* secure. >+ * >+ * @param str {String} >+ */ >+ $.secureEvalJSON = typeof JSON === 'object' && JSON.parse ? JSON.parse : function (str) { >+ var filtered = >+ str >+ .replace(/\\["\\\/bfnrtu]/g, '@') >+ .replace(/"[^"\\\n\r]*"|true|false|null|-?\d+(?:\.\d*)?(?:[eE][+\-]?\d+)?/g, ']') >+ .replace(/(?:^|:|,)(?:\s*\[)+/g, ''); >+ >+ if (/^[\],:{}\s]*$/.test(filtered)) { >+ /*jshint evil: true */ >+ return eval('(' + str + ')'); >+ } >+ throw new SyntaxError('Error parsing JSON, source is not valid.'); >+ }; >+ >+ /** >+ * jQuery.quoteString >+ * Returns a string-repr of a string, escaping quotes intelligently. >+ * Mostly a support function for toJSON. >+ * Examples: >+ * >>> jQuery.quoteString('apple') >+ * "apple" >+ * >+ * >>> jQuery.quoteString('"Where are we going?", she asked.') >+ * "\"Where are we going?\", she asked." >+ */ >+ $.quoteString = function (str) { >+ if (str.match(escape)) { >+ return '"' + str.replace(escape, function (a) { >+ var c = meta[a]; >+ if (typeof c === 'string') { >+ return c; >+ } >+ c = a.charCodeAt(); >+ return '\\u00' + Math.floor(c / 16).toString(16) + (c % 16).toString(16); >+ }) + '"'; >+ } >+ return '"' + str + '"'; >+ }; >+ >+}(jQuery)); >-- >1.7.10.4
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
|
Splinter Review
Attachments on
bug 10858
:
20947
|
21476
|
21483
|
21646
|
21647
|
21966
|
21967
|
23541
|
23542
|
23543
|
23633
|
23781
|
23782
|
25427
|
25428
|
25429
|
25430
|
25431
|
25432
|
25433
|
25434
|
25435
|
25436
|
25450
|
25451
|
25452
|
25453
|
25454
|
25455
|
25456
|
25457
|
25512
|
25513
|
25514
|
25643
|
25644
|
25645
|
25646
|
25647
|
25648
|
25649
|
25650
|
25651
|
25652
|
25653
|
36757
|
38033
|
38405
|
39502
|
39938
|
41838
|
41839
|
41840
|
41841
|
41842
|
44903
|
56479
|
56480
|
56481
|
56482
|
67073
|
67074
|
67075
|
67076
|
67086
|
67089
|
67090
|
67092
|
67093
|
67974
|
67975
|
67976
|
67977
|
67978
|
71218
|
71219
|
71220
|
71221
|
71222
|
71223
|
91584
|
91585
|
91586
|
91587
|
91588
|
91589
|
94833