info: Fix JavaScript to support older versions of CiviCRM and jQuery.
[org.fsf.memberdashboard.git] / assets / js / member-info.js
index 7158f054609600ef30adcde8846007be40ebbe5b..b4ff8d0857e64c16f770355f16bbaa15063b6a29 100644 (file)
@@ -19,9 +19,9 @@
  * <http://www.gnu.org/licenses/>.
  */
 
-CRM.$(function($) {
+(function($) {
   function loadProfile(gid, success) {
-    $.get('/drupal/civicrm/profile/edit', {
+    $.get('/civicrm/profile/edit', {
       gid: gid,
       json: 1
     }, success);
@@ -42,6 +42,9 @@ CRM.$(function($) {
         .value();
     }
 
+    // Support older versions of jQuery that don't parse the JSON by
+    // default.
+    profile = _.isString(profile) ? JSON.parse(profile): profile;
     var form = $('<form' + profile.attributes + '></form>');
 
     form.append(profile.requirednote)
@@ -49,10 +52,10 @@ CRM.$(function($) {
       .append.apply(form, renderFields());
 
     $('#info-loading').remove();
-    $('#crm-main-content-wrapper').append(form);
+    $('#info-form').append(form);
   }
 
   $(document).ready(function() {
     loadProfile(memberDashboard.profileId, renderProfile);
   });
-});
+})(jQuery);