{"id":160651,"date":"2012-11-28T23:37:03","date_gmt":"2012-11-28T19:37:03","guid":{"rendered":"http:\/\/savepearlharbor.com\/?p=160651"},"modified":"-0001-11-30T00:00:00","modified_gmt":"-0001-11-29T21:00:00","slug":"","status":"publish","type":"post","link":"https:\/\/savepearlharbor.com\/?p=160651","title":{"rendered":"<span class=\"post_title\">\u041f\u0430\u0433\u0438\u043d\u0430\u0446\u0438\u044f \u0434\u043b\u044f Backbone.js<\/span>"},"content":{"rendered":"<div class=\"content html_format\">   \t\u0414\u043e\u0431\u0440\u044b\u0439 \u0434\u0435\u043d\u044c! \u041d\u0435\u0434\u0430\u0432\u043d\u043e \u043f\u0438\u0441\u0430\u043b \u043f\u0430\u0433\u0438\u043d\u0430\u0446\u0438\u044e \u0434\u043b\u044f Backbone.js, \u0432\u043e\u0442 \u0445\u043e\u0442\u0435\u043b \u0431\u044b \u043f\u043e\u0434\u0435\u043b\u0438\u0442\u044c\u0441\u044f \u0441 \u0412\u0430\u043c\u0438, \u043c\u043e\u0436\u0435\u0442 \u043a\u043e\u043c\u0443-\u0442\u043e \u043f\u0440\u0438\u0433\u043e\u0434\u0438\u0442\u0441\u044f.<br \/>  <a name=\"habracut\"><\/a><br \/>  \u041f\u0443\u0441\u043a\u0430\u044f \u043d\u0430\u043c \u043d\u0430\u0434\u043e \u0441\u0434\u0435\u043b\u0430\u0442\u044c \u043f\u0430\u0433\u0438\u043d\u0430\u0446\u0438\u044e \u0432\u0438\u0434\u0430:<\/p>\n<p>  1\u2026 3 4 5 6 7\u2026 12<\/p>\n<p>  \u0414\u043b\u044f \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 \u043f\u043e\u043d\u0430\u0434\u043e\u0431\u0438\u0442\u044c\u0441\u044f \u0432\u0438\u0434 <b>PaginationView<\/b> \u0438 \u0448\u0430\u0431\u043b\u043e\u043d <b>pagination-view<\/b>.<\/p>\n<h1>\u0412\u0438\u0434 \u2014 PaginationView<\/h1>\n<p>  <\/p>\n<pre><code class=\"javascript\">window.PaginationView = Backbone.View.extend({ \ttemplate: _.template($(&quot;#pagination-view&quot;).html()), \/\/ \u0448\u0430\u0431\u043b\u043e\u043d \tlink: &quot;&quot;, \/\/ \u0441\u0441\u044b\u043b\u043a\u0430 \tpage_count: null, \/\/ \u043a\u043e\u043b-\u0432\u043e \u0441\u0442\u0440\u0430\u043d\u0438\u0446 \tpage_active: null, \/\/ \u0430\u043a\u0442\u0438\u0432\u043d\u0430\u044f \u0441\u0442\u0440\u0430\u043d\u0438\u0446\u0430 \tpage_show: 5, \/\/ \u043a\u043e\u043b-\u0432\u043e \u0441\u0442\u0440\u0430\u043d\u0438\u0446 \u0432 \u0431\u043b\u043e\u043a\u0435 \u0432\u0438\u0434\u0438\u043c\u043e\u0441\u0442\u0438 \tattributes: { \/\/ \u0430\u0442\u0440\u0438\u0431\u0443\u0442\u044b \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u0430 \t\t&quot;class&quot;: &quot;pagination&quot; \t},         initialize: function(params) { \/\/ \u043a\u043e\u043d\u0441\u0442\u0440\u0443\u043a\u0442\u043e\u0440 \t\tthis.link = params.link; \t\tthis.page_count = params.page_count; \t\tif (this.page_count &lt;= this.page_show) { \t\t\tthis.page_show = this.page_count; \t\t} \t\tthis.page_active = params.page_active; \t},         render: function(eventName) { \/\/ \u0432\u044b\u0434\u0430\u0447\u0430 \t\t... \t} }); <\/code><\/pre>\n<p>  \u0418\u043c\u0435\u0435\u043c \u0442\u0430\u043a\u043e\u0435 \u043e\u043f\u0438\u0441\u0430\u043d\u0438\u0435 \u0432\u0438\u0434\u0430. \u0412 \u043a\u043e\u043d\u0441\u0442\u0440\u0443\u043a\u0442\u043e\u0440\u0435 \u043f\u0440\u0438\u043d\u0438\u043c\u0430\u0435\u043c \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u044b, params \u2014 \u043e\u0431\u044a\u0435\u043a\u0442 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u043e\u0432.<\/p>\n<p>  \u0422\u0435\u043f\u0435\u0440\u044c \u0440\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0438\u043c \u043b\u043e\u0433\u0438\u043a\u0443 \u0432\u044b\u0434\u0430\u0447\u0438. \u0414\u043b\u044f \u0432\u044b\u0434\u0430\u0447\u0438 \u043f\u0430\u0433\u0438\u043d\u0430\u0446\u0438\u0438, \u0430 \u0442\u043e\u0447\u043d\u0435\u0435 \u0431\u043b\u043e\u043a\u0430, \u0432\u0438\u0434\u0438\u043c\u044b\u0445 \u0441\u0442\u0440\u0430\u043d\u0438\u0446, \u043d\u0430\u043c \u043d\u0430\u0434\u043e \u043d\u0430\u0439\u0442\u0438 \u0438\u043d\u0434\u0435\u043a\u0441 \u043d\u0430\u0447\u0430\u043b\u0430 \u0438 \u043a\u043e\u043d\u0446\u0430 \u044d\u0442\u0438\u0445 \u0441\u0442\u0440\u0430\u043d\u0438\u0446. \u0418\u0449\u0435\u043c \u043a\u043e\u043b-\u0432\u043e \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u043e\u0432 \u0434\u043e \u0430\u043a\u0442\u0438\u0432\u043d\u043e\u0433\u043e \u0438 \u043f\u043e\u0441\u043b\u0435. \u0422\u043e \u0435\u0441\u0442\u044c \u0434\u0435\u043b\u0438\u043c \u043f\u043e\u043f\u043e\u043b\u0430\u043c.<\/p>\n<pre><code class=\"javascript\">var range = Math.floor(this.page_show \/ 2); var nav_begin = this.page_active - range; var nav_end = this.page_active + range; <\/code><\/pre>\n<p>  \u0414\u0430\u043b\u044c\u0448\u0435 \u043d\u0430\u043c \u043d\u0443\u0436\u043d\u043e \u0443\u0437\u043d\u0430\u0442\u044c \u0438\u043b\u0438 \u043d\u0430\u0434\u043e \u043d\u0430\u043c \u0432\u044b\u0434\u0430\u0432\u0430\u0442\u044c &quot;&#8230;&quot; \u0441 \u043a\u0430\u0436\u0434\u043e\u0439 \u0438\u0437 \u0441\u0442\u043e\u0440\u043e\u043d. \u0417\u0430\u0432\u043e\u0434\u0438\u043c \u0434\u0432\u0435 \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u0435, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043f\u043e\u043a\u0430\u0436\u0443\u0442, \u043d\u0443\u0436\u043d\u044b \u043b\u0438:<\/p>\n<pre><code class=\"javascript\">var left_dots = true; var right_dots = true; <\/code><\/pre>\n<p>  \u0418 \u0442\u0430\u043a, \u043a\u043e\u0433\u0434\u0430 \u043d\u0430\u043c \u043d\u0443\u0436\u043d\u044b &quot;&#8230;&quot;, \u043a\u043e\u0433\u0434\u0430 \u043d\u0430\u0447\u0430\u043b\u043e \u0431\u043e\u043b\u044c\u0448\u0435 2 (\u0441\u043b\u0435\u0432\u0430) \u0438 \u043a\u043e\u0433\u0434\u0430 \u043c\u0435\u043d\u044c\u0448\u0435 \u043a\u043e\u043d\u0446\u0430 \u2014 1 (\u0441\u043f\u0440\u0430\u0432\u0430). \u0414\u043b\u044f \u044d\u0442\u043e\u0433\u043e \u043f\u0438\u0448\u0435\u043c \u0434\u0432\u0435 \u043f\u0440\u043e\u0432\u0435\u0440\u043a\u0438, \u0432 \u043a\u043e\u0442\u043e\u0440\u044b\u0445 \u0440\u0430\u0437\u0431\u0435\u0440\u0435\u043c \u0435\u0449\u0435 \u043e\u0434\u0438\u043d \u0447\u0430\u0441\u0442\u043d\u044b\u0439 \u0441\u043b\u0443\u0447\u0430\u0439. \u041e\u043d \u0441\u043e\u0441\u0442\u043e\u0438\u0442 \u0432 \u0442\u043e\u043c, \u0447\u0442\u043e \u0435\u0441\u043b\u0438 \u0443 \u043d\u0430\u0441 \u0430\u043a\u0442\u0438\u0432\u043d\u044b\u0439 \u0432\u0442\u043e\u0440\u043e\u0439, \u0442\u043e \u0431\u043b\u043e\u043a \u0432\u044b\u0434\u0430\u0447\u0438 \u0438\u043c\u0435\u0435\u0442 \u043d\u0430 \u043e\u0434\u0438\u043d \u0431\u043e\u043b\u044c\u0448\u0435 \u044d\u043b\u0435\u043c\u0435\u043d\u0442. <\/p>\n<p>  1 2 3 4 5 6\u2026 12<\/p>\n<p>  \u0418 \u0442\u0430\u043a \u0436\u0435 \u0432 \u043a\u043e\u043d\u0446\u0435.<\/p>\n<p>  1\u2026 7 8 9 10 11 12<\/p>\n<pre><code class=\"javascript\">if (nav_begin &lt;= 2) { \tnav_end = this.page_show; \tif (nav_begin == 2) {              nav_end++;         }  \tnav_begin = 1; \tleft_dots = false; } \t\t if (nav_end &gt;= this.page_count - 1 ) { \tnav_begin = this.page_count - this.page_show + 1; \tif (nav_end == this.page_count - 1) {                nav_begin--;         } \tnav_end = this.page_count; \tright_dots = false; } <\/code><\/pre>\n<p>  \u0418 \u0432 \u043a\u043e\u043d\u0446\u0435 \u043a\u043e\u043d\u0446\u043e\u0432 \u043e\u0442\u043f\u0440\u0430\u0432\u043b\u044f\u0435\u043c \u0448\u0430\u0431\u043b\u043e\u043d\u0443:<\/p>\n<pre><code class=\"javascript\">\t $(this.el).html( this.template({ \tlink: this.link, \tpage_count: this.page_count, \tpage_active: this.page_active, \tnav_begin: nav_begin, \tnav_end: nav_end, \tleft_dots: left_dots, \tright_dots: right_dots }) ); <\/code><\/pre>\n<p>  <\/p>\n<h1>\u0428\u0430\u0431\u043b\u043e\u043d pagination-view<\/h1>\n<p>  \u0428\u0430\u0431\u043b\u043e\u043d \u043d\u0430\u043f\u0438\u0441\u0430\u043d \u0441 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435\u043c Twitter Bootstrap. \u0422\u0440\u0438\u0432\u0438\u0430\u043b\u044c\u043d\u0430\u044f \u0432\u044b\u0434\u0430\u0447\u0430.<\/p>\n<pre><code class=\"html\">&lt;ul&gt;   &lt;% if (page_active &gt; 1) { %&gt;     &lt;li&gt;&lt;a href=&quot;&lt;%= link %&gt;&lt;%= page_active-1 %&gt;&quot;&gt;\u00ab&lt;\/a&gt;&lt;\/li&gt; &lt;% } %&gt; &lt;% if (left_dots == true) {%&gt;     &lt;li&gt;&lt;a href=&quot;&lt;%= link %&gt;1&quot;&gt;1&lt;\/a&gt;&lt;\/li&gt;     &lt;li class=&quot;disabled&quot;&gt;&lt;a href=&quot;#&quot;&gt;...&lt;\/a&gt;&lt;\/li&gt; &lt;% } %&gt;  &lt;% for (var i = nav_begin; i &lt;= nav_end; i++) { %&gt;      &lt;li &lt;% if (page_active == i) print('class=&quot;active&quot;') %&gt; &gt;&lt;a href=&quot;&lt;%= link %&gt;&lt;%= i %&gt;&quot;&gt;&lt;%= i %&gt;&lt;\/a&gt;&lt;\/li&gt;  &lt;% } %&gt;  &lt;% if (right_dots == true) {%&gt;     &lt;li class=&quot;disabled&quot;&gt;&lt;a href=&quot;#&quot;&gt;...&lt;\/a&gt;&lt;\/li&gt;     &lt;li&gt;&lt;a href=&quot;&lt;%= link %&gt;&lt;%= page_count %&gt;&quot;&gt;&lt;%= page_count %&gt;&lt;\/a&gt;&lt;\/li&gt; &lt;% } %&gt;  &lt;% if (page_active &lt; page_count) { %&gt;     &lt;li&gt;&lt;a  href=&quot;&lt;%= link %&gt;&lt;%= page_active+1 %&gt;&quot;&gt;\u00bb&lt;\/a&gt;&lt;\/li&gt; &lt;% } %&gt; &lt;\/ul&gt; <\/code><\/pre>\n<p>  P.S. \u0412\u0441\u0435 \u043e\u0447\u0435\u043d\u044c \u043f\u0440\u043e\u0441\u0442\u043e, \u0431\u0435\u0440\u0438\u0442\u0435 \u0438 \u043f\u043e\u043b\u044c\u0437\u0443\u0439\u0442\u0435\u0441\u044c :).<br \/>  P.S.S. \u0415\u0441\u043b\u0438 \u043a\u043e\u043b-\u0432\u043e \u0441\u0442\u0440\u0430\u043d\u0438\u0446 \u0431\u043b\u043e\u043a\u0430 \u043f\u0430\u0440\u043d\u043e\u0435 \u0447\u0438\u0441\u043b\u043e, \u0442\u043e \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u0443\u044e range \u043d\u0443\u0436\u043d\u043e \u0438\u0441\u043a\u0430\u0442\u044c \u043f\u043e-\u0434\u0440\u0443\u0433\u043e\u043c\u0443, \u043d\u043e \u0432 \u043f\u0430\u0433\u0438\u043d\u0430\u0446\u0438\u044f\u0445 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044e\u0442 \u0437\u0430\u0447\u0430\u0441\u0442\u0443\u044e \u043d\u0435\u043f\u0430\u0440\u043d\u043e\u0435 \u0447\u0438\u0441\u043b\u043e.    \t   \t<\/p>\n<div class=\"clear\"><\/div>\n<\/p><\/div>\n<p> \u0441\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 \u043e\u0440\u0438\u0433\u0438\u043d\u0430\u043b \u0441\u0442\u0430\u0442\u044c\u0438 <a href=\"http:\/\/habrahabr.ru\/post\/160651\/\"> http:\/\/habrahabr.ru\/post\/160651\/<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<div class=\"content html_format\">   \t\u0414\u043e\u0431\u0440\u044b\u0439 \u0434\u0435\u043d\u044c! \u041d\u0435\u0434\u0430\u0432\u043d\u043e \u043f\u0438\u0441\u0430\u043b \u043f\u0430\u0433\u0438\u043d\u0430\u0446\u0438\u044e \u0434\u043b\u044f Backbone.js, \u0432\u043e\u0442 \u0445\u043e\u0442\u0435\u043b \u0431\u044b \u043f\u043e\u0434\u0435\u043b\u0438\u0442\u044c\u0441\u044f \u0441 \u0412\u0430\u043c\u0438, \u043c\u043e\u0436\u0435\u0442 \u043a\u043e\u043c\u0443-\u0442\u043e \u043f\u0440\u0438\u0433\u043e\u0434\u0438\u0442\u0441\u044f.  <\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[],"tags":[],"class_list":["post-160651","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/160651","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=160651"}],"version-history":[{"count":0,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/160651\/revisions"}],"wp:attachment":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=160651"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=160651"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=160651"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}