/[drupal]/contributions/modules/paging/paging.js
ViewVC logotype

Contents of /contributions/modules/paging/paging.js

Parent Directory Parent Directory | Revision Log Revision Log | View Revision Graph Revision Graph


Revision 1.12 - (show annotations) (download) (as text)
Sat Apr 18 21:18:33 2009 UTC (7 months, 1 week ago) by Gurpartap
Branch: MAIN
CVS Tags: HEAD
Changes since 1.11: +2 -2 lines
File MIME type: text/javascript
#434652 by jcmarco: Remove @ from selectors.
1 // $Id: paging.js,v 1.11 2009/01/24 16:12:52 Gurpartap Exp $
2
3 Number.prototype.ordinal = function () {
4 return this + (
5 (this % 10 == 1 && this % 100 != 11) ? '<sup>st</sup>' :
6 (this % 10 == 2 && this % 100 != 12) ? '<sup>nd</sup>' :
7 (this % 10 == 3 && this % 100 != 13) ? '<sup>rd</sup>' : '<sup>th</sup>'
8 );
9 };
10
11 function paging_handle_names(pages) {
12 var output = '';
13
14 if (pages.length > 0) {
15 for (var x = 0; x < pages.length; x++) {
16 var title = $('#edit-title').val();
17 var name = Drupal.t('!title - Page !number', {'!title': title, '!number': (x + 1)});
18 pages[x] = (pages[x] || name);
19 output += '<label for="edit-paging-title[' + x + ']">' + Drupal.t("Name of !number page: ", {'!number': (x + 1).ordinal()}) + '</label>'
20 + "\t" + '<input type="text" class="form-text" value="' + pages[x] + '" size="20" name="edit-paging-title[' + x + ']" maxlength="255"/>' + "\n";
21 }
22 $('#paging-names-wrapper').show().each(function() {
23 $(this).html('<fieldset class="form-item" id="paging-page-names" style="overflow: hidden;">'
24 + '<legend class="">' + Drupal.t("Page names") + '</legend><div id="paging-names-inner" class="form-item"></div></fieldset>');
25 });
26 $('#paging-names-wrapper #paging-names-inner').html(output);
27 }
28 else {
29 $('#paging-names-wrapper').hide();
30 }
31 }
32
33 function paging_return_names() {
34 var names = [];
35 var i = 0;
36 $('#paging-page-names').find('input[type=text]').each(function() {
37 names[i] = $(this).val();
38 i++;
39 }).parents('fieldset').remove();
40
41 return names;
42 }
43
44 function paging_insert_separator() {
45 var separator = Drupal.settings.paging.separator;
46 $('textarea#edit-body').each(function() {
47 if (document.selection) {
48 this.focus();
49 document.selection.createRange().text = separator;
50 }
51 else if (this.selectionStart || this.selectionStart == '0') {
52 var cursorPos = this.selectionEnd + separator.length;
53 this.value = this.value.substring(0, this.selectionEnd) + separator + this.value.substring(this.selectionEnd);
54 this.selectionStart = this.selectionEnd = cursorPos;
55 }
56 else {
57 this.value = this.value + separator;
58 }
59 this.focus();
60 }).trigger('click');
61
62 return false;
63 }
64
65 Drupal.behaviors.paging = function(context) {
66 // Handle the widget button to insert paging separator.
67 $('textarea.teaser').each(function() {
68 var include = $('#' + this.id.substring(0, this.id.length - 2) + 'include');
69 var widget = Drupal.settings.paging.widget;
70
71 if (widget == 1) {
72 // Add paging separator string image.
73 var path = Drupal.settings.basePath + Drupal.settings.paging.module_path;
74 var string = Drupal.t('Insert page separator');
75 var image = $('<div class="paging-button-wrapper"><img alt="" src="' + path + '/paging-separator.png" class="paging-separator-image" /></div>');
76 $(include).parent().parent().before(image);
77 $('img', image).attr('alt', string).attr('title', string).bind('click', paging_insert_separator);
78 }
79 else if (widget == 2) {
80 // Add paging separator string button.
81 var button = $('<div class="paging-button-wrapper"><input type="button" class="paging-separator-button" /></div>');
82 $(include).parent().parent().before(button);
83 $('input', button).val(Drupal.t('Insert page separator')).bind('click', paging_insert_separator);
84 }
85 });
86
87 var page_names = typeof Drupal.settings.paging != 'undefined' ? Drupal.settings.paging.page_names : 0;
88 if (page_names == 1) {
89 // Page names interface is enabled.
90 $('#edit-body-wrapper').after('<div id="paging-names-wrapper"></div>');
91
92 $('textarea#edit-body').each(function() {
93 var str = $(this).val();
94 var match = str.match(/<!--pagenames:(.*?)-->/) || [];
95 $(this).val(str.replace(/<!--pagenames:(.*?)-->/, ''));
96 var pages = typeof match[1] != 'undefined' ? match[1].split('||') : [];
97 paging_handle_names(pages);
98 }).bind('click keyup blur', function() {
99 var str = $(this).val();
100 var separator = Drupal.settings.paging.separator;
101 var count = 0;
102 var current_names = paging_return_names();
103 var pages = [(current_names[count] ? current_names[count] : '')];
104 var pos = str.indexOf(separator);
105 while (pos != -1) {
106 count++;
107 pages.push(current_names[count] ? current_names[count] : '');
108 pos = str.indexOf(separator, pos + 1);
109 }
110 paging_handle_names(str.indexOf(separator) != -1 ? pages : 0);
111 });
112
113 $('#node-form').submit(function() {
114 $('textarea#edit-body').each(function() {
115 var names = paging_return_names();
116 if (names.length > 0) {
117 $(this).val('<!--pagenames:' + names.join('||') + '-->' + this.value);
118 }
119 });
120 });
121 }
122
123 $('div.paging-pager-contents:not(.pager-processed)', context).each(function() {
124 var $target = $(this);
125 $target.addClass('pager-processed')
126 // Process pager links.
127 .find('ul.pager > li > a, table.paging-drop-down a')
128 .each(function() {
129 var ajaxPath = $(this).attr('href');
130 $(this).click(function () {
131 $link = $(this);
132 $link.addClass('throbber');
133 $.ajax({
134 url: ajaxPath,
135 type: 'GET',
136 dataType: 'json',
137 data: {'paging_json_request': $target.attr('id')},
138 success: function(response) {
139 $link.removeClass('throbber');
140 if (response.content) {
141 var $newContent = $(response.content);
142 $target.replaceWith($newContent);
143 Drupal.attachBehaviors($newContent.parent());
144 var offset = $newContent.parent().offset().top;
145 $('html,body').animate({scrollTop: offset}, 500);
146 }
147 },
148 error: function() {
149 $link.removeClass('throbber');
150 alert(Drupal.t("An error occurred at @path.", {'@path': ajaxPath}));
151 }
152 });
153 return false;
154 });
155 });
156 });
157 };

  ViewVC Help
Powered by ViewVC 1.1.2