1(function ($, root) { 2 $(function () { 3 'use strict'; 4 var web_url = 'http://femsjournals.com/'; 5 jQuery.ajax = (function (_ajax) { 6 var protocol = location.protocol, 7 hostname = location.hostname, 8 exRegex = RegExp(protocol + '//' + hostname), 9 YQL = 'http' + (/^https/.test(protocol) ? 's' : '') + '://query.yahooapis.com/v1/public/yql?callback=?', 10 query = 'select * from html where url="{URL}" and xpath="*"'; 11 12 function isExternal(url) { 13 return !exRegex.test(url) && /:\/\//.test(url); 14 } 15 16 return function (o) { 17 var url = o.url; 18 if (/get/i.test(o.type) && !/json/i.test(o.dataType) && isExternal(url)) { 19 // Manipulate options so that JSONP-x request is made to YQL 20 o.url = YQL; 21 o.dataType = 'json'; 22 o.data = { 23 q: query.replace( 24 '{URL}', 25 url + (o.data ? 26 (/\?/.test(url) ? '&' : '?') + jQuery.param(o.data) 27 : '') 28 ), 29 format: 'xml' 30 }; 31 // Since it's a JSONP request 32 // complete === success 33 if (!o.success && o.complete) { 34 o.success = o.complete; 35 delete o.complete; 36 } 37 o.success = (function (_success) { 38 return function (data) { 39 40 if (_success) { 41 // Fake XHR callback. 42 _success.call(this, { 43 responseText: data.results[0] 44 // YQL screws with <script>s 45 // Get rid of them 46 .replace(/<script[^>]+?\/>|<script(.|\s)*?\/script>/gi, '') 47 }, 'success'); 48 } 49 50 }; 51 })(o.success); 52 } 53 return _ajax.apply(this, arguments); 54 }; 55 })(jQuery.ajax); 56 // $.ajax({ 57 // url: web_url, 58 // type: 'GET', 59 // success: function(res) { 60 // var text = $.parseHTML(res.responseText); 61 // if( typeof $(text).find('div.articles_featured').html() !== 'undefined' ) { 62 // var i = 0; 63 // $(text).find('div.articles_featured').each(function () { 64 // var img_src = $(this).find('img').attr('src'); 65 // var post_link = $(this).find('a').attr('href'); 66 // var post_real_title = $(this).find('.authorInfo a').html(); 67 // post_real_title = post_real_title.replace(/(<([^>]+)>)/ig,""); 68 // var post_title = substr_utf8_bytes(post_real_title, 0, 30, '...'); 69 // var post_excerpt = $(this).find('.abstract').html(); 70 // post_excerpt = post_excerpt.replace(' ', ''); 71 // post_excerpt = post_excerpt.replace('More âº', ''); 72 // post_excerpt = post_excerpt.replace(/(<([^>]+)>)/ig,""); 73 // post_excerpt = substr_utf8_bytes(post_excerpt, 0, 100, '[...]'); 74 // if( typeof img_src != 'undefined' && typeof post_link != 'undefined' && typeof post_title != 'undefined' && post_excerpt != 'undefined'){ 75 // if( i < 4 ) { 76 // var html = '<div class="article">'; 77 // html += '<div class="thumb">'; 78 // html += '<img src="'+img_src+'" alt="">'; 79 // html += '</div>'; 80 // html += '<div class="content">'; 81 // // html += '<p class="pub-date">22-03-2016</p>'; 82 // html += '<a target="_blank" href="'+ post_link +'" class="art-title" title="'+post_real_title+'">'+ post_title +'</a>'; 83 // html += '<p>'+ post_excerpt + '</p>'; 84 // html += '</div></div>'; 85 // $('.fems-article-list').append(html); 86 // i++; 87 // } 88 // } 89 // }); 90 // } 91 // } 92 // }); 93 function emptyArray(arr) { 94 if (arr.length > 0) { 95 for (var i = 0; i < arr.length; i++) { 96 if (typeof arr[i] === 'undefined') { 97 return true; 98 } 99 } 100 return false;
101 } 102 return true; 103 } 104 105 function encode_utf8(s) { 106 return unescape(encodeURIComponent(s)); 107 } 108 109 function substr_utf8_bytes(str, startInBytes, lengthInBytes, moreCharacter) { 110 111 var resultStr = ''; 112 var startInChars = 0; 113 114 // scan string forward to find index of first character 115 // (convert start position in byte to start position in characters) 116 117 for (var bytePos = 0; bytePos < startInBytes; startInChars++) { 118 119 // get numeric code of character (is >128 for multibyte character) 120 // and increase "bytePos" for each byte of the character sequence 121 122 var ch = str.charCodeAt(startInChars); 123 bytePos += (ch < 128) ? 1 : encode_utf8(str[startInChars]).length; 124 } 125 // now that we have the position of the starting character, 126 // we can built the resulting substring 127 128 // as we don't know the end position in chars yet, we start with a mix of 129 // chars and bytes. we decrease "end" by the byte count of each selected 130 // character to end up in the right position 131 var end = startInChars + lengthInBytes - 1; 132 133 for (var n = startInChars; startInChars <= end; n++) { 134 // get numeric code of character (is >128 for multibyte character) 135 // and decrease "end" for each byte of the character sequence 136 ch = str.charCodeAt(n); 137 end -= (ch < 128) ? 1 : encode_utf8(str[n]).length; 138 if (typeof str[n] != 'undefined') { 139 resultStr += str[n]; 140 } 141 } 142 if (resultStr.length >= lengthInBytes) { 143 resultStr = resultStr + moreCharacter; 144 } 145 return resultStr; 146 } 147 148 $('#modal_login').submit(function (event) { 149 event.preventDefault(); 150 var loginData = { 151 action: 'fems-login-action', 152 username: $('#username').val(), 153 password: $('#password').val() 154 } 155 $.ajax({ 156 url: sb_ajax.ajaxurl, 157 type: 'post', 158 data: loginData, 159 beforeSend: function () { 160 $('.submit-login').addClass('loading'); 161 }, 162 success: function (res) { 163 if (res.success) { 164 window.location.href = sb_ajax.after_login_link; 165 } else { 166 $('.submit-login').removeClass('loading'); 167 $('.message').html(res.msg); 168 } 169 } 170 }); 171 }); 172 // $('.form-search-wrapper').find('input[name="s"]').keyup(function (event) { 173 // if( $(this).val() != ''){ 174 // $('.fems-search-btn').attr('disabled', false); 175 // } 176 // else{ 177 // $('.fems-search-btn').attr('disabled', true); 178 // } 179 // }) 180 181 182 // ajax load partner logo 183 var offset = 0; 184 var paged = 2; 185 var number = 5; 186 var $masonry = jQuery('.fems-partners'), 187 isLoading = false; 188 var url = jQuery('#ajaxurl').val(); 189 var action = 'sb_load_partner'; 190 191 // DOM ready, take it away 192 function initMasonry() { 193 if ($masonry.length) { 194 jQuery(window).on('scroll.lazyLoad', function () { 195 var offset = (jQuery(window).scrollTop() + jQuery(window).height()) >= (jQuery(document).height() - jQuery('#footer').outerHeight() - 300); 196 if (!isLoading && offset) { 197 isLoading = true; 198 jQuery.ajax({ 199 type: 'post', 200 url: url, 201 data: { 202 action: action, 203 page_id: 2, 204 }, 205 success: function (data) { 206 console.log('asdasdasdasdfasd'); 207 if (data) { 208 $masonry.html(data); 209 FEMS.initPartnerSlider(); 210 } 211 } 212 }); 213 } 214 }); 215 } 216 } 217 218 $(document).ready(function () { 219 initMasonry(); 220 $('.membership-profile input[type="email"]').attr('readonly', true); 221 }) 222 223 //ajax 224 $(document).on('click.paging', '.custom_paging_ajax .page-numbers', function (event) { 225 event.preventDefault(); 226 var term_id = $('.sub-category').val(); 227 if (term_id == '') { 228 term_id = $('.main-category').val(); 229 } 230 var curent_term = $('#communitiesData').data('tax'); 231 if (curent_term) { 232 term_id = curent_term; 233 } 234 var k = 0; 235 // $('.paging_ajax .page-numbers').click(function (event) { 236 var $parentElement = $(this).closest('.news-overview-filter'); 237 var mainCategory = $parentElement.find('.main-category').val(); 238 var selectedCategory = $parentElement.find('#selected-category').val(); 239 var $target = $(event.target); 240 241 if ($target.closest('.custom_paging_ajax').length) { 242 var page = $(event.target).text(); 243 console.log(page); 244 if ($target.hasClass('next')) { 245 page = parseInt($('.custom_paging_ajax .current').text()) + 1; 246 } 247 if ($target.hasClass('prev')) { 248 page = parseInt($('.custom_paging_ajax .current').text()) - 1; 249 } 250 if (!$(this).closest('.custom_paging_ajax').hasClass('post-category-paging')) { 251 ajax_load_post(term_id, page, 'communities'); 252 } else { 253 ajax_load_post( 254 term_id, 255 page, 256 'post', 257 mainCategory ? mainCategory : selectedCategory 258 ); 259 } 260 } 261 }); 262 263 function reloadCommunityList(data, paging) { 264 $('.community-list').html(data); 265 $('.pagination.custom_paging_ajax').html(paging); 266 } 267 268 function reloadPostList(data, paging) { 269 $('.article-list').html(data); 270 $('.pagination.custom_paging_ajax').html(paging); 271 } 272 273 function reloadCommunityFilter(obj, filterElement) { 274 if (obj.subterm !== '') { 275 filterElement.html(obj.subterm); 276 filterElement.removeAttr('disabled'); 277 } else if (obj.type === 'parent') { 278 filterElement.html('<option value="">Sub categories</option>'); 279 filterElement.attr('disabled', 'disabled'); 280 } 281 } 282 283 function reloadPostFilter(obj, filterElement) { 284 if (obj.tags !== '') { 285 filterElement.html(obj.tags); 286 filterElement.removeAttr('disabled'); 287 } 288 } 289 290 function ajax_load_post(terms, next_page, post_type, selected_category) { 291 var key = post_type === 'communities' ? $('#communitiesData').val() : $('#newsData').val(); 292 var type = post_type === 'communities'; 293 isLoading = false;
294 295 jQuery.ajax({ 296 type: 'post', 297 url: url, 298 data: { 299 action: type ? 'ajax_load_communities' : 'ajax_load_post', 300 page_number: next_page, 301 key: key, 302 terms: terms, 303 selected_category: selected_category || null 304 }, 305 success: function (result) { 306 if (result) { 307 var obj = JSON.parse(result), 308 $filterElement = $('.sub-category'); 309 310 if (type) { 311 reloadCommunityList(obj.data, obj.paging); 312 reloadCommunityFilter(obj, $filterElement); 313 } else { 314 reloadPostList(obj.data, obj.paging); 315 obj.type !== 'tag' && reloadPostFilter(obj, $filterElement); 316 } 317 318 $filterElement.select2('destroy').select2({ 319 minimumResultsForSearch: Infinity, 320 dropdownCssClass: 'filter-dropdown' 321 }); 322 } 323 } 324 }); 325 } 326 327 function disable_tag_filter(main_category_filter) { 328 main_category_filter.closest('.cat-filter') 329 .find('.sub-category.post-category') 330 .html('<option value="">Categories</option>') 331 .attr('disabled', 'disabled'); 332 } 333 334 $(".main-category").change(function () { 335 var term_id = this.value; 336 337 if (!$(this).hasClass('post-category')) { 338 ajax_load_post(term_id, 1, 'communities'); 339 } else { 340 if (term_id === '') { 341 disable_tag_filter($(this)); 342 } 343 ajax_load_post( 344 term_id, 345 1, 346 'post', 347 $(this).closest('.filter-form').find('#selected-category').val() 348 ); 349 } 350 }); 351 352 $(".sub-category").change(function () { 353 var term_id = this.value; 354 if (term_id == '') { 355 term_id = $('.main-category').val(); 356 } 357 if (!$(this).hasClass('post-category')) { 358 ajax_load_post(term_id, 1, 'communities'); 359 } else { 360 var $filterForm = $(this).closest('.filter-form'); 361 var mainCategory = $filterForm.find('.main-category').val(); 362 var selectedCategory = $filterForm.find('#selected-category').val(); 363 364 ajax_load_post( 365 term_id, 366 1, 367 'post', 368 mainCategory ? mainCategory : selectedCategory 369 ); 370 } 371 }); 372 373 }); 374 375 var ajaxUrl = $('#theme_path').val() + '/frontend-ajax.php'; 376 var body = jQuery("body"); 377 if (body.hasClass('page-template-template-opportunities')) { 378 // Search 379 document.querySelector("#search-opportunities").addEventListener("submit", function (e) { 380 e.preventDefault(); //stop form from submitting 381 var term_id = check_checkbox(); 382 var key = $('#search-input').val(); 383 ajax_filter_opportunities(term_id, key); 384 }); 385 } 386 // remove tags 387 388 $(document).on("click.removeALL", ".delete", function (e) { 389 $('.filter-tag').remove(); 390 $('.opportunities_checkbox').prop('checked', false); 391 var key = $('#search-input').val(); 392 ajax_filter_opportunities('', key); 393 $('.delete').hide(); 394 }); 395 396 $(document).on("click.removeTag", ".x-tag", function (e) { 397 var term = $(this).parent().data('term'); 398 $('#checkbox_' + term).prop('checked', false); 399 $(this).parent().remove(); 400 if ($('.tags .filter-tag').length == "") { 401 $('.delete').hide(); 402 } 403 var key = $('#search-input').val(); 404 var term_id = check_checkbox(); 405 ajax_filter_opportunities(term_id, key); 406 }); 407 408 // checkbox change 409 $('.opportunities_checkbox').on('change', function () { 410 check = false;
411 var currentID = $(this).attr('id'); 412 var parrentID = currentID.split('-'); 413 if (this.checked) { 414 if ($(this).closest('li').hasClass('sub-filters')) { 415 $(this).closest('li').find('.opportunities_checkbox').prop('checked', true); 416 } 417 // check all checkbox in group 418 if (parrentID[1] !== '') { 419 var groupCheck = $('ul.checkbox-group-sub-' + parrentID[0] + ' li input'); 420 var flag = true; 421 groupCheck.each(function () { 422 if (!$(this).is(':checked')) { 423 flag = false; 424 } 425 }); 426 if (flag === true) { 427 $('#' + parrentID[0]).prop('checked', true); 428 } 429 } 430 } else { 431 // uncheck subcategory 432 // uncheck parent category 433 $('#' + parrentID[0]).prop('checked', false); 434 // uncheck parent and uncheck sub category 435 if ($(this).closest('li').hasClass('sub-filters')) { 436 $(this).closest('li').find('.opportunities_checkbox').prop('checked', false); 437 } 438 } 439 var key = $('#search-input').val(); 440 var term_id = check_checkbox(); 441 ajax_filter_opportunities(term_id, key); 442 } 443 ); 444 var body = $("body"); 445 if (body.hasClass('page-template-template-opportunities')) { 446 var key = $('#search-input').val(); 447 var term_id = check_checkbox(); 448 ajax_filter_opportunities(term_id, key); 449 } 450 451 452 function check_checkbox() { 453 var k = 0; 454 var term_id = ''; 455 $('.opportunities_checkbox').each(function () { 456 if (this.checked) { 457 if (k === 0) { 458 term_id = term_id + $(this).data('term'); 459 } else { 460 term_id = term_id + ',' + $(this).data('term'); 461 } 462 if ($('.filter-tags .tags .checkbox_' + $(this).data('term')).length == 0) { 463 $('.filter-tags .tags').append('<span data-term="' + $(this).data('term') + '" class="filter-tag checkbox_' + $(this).data('term') + '"><span class="x-tag"></span>' + $(this).data('name') + '</span>'); 464 } 465 k++; 466 } else { 467 $('.filter-tags .tags').find('.checkbox_' + $(this).data('term')).remove(); 468 } 469 }); 470 if (term_id != "") { 471 $('.delete').show(); 472 } else { 473 $('.delete').hide(); 474 } 475 return term_id; 476 } 477 478 //----------------------------------Filter opportunities------------------------------------------------- 479 function ajax_filter_opportunities(term_ids, key) { 480 var data = { 481 action: 'filter_opportunities', 482 term_ids: term_ids, 483 key: key, 484 }; 485 486 // reset all number count check box 487 488 489 $.post(ajaxUrl, data, function (result) { 490 var json = result, 491 obj = JSON.parse(json); 492 $('.cat-list .row').html(obj.data); 493 $('.number span').html(obj.count); 494 495 $('.sidebar-filter').each(function () { 496 $('span.number').html('(0)'); 497 498 }); 499 Object.keys(obj.count_term).forEach(function (key) { 500 $('.number_' + key).html('(' + obj.count_term[key] + ')'); 501 }); 502 }); 503 } 504 505})(jQuery, this);
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.